[Issue #15] Fixed incorrect reporting on setup/teardown crash

This commit is contained in:
Snaipe 2015-04-10 23:21:03 +02:00
parent 8a29e3e792
commit 14aa37594d
7 changed files with 66 additions and 35 deletions

View file

@ -91,16 +91,17 @@ void criterion_log(enum criterion_logging_level level, const char *msg, ...);
# define criterion_pimportant(...) criterion_plog(CRITERION_IMPORTANT, __VA_ARGS__)
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_stats *stats);
void (*log_post_all )(struct criterion_global_stats *stats);
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_other_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_stats *stats);
void (*log_post_all )(struct criterion_global_stats *stats);
};
extern struct criterion_output_provider normal_logging;

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: criterion 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-04-10 00:15+0200\n"
"POT-Creation-Date: 2015-04-10 23:08+0200\n"
"PO-Revision-Date: 2015-04-03 17:58+0200\n"
"Last-Translator: <franklinmathieu@gmail.com>\n"
"Language-Team: French\n"
@ -28,22 +28,22 @@ msgstr "Criterion v%s\n"
msgid "%1$s::%2$s\n"
msgstr "%1$s::%2$s\n"
#: src/log/normal.c:44 src/log/normal.c:110
#: src/log/normal.c:47 src/log/normal.c:121
#, c-format
msgid " %s\n"
msgstr " %s\n"
#: src/log/normal.c:70
#: src/log/normal.c:76
#, c-format
msgid "%1$s::%2$s: Test is disabled\n"
msgstr "%1$s::%2$s: Le test est désactivé\n"
#: src/log/normal.c:71
#: src/log/normal.c:77
#, c-format
msgid "%1$s::%2$s: Suite is disabled\n"
msgstr "%1$s::%2$s: La suite est désactivée\n"
#: src/log/normal.c:85
#: src/log/normal.c:94
#, c-format
msgid ""
"%1$sSynthesis: Tested: %2$s%3$lu%4$s | Passing: %5$s%6$lu%7$s | Failing: %8$s"
@ -52,19 +52,26 @@ msgstr ""
"%1$sSynthèse: Testés: %2$s%3$lu%4$s | Validés: %5$s%6$lu%7$s | Échoués: %8$s"
"%9$lu%10$s | Plantages: %11$s%12$lu%13$s %14$s\n"
#: src/log/normal.c:104
#: src/log/normal.c:115
#, c-format
msgid "%1$s%2$s%3$s:%4$s%5$d%6$s: Assertion failed: %7$s\n"
msgstr "%1$s%2$s%3$s:%4$s%5$d%6$s: Échec d'assertion: %7$s\n"
#: src/log/normal.c:117
#: src/log/normal.c:128
#, c-format
msgid "%1$s%2$s%3$s:%4$s%5$u%6$s: Unexpected signal caught below this line!\n"
msgstr ""
"%1$s%2$s%3$s:%4$s%5$u%6$s: Un signal inattendu a été reçu après cette "
"ligne!\n"
#: src/log/normal.c:121
#: src/log/normal.c:132
#, c-format
msgid "%1$s::%2$s: CRASH!\n"
msgstr "%1$s::%2$s: PLANTAGE!\n"
#: src/log/normal.c:139
#, c-format
msgid "%1$sWarning! This test crashed during its setup or teardown.%2$s\n"
msgstr ""
"%1$sAttention! Ce test a planté pendant son initialisation ou sa "
"finalisation.%2$s\n"

View file

