From: Nick Mathewson Date: Fri, 17 Apr 2009 06:57:52 +0000 (+0000) Subject: Add the latest tinytest. This one supports a --terse flag and a --no-fork flag,... X-Git-Tag: release-2.0.1-alpha~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=812800629b15c20c7d5fc15c6999c0df47136005;p=libevent Add the latest tinytest. This one supports a --terse flag and a --no-fork flag, and outputs nicer. svn:r1190 --- diff --git a/test/tinytest.c b/test/tinytest.c index 223773e1..dbfc098b 100644 --- a/test/tinytest.c +++ b/test/tinytest.c @@ -44,9 +44,12 @@ static int in_tinytest_main = 0; /**< true if we're in tinytest_main().*/ static int n_ok = 0; /**< Number of tests that have passed */ static int n_bad = 0; /**< Number of tests that have failed. */ +static int n_skipped = 0; /**< Number of tests that have been skipped. */ static int opt_forked = 0; /**< True iff we're called from inside a win32 fork*/ -static int opt_verbosity = 1; /**< 0==quiet,1==normal,2==verbose */ +static int opt_nofork = 0; /**< Suppress calls to fork() for debugging. */ +static int opt_verbosity = 1; /**< -==quiet,0==terse,1==normal,2==verbose */ +const char *verbosity_flag = ""; enum outcome { SKIP=2, OK=1, FAIL=0 }; static enum outcome cur_test_outcome = 0; @@ -109,13 +112,11 @@ _testcase_run_forked(const struct testgroup_t *group, " called from within tinytest_main.\n"); abort(); } - if (opt_verbosity) + if (opt_verbosity>0) printf("[forking] "); - verbosity = (opt_verbosity == 2) ? "--verbose" : - (opt_verbosity == 0) ? "--quiet" : ""; snprintf(buffer, sizeof(buffer), "%s --RUNNING-FORKED %s %s%s", - commandname, verbosity, group->prefix, testcase->name); + commandname, verbosity_flag, group->prefix, testcase->name); memset(&si, 0, sizeof(si)); memset(&info, 0, sizeof(info)); @@ -145,7 +146,7 @@ _testcase_run_forked(const struct testgroup_t *group, if (pipe(outcome_pipe)) perror("opening pipe"); - if (opt_verbosity) + if (opt_verbosity>0) printf("[forking] "); pid = fork(); if (!pid) { @@ -190,20 +191,22 @@ testcase_run_one(const struct testgroup_t *group, enum outcome outcome; if (testcase->flags & TT_SKIP) { - if (opt_verbosity) - printf("%s%s... SKIPPED\n", + if (opt_verbosity>0) + printf("%s%s: SKIPPED\n", group->prefix, testcase->name); + ++n_skipped; return SKIP; } - if (opt_verbosity && !opt_forked) - printf("%s%s... ", group->prefix, testcase->name); - else { + if (opt_verbosity>0 && !opt_forked) { + printf("%s%s: ", group->prefix, testcase->name); + } else { + if (opt_verbosity==0) printf("."); cur_test_prefix = group->prefix; cur_test_name = testcase->name; } - if ((testcase->flags & TT_FORK) && !opt_forked) { + if ((testcase->flags & TT_FORK) && !(opt_forked||opt_nofork)) { outcome = _testcase_run_forked(group, testcase); } else { outcome = _testcase_run_bare(testcase); @@ -211,10 +214,11 @@ testcase_run_one(const struct testgroup_t *group, if (outcome == OK) { ++n_ok; - if (opt_verbosity && !opt_forked) + if (opt_verbosity>0 && !opt_forked) puts(opt_verbosity==1?"OK":""); } else if (outcome == SKIP) { - if (opt_verbosity && !opt_forked) + ++n_skipped; + if (opt_verbosity>0 && !opt_forked) puts("SKIPPED"); } else { ++n_bad; @@ -256,7 +260,7 @@ _tinytest_set_flag(struct testgroup_t *groups, const char *arg, unsigned long fl static void usage(struct testgroup_t *groups) { - puts("Options are: --verbose --quiet"); + puts("Options are: [--verbose|--quiet|--terse] [--no-fork]"); puts("Known tests are:"); _tinytest_set_flag(groups, "..", 0); exit(0); @@ -272,15 +276,22 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups) #endif for (i=1; i= 1) + printf("%d tests ok. (%d skipped)\n", n_ok, n_skipped); + return (n_bad == 0) ? 0 : 1; } @@ -320,8 +338,9 @@ _tinytest_get_verbosity(void) void _tinytest_set_test_failed(void) { - if (opt_verbosity == 0 && cur_test_name) { - printf("%s%s... ", cur_test_prefix, cur_test_name); + if (opt_verbosity <= 0 && cur_test_name) { + if (opt_verbosity==0) puts(""); + printf("%s%s: ", cur_test_prefix, cur_test_name); cur_test_name = NULL; } cur_test_outcome = 0;