From 10c9e4eed28991a2c689efe682f5e97b4cb64292 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Fri, 2 Oct 2015 10:00:51 +0200 Subject: [PATCH] [Issues #65,#66] Delayed TAP output until the end of the tests --- include/criterion/stats.h | 1 + src/core/stats.c | 1 + src/log/tap.c | 75 ++++++++++++++++++++------------------- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/include/criterion/stats.h b/include/criterion/stats.h index ec80c2f..e21a50f 100644 --- a/include/criterion/stats.h +++ b/include/criterion/stats.h @@ -45,6 +45,7 @@ struct criterion_test_stats { int exit_code; float elapsed_time; bool timed_out; + bool crashed; unsigned progress; const char *file; diff --git a/src/core/stats.c b/src/core/stats.c index 8980f2b..bba2f8b 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -232,6 +232,7 @@ static void push_test_crash(s_glob_stats *stats, s_test_stats *test, UNUSED void *ptr) { test->failed = 1; + test->crashed = 1; ++suite->tests_failed; ++suite->tests_crashed; ++stats->tests_failed; diff --git a/src/log/tap.c b/src/log/tap.c index 4615f70..3a48231 100644 --- a/src/log/tap.c +++ b/src/log/tap.c @@ -38,44 +38,22 @@ # define strdup _strdup #endif -void tap_log_pre_all(struct criterion_test_set *set) { - size_t enabled_count = 0; - FOREACH_SET(struct criterion_suite_set *s, set->suites) { - if ((s->suite.data && s->suite.data->disabled) || !s->tests) - continue; - - FOREACH_SET(struct criterion_test *test, s->tests) { - if (!test->data->disabled) - ++enabled_count; - } - } - criterion_important("TAP version 13\n1.." SIZE_T_FORMAT "\n", set->tests); +static void print_prelude(struct criterion_global_stats *stats) { + criterion_important("TAP version 13\n1.." SIZE_T_FORMAT "\n", stats->nb_tests); criterion_important("# Criterion v%s\n", VERSION); } -void tap_log_pre_suite(struct criterion_suite_set *set) { +static void print_pre_suite(struct criterion_suite_stats *stats) { criterion_important("\n# Running " SIZE_T_FORMAT " tests from %s\n", - set->tests->size, - set->suite.name); + stats->nb_tests, + stats->suite->name); } static INLINE bool is_disabled(struct criterion_test *t, struct criterion_suite *s) { return t->data->disabled || (s->data && s->data->disabled); } -void tap_log_post_suite(struct criterion_suite_stats *stats) { - for (struct criterion_test_stats *ts = stats->tests; ts; ts = ts->next) { - if (is_disabled(ts->test, stats->suite)) { - criterion_important("ok - %s::%s %s # SKIP %s is disabled\n", - ts->test->category, - ts->test->name, - DEF(ts->test->data->description, ""), - ts->test->data->disabled ? "test" : "suite"); - } - } -} - -void tap_log_post_test(struct criterion_test_stats *stats) { +static void print_test_normal(struct criterion_test_stats *stats) { const char *format = can_measure_time() ? "%s - %s::%s %s (%3.2fs)\n" : "%s - %s::%s %s\n"; criterion_important(format, @@ -109,7 +87,7 @@ void tap_log_post_test(struct criterion_test_stats *stats) { } } -void tap_log_test_crash(struct criterion_test_stats *stats) { +static void print_test_crashed(struct criterion_test_stats *stats) { bool sf = criterion_options.short_filename; criterion_important("not ok - %s::%s unexpected signal after %s:%u\n", stats->test->category, @@ -118,18 +96,43 @@ void tap_log_test_crash(struct criterion_test_stats *stats) { stats->progress); } -void tap_log_test_timeout(struct criterion_test_stats *stats) { +static void print_test_timeout(struct criterion_test_stats *stats) { criterion_important("not ok - %s::%s timed out (%3.2fs)\n", stats->test->category, stats->test->name, stats->elapsed_time); } +static void print_test(struct criterion_test_stats *ts, + struct criterion_suite_stats *ss) { + + if (is_disabled(ts->test, ss->suite)) { + criterion_important("ok - %s::%s %s # SKIP %s is disabled\n", + ts->test->category, + ts->test->name, + DEF(ts->test->data->description, ""), + ts->test->data->disabled ? "test" : "suite"); + } else if (ts->crashed) { + print_test_crashed(ts); + } else if (ts->timed_out) { + print_test_timeout(ts); + } else { + print_test_normal(ts); + } +} + +void tap_log_post_all(struct criterion_global_stats *stats) { + print_prelude(stats); + + for (struct criterion_suite_stats *ss = stats->suites; ss; ss = ss->next) { + print_pre_suite(ss); + + for (struct criterion_test_stats *ts = ss->tests; ts; ts = ts->next) { + print_test(ts, ss); + } + } +} + struct criterion_output_provider tap_logging = { - .log_pre_all = tap_log_pre_all, - .log_pre_suite = tap_log_pre_suite, - .log_test_crash = tap_log_test_crash, - .log_test_timeout = tap_log_test_timeout, - .log_post_test = tap_log_post_test, - .log_post_suite = tap_log_post_suite, + .log_post_all = tap_log_post_all, };