From b0403cf36d141f81803a0862496a581f8b33e69e Mon Sep 17 00:00:00 2001 From: Snaipe Date: Mon, 2 Feb 2015 13:00:16 +0100 Subject: [PATCH] Replaced criterion_{init,fini} with report hooks --- include/hooks.h | 2 ++ samples/simple.c | 11 +++++++++-- src/report.c | 10 +++++++--- src/report.h | 2 ++ src/runner.c | 4 ++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/hooks.h b/include/hooks.h index 78754d9..ccbf4b4 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -4,10 +4,12 @@ #include "common.h" typedef enum { + PRE_EVERYTHING, PRE_INIT, PRE_TEST, POST_TEST, POST_FINI, + POST_EVERYTHING, } e_report_status; typedef void (*f_report_hook)(void *); diff --git a/samples/simple.c b/samples/simple.c index 19d4336..7507483 100644 --- a/samples/simple.c +++ b/samples/simple.c @@ -19,10 +19,17 @@ ReportHook(PRE_INIT) { printf("testing %s in category %s\n", test->name, test->category); } -void criterion_init(void) { +ReportHook(POST_TEST) { + struct criterion_test_stats *stats = data; + + printf("Asserts: [%d passed, %d failed, %d total]\n", + stats->passed, stats->failed, stats->passed + stats->failed); +} + +ReportHook(PRE_EVERYTHING) { puts("criterion_init"); } -void criterion_fini(void) { +ReportHook(POST_EVERYTHING) { puts("criterion_fini"); } diff --git a/src/report.c b/src/report.c index c647c74..5e53ac0 100644 --- a/src/report.c +++ b/src/report.c @@ -15,16 +15,17 @@ } \ } +IMPL_CALL_REPORT_HOOKS(PRE_EVERYTHING); IMPL_CALL_REPORT_HOOKS(PRE_INIT); IMPL_CALL_REPORT_HOOKS(PRE_TEST); IMPL_CALL_REPORT_HOOKS(POST_TEST); IMPL_CALL_REPORT_HOOKS(POST_FINI); +IMPL_CALL_REPORT_HOOKS(POST_EVERYTHING); ReportHook(PRE_INIT) { struct criterion_test *test = data; - printf("%s::%s: ", test->category, test->name); - fflush(stdout); + fprintf(stderr, "%s::%s: RUNNING\n", test->category, test->name); } ReportHook(POST_TEST) { @@ -32,8 +33,11 @@ ReportHook(POST_TEST) { int success = stats->failed == 0; - printf("%s\n", success ? "SUCCESS" : "FAILURE"); + fprintf(stderr, "%s::%s: %s\n", stats->test->category, stats->test->name, success ? "SUCCESS" : "FAILURE"); } ReportHook(PRE_TEST) {} ReportHook(POST_FINI) {} + +ReportHook(PRE_EVERYTHING) {} +ReportHook(POST_EVERYTHING) {} diff --git a/src/report.h b/src/report.h index 10666e1..3efeca2 100644 --- a/src/report.h +++ b/src/report.h @@ -10,9 +10,11 @@ extern f_report_hook __stop_criterion_hooks_##Kind; \ void call_report_hooks_##Kind(void *data) +DECL_CALL_REPORT_HOOKS(PRE_EVERYTHING); DECL_CALL_REPORT_HOOKS(PRE_INIT); DECL_CALL_REPORT_HOOKS(PRE_TEST); DECL_CALL_REPORT_HOOKS(POST_TEST); DECL_CALL_REPORT_HOOKS(POST_FINI); +DECL_CALL_REPORT_HOOKS(POST_EVERYTHING); #endif /* !REPORT_H_ */ diff --git a/src/runner.c b/src/runner.c index 04ab118..13cc722 100644 --- a/src/runner.c +++ b/src/runner.c @@ -67,11 +67,11 @@ static void run_test(struct criterion_test *test) { } void run_all(void) { + report(PRE_EVERYTHING, NULL); map_tests(run_test); + report(POST_EVERYTHING, NULL); } int main(void) { - (criterion_init ?: nothing)(); run_all(); - (criterion_fini ?: nothing)(); }