Added PRE/POST_SUITE hooks
This commit is contained in:
parent
3274a78be9
commit
374542db5e
5 changed files with 31 additions and 1 deletions
|
@ -42,12 +42,14 @@ void criterion_log(enum criterion_logging_level level, const char *msg, ...);
|
|||
|
||||
struct criterion_output_provider {
|
||||
void (*log_pre_all )(struct criterion_test_set *set);
|
||||
void (*log_pre_suite )(struct criterion_suite_set *set);
|
||||
void (*log_pre_init )(struct criterion_test *test);
|
||||
void (*log_pre_test )(struct criterion_test *test);
|
||||
void (*log_assert )(struct criterion_assert_stats *stats);
|
||||
void (*log_test_crash)(struct criterion_test_stats *stats);
|
||||
void (*log_post_test )(struct criterion_test_stats *stats);
|
||||
void (*log_post_fini )(struct criterion_test_stats *stats);
|
||||
void (*log_post_suite)(struct criterion_suite_set *set);
|
||||
void (*log_post_all )(struct criterion_global_stats *stats);
|
||||
};
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#define FG_BOLD NORMALIZE("\e[0;1m")
|
||||
#define FG_RED NORMALIZE("\e[0;31m")
|
||||
#define FG_GREEN NORMALIZE("\e[0;32m")
|
||||
#define FG_GOLD NORMALIZE("\e[0;33m")
|
||||
#define FG_BLUE NORMALIZE("\e[0;34m")
|
||||
#define RESET NORMALIZE("\e[0m")
|
||||
|
||||
|
@ -95,8 +96,21 @@ void normal_log_test_crash(struct criterion_test_stats *stats) {
|
|||
stats->test->name);
|
||||
}
|
||||
|
||||
void normal_log_pre_suite(struct criterion_suite_set *set) {
|
||||
criterion_info("[%s====%s] ", FG_BLUE, RESET);
|
||||
criterion_info("Running %s" SIZE_T_FORMAT "%s test%s from %s%s%s:\n",
|
||||
FG_BLUE,
|
||||
set->tests->size,
|
||||
RESET,
|
||||
set->tests->size == 1 ? "" : "s",
|
||||
FG_GOLD,
|
||||
set->suite.name,
|
||||
RESET);
|
||||
}
|
||||
|
||||
struct criterion_output_provider normal_logging = {
|
||||
.log_pre_init = normal_log_pre_init,
|
||||
.log_pre_suite = normal_log_pre_suite,
|
||||
.log_post_test = normal_log_post_test,
|
||||
.log_assert = normal_log_assert,
|
||||
.log_post_all = normal_log_post_all,
|
||||
|
|
|
@ -71,6 +71,10 @@ IMPL_REPORT_HOOK(PRE_ALL)(struct criterion_test_set *set) {
|
|||
log(pre_all, set);
|
||||
}
|
||||
|
||||
IMPL_REPORT_HOOK(PRE_SUITE)(struct criterion_suite_set *set) {
|
||||
log(pre_suite, set);
|
||||
}
|
||||
|
||||
IMPL_REPORT_HOOK(PRE_INIT)(struct criterion_test *test) {
|
||||
log(pre_init, test);
|
||||
}
|
||||
|
@ -95,6 +99,10 @@ IMPL_REPORT_HOOK(POST_FINI)(struct criterion_test_stats *stats) {
|
|||
log(post_fini, stats);
|
||||
}
|
||||
|
||||
IMPL_REPORT_HOOK(POST_SUITE)(struct criterion_suite_set *set) {
|
||||
log(post_suite, set);
|
||||
}
|
||||
|
||||
IMPL_REPORT_HOOK(POST_ALL)(struct criterion_global_stats *stats) {
|
||||
log(post_all, stats);
|
||||
}
|
||||
|
|
|
@ -33,12 +33,14 @@
|
|||
void call_report_hooks_##Kind(void *data)
|
||||
|
||||
DECL_CALL_REPORT_HOOKS(PRE_ALL);
|
||||
DECL_CALL_REPORT_HOOKS(PRE_SUITE);
|
||||
DECL_CALL_REPORT_HOOKS(PRE_INIT);
|
||||
DECL_CALL_REPORT_HOOKS(PRE_TEST);
|
||||
DECL_CALL_REPORT_HOOKS(ASSERT);
|
||||
DECL_CALL_REPORT_HOOKS(TEST_CRASH);
|
||||
DECL_CALL_REPORT_HOOKS(POST_TEST);
|
||||
DECL_CALL_REPORT_HOOKS(POST_FINI);
|
||||
DECL_CALL_REPORT_HOOKS(POST_SUITE);
|
||||
DECL_CALL_REPORT_HOOKS(POST_ALL);
|
||||
|
||||
#endif /* !REPORT_H_ */
|
||||
|
|
|
@ -97,13 +97,17 @@ static void map_tests(struct criterion_test_set *set, struct criterion_global_st
|
|||
if ((s->suite.data && s->suite.data->disabled) || !s->tests)
|
||||
continue;
|
||||
|
||||
report(PRE_SUITE, s);
|
||||
|
||||
FOREACH_SET(struct criterion_test *t, s->tests) {
|
||||
fun(stats, t, &s->suite);
|
||||
if (criterion_options.fail_fast && stats->tests_failed > 0)
|
||||
return;
|
||||
break;
|
||||
if (!is_runner())
|
||||
return;
|
||||
}
|
||||
|
||||
report(POST_SUITE, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue