From: amalec Date: Wed, 29 Aug 2001 00:49:07 +0000 (+0000) Subject: Added test checking running empty suites X-Git-Tag: 0.10.0~1060 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a8961f85bc20d3b9187edb821abc307341f5f6d;p=check Added test checking running empty suites git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@87 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/check/src/check_print.c b/check/src/check_print.c index 0b93da6..5c3dc29 100644 --- a/check/src/check_print.c +++ b/check/src/check_print.c @@ -47,7 +47,7 @@ static void srunner_fprint_summary (FILE *file, SRunner *sr, int print_mode) char *str; str = sr_stat_str (sr); - fprintf (file, str); + fprintf (file, "%s\n", str); free(str); } return; @@ -71,7 +71,7 @@ void tr_fprint (FILE *file, TestResult *tr, int print_mode) if ((print_mode >= CRVERBOSE && tr->rtype == CRPASS) || (tr->rtype != CRPASS && print_mode >= CRNORMAL)) { char *trstr = tr_str (tr); - fprintf (file, trstr); + fprintf (file,"%s\n", trstr); free(trstr); } } diff --git a/check/src/check_str.c b/check/src/check_str.c index b809a8a..79bb29b 100644 --- a/check/src/check_str.c +++ b/check/src/check_str.c @@ -35,7 +35,7 @@ char *tr_str (TestResult *tr) exact_msg = (tr->rtype == CRERROR) ? "(after this point) ": ""; rstr = emalloc(CMAXMSG); - snprintf (rstr, CMAXMSG, "%s:%d:%s:%s: %s%s\n", + snprintf (rstr, CMAXMSG, "%s:%d:%s:%s: %s%s", tr->file, tr->line, rtype_str(tr->rtype), tr->tcname, exact_msg, tr->msg); @@ -51,7 +51,7 @@ char *sr_stat_str (SRunner *sr) ts = sr->stats; str = emalloc (CMAXMSG); - snprintf (str, CMAXMSG, "%d%%: Checks: %d, Failures: %d, Errors: %d\n", + snprintf (str, CMAXMSG, "%d%%: Checks: %d, Failures: %d, Errors: %d", percent_passed (ts), ts->n_checked, ts->n_failed, ts->n_errors); return str; @@ -80,6 +80,8 @@ static int percent_passed (TestStats *t) { if (t->n_failed == 0 && t->n_errors == 0) return 100; + else if (t->n_checked == 0) + return 0; else return (int) ( (float) (t->n_checked - (t->n_failed + t->n_errors)) / (float) t->n_checked * 100); diff --git a/check/tests/check_check_limit.c b/check/tests/check_check_limit.c new file mode 100644 index 0000000..70c75c1 --- /dev/null +++ b/check/tests/check_check_limit.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include "check_check.h" +#include "check_str.h" + + +static SRunner *sr; + +static void limit_setup (void) +{ + Suite *s = suite_create("Empty"); + sr = srunner_create(s); + srunner_run_all(sr, CRSILENT); +} + +static void limit_teardown (void) +{ + srunner_free(sr); +} + +START_TEST(test_summary) +{ + fail_unless(strcmp(sr_stat_str(sr), + "100%: Checks: 0, Failures: 0, Errors: 0") == 0, + "Bad statistics string for empty suite"); +} +END_TEST + +Suite *make_limit_suite (void) +{ + Suite *s = suite_create("Limit"); + TCase *tc = tcase_create("Empty"); + + tcase_add_test(tc,test_summary); + tcase_set_fixture(tc,limit_setup,limit_teardown); + + suite_add_tcase(s, tc); + + return s; +}