[Issues #65,#66] Delayed TAP output until the end of the tests

This commit is contained in:
Snaipe 2015-10-02 10:00:51 +02:00
parent 12787b34ba
commit 10c9e4eed2
3 changed files with 41 additions and 36 deletions

View file

@ -45,6 +45,7 @@ struct criterion_test_stats {
int exit_code;
float elapsed_time;
bool timed_out;
bool crashed;
unsigned progress;
const char *file;

View file

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

View file

@ -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,
};