Replaced criterion_{init,fini} with report hooks

This commit is contained in:
Snaipe 2015-02-02 13:00:16 +01:00
parent 2e2b2bc2df
commit b0403cf36d
5 changed files with 22 additions and 7 deletions

View file

@ -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 *);

View file

@ -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");
}

View file

@ -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) {}

View file

@ -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_ */

View file

@ -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)();
}