From 162aa6608bba6494175dd9a066b049c171205501 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Fri, 6 Feb 2015 02:46:15 +0100 Subject: [PATCH] Fixed innaccurate statistics on wrong signal --- include/criterion/stats.h | 6 ++++-- samples/simple.c | 2 +- src/report.c | 4 +--- src/stats.c | 11 +++++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/criterion/stats.h b/include/criterion/stats.h index 7c9318b..c836cbe 100644 --- a/include/criterion/stats.h +++ b/include/criterion/stats.h @@ -24,6 +24,7 @@ #ifndef CRITERION_STATS_H_ # define CRITERION_STATS_H_ +# include # include "criterion.h" struct criterion_assert_stats { @@ -40,8 +41,9 @@ struct criterion_assert_stats { struct criterion_test_stats { struct criterion_test *test; struct criterion_assert_stats *asserts; - int passed; - int failed; + bool failed; + int passed_asserts; + int failed_asserts; int signal; unsigned progress; const char *file; diff --git a/samples/simple.c b/samples/simple.c index fcb3a2b..cd07611 100644 --- a/samples/simple.c +++ b/samples/simple.c @@ -25,7 +25,7 @@ ReportHook(PRE_INIT)(struct criterion_test *test) { ReportHook(POST_TEST)(struct criterion_test_stats *stats) { printf("Asserts: [%d passed, %d failed, %d total]\n", - stats->passed, stats->failed, stats->passed + stats->failed); + stats->passed_asserts, stats->failed_asserts, stats->passed_asserts + stats->failed_asserts); } ReportHook(PRE_EVERYTHING)() { diff --git a/src/report.c b/src/report.c index d5abda1..06e1854 100644 --- a/src/report.c +++ b/src/report.c @@ -53,9 +53,7 @@ ReportHook(PRE_INIT)(struct criterion_test *test) { } ReportHook(POST_TEST)(struct criterion_test_stats *stats) { - int success = stats->failed == 0; - - fprintf(stderr, "%s::%s: %s\n", stats->test->category, stats->test->name, success ? "SUCCESS" : "FAILURE"); + fprintf(stderr, "%s::%s: %s\n", stats->test->category, stats->test->name, stats->failed ? "FAILURE" : "SUCCESS"); } ReportHook(PRE_TEST)() {} diff --git a/src/stats.c b/src/stats.c index 4ecda69..24199ad 100644 --- a/src/stats.c +++ b/src/stats.c @@ -102,10 +102,10 @@ static void push_assert(s_glob_stats *stats, if (data->passed) { ++stats->asserts_passed; - ++test->passed; + ++test->passed_asserts; } else { ++stats->asserts_failed; - ++test->failed; + ++test->failed_asserts; } test->progress = dup->line; @@ -115,15 +115,18 @@ static void push_assert(s_glob_stats *stats, static void push_post_test(s_glob_stats *stats, s_test_stats *test, UNUSED void *ptr) { - if (test->failed > 0) + if (test->failed_asserts > 0 || test->signal != test->test->data->signal) { + test->failed = 1; ++stats->tests_failed; - else + } else { ++stats->tests_passed; + } } static void push_test_crash(s_glob_stats *stats, s_test_stats *test, UNUSED void *ptr) { + test->failed = 1; ++stats->tests_failed; ++stats->tests_crashed; }