@ -134,6 +134,12 @@ void normal_log_test_crash(struct criterion_test_stats *stats) {
stats->test->name);
}
void normal_log_other_crash(UNUSED struct criterion_test_stats *stats) {
criterion_pimportant(CRITERION_PREFIX_DASHES,
_("%1$sWarning! This test crashed during its setup or teardown.%2$s\n"),
FG_BOLD, RESET);
}
void normal_log_pre_suite(struct criterion_suite_set *set) {
criterion_pinfo(CRITERION_PREFIX_EQUALS,
_s("Running %1$s%2$lu%3$s test from %4$s%5$s%6$s:\n",
@ -144,12 +150,13 @@ void normal_log_pre_suite(struct criterion_suite_set *set) {
}
struct criterion_output_provider normal_logging = {
.log_pre_all = normal_log_pre_all,
.log_pre_init = normal_log_pre_init,
.log_pre_suite = normal_log_pre_suite,
.log_assert = normal_log_assert,
.log_test_crash = normal_log_test_crash,
.log_post_test = normal_log_post_test,
.log_post_suite = normal_log_post_suite,
.log_post_all = normal_log_post_all,
.log_pre_all = normal_log_pre_all,
.log_pre_init = normal_log_pre_init,
.log_pre_suite = normal_log_pre_suite,
.log_assert = normal_log_assert,
.log_test_crash = normal_log_test_crash,
.log_other_crash = normal_log_other_crash,
.log_post_test = normal_log_post_test,
.log_post_suite = normal_log_post_suite,
.log_post_all = normal_log_post_all,
};

View file

@ -50,9 +50,6 @@
IMPL_CALL_REPORT_HOOKS(Type); \
ReportHook(Type)
#define log(Type, Arg) \
(criterion_options.output_provider->log_ ## Type ?: nothing)(Arg);
__attribute__((always_inline))
static inline void nothing() {}

View file

@ -43,4 +43,7 @@ DECL_CALL_REPORT_HOOKS(POST_FINI);
DECL_CALL_REPORT_HOOKS(POST_SUITE);
DECL_CALL_REPORT_HOOKS(POST_ALL);
#define log(Type, Arg) \
(criterion_options.output_provider->log_ ## Type ?: nothing)(Arg);
#endif /* !REPORT_H_ */

View file

@ -184,14 +184,20 @@ static void run_test(struct criterion_global_stats *stats,
if (proc == NULL && !is_runner())
return;
bool test_started = false;
bool normal_finish = false;
struct event *ev;
while ((ev = worker_read_event(proc)) != NULL) {
stat_push_event(stats, suite_stats, test_stats, ev);
switch (ev->kind) {
case PRE_INIT: report(PRE_INIT, test); break;
case PRE_TEST: report(PRE_TEST, test); break;
case PRE_TEST: report(PRE_TEST, test);
test_started = true;
break;
case ASSERT: report(ASSERT, ev->data); break;
case POST_TEST: report(POST_TEST, test_stats); break;
case POST_TEST: report(POST_TEST, test_stats);
normal_finish = true;
break;
case POST_FINI: report(POST_FINI, test_stats); break;
}
sfree(ev);
@ -199,6 +205,16 @@ static void run_test(struct criterion_global_stats *stats,
struct process_status status = wait_proc(proc);
if (status.kind == SIGNAL) {
if (normal_finish || !test_started) {
log(other_crash, test_stats);
if (!test_started) {
stat_push_event(stats,
suite_stats,
test_stats,
&(struct event) { .kind = TEST_CRASH });
}
return;
}
test_stats->signal = status.status;
if (test->data->signal == 0) {
push_event(TEST_CRASH);

View file

@ -29,7 +29,7 @@
static void nothing() {};
static void push_pre_suite();
static void push_pre_test();
static void push_pre_init();
static void push_assert();
static void push_post_test();
static void push_test_crash();
@ -81,8 +81,8 @@ void stat_push_event(s_glob_stats *stats,
static void (*const handles[])(s_glob_stats *, s_suite_stats *, s_test_stats *, void *) = {
nothing, // PRE_ALL
push_pre_suite, // PRE_SUITE
nothing, // PRE_INIT
push_pre_test, // PRE_TEST
push_pre_init, // PRE_INIT
nothing, // PRE_TEST
push_assert, // ASSERT
push_test_crash, // TEST_CRASH
push_post_test, // POST_TEST
@ -113,7 +113,7 @@ static inline bool is_disabled(struct criterion_test *t,
return t->data->disabled || (s->data && s->data->disabled);
}
static void push_pre_test(s_glob_stats *stats,
static void push_pre_init(s_glob_stats *stats,
s_suite_stats *suite,
s_test_stats *test,
UNUSED void *ptr) {