diff --git a/misc/spoofed_criterion/include/criterion/criterion.h b/misc/spoofed_criterion/include/criterion/criterion.h index df909e2ad..935f09676 100644 --- a/misc/spoofed_criterion/include/criterion/criterion.h +++ b/misc/spoofed_criterion/include/criterion/criterion.h @@ -3,6 +3,7 @@ struct fake_criterion_test { void (*test)(void); + void (*init)(void); int exit_code; }; diff --git a/misc/spoofed_criterion/include/criterion/logging.h b/misc/spoofed_criterion/include/criterion/logging.h index 5b1342b5c..e0016e8a5 100644 --- a/misc/spoofed_criterion/include/criterion/logging.h +++ b/misc/spoofed_criterion/include/criterion/logging.h @@ -1,4 +1,5 @@ #include #include -#define cr_log_info printf +#define cr_log_info(f, ...) printf(f "\n", ##__VA_ARGS__) +#define cr_log_error(f, ...) fprintf(stderr, f "\n", ##__VA_ARGS__) diff --git a/misc/spoofed_criterion/include/criterion/new/assert.h b/misc/spoofed_criterion/include/criterion/new/assert.h index 40df9b35c..854bbc294 100644 --- a/misc/spoofed_criterion/include/criterion/new/assert.h +++ b/misc/spoofed_criterion/include/criterion/new/assert.h @@ -1,6 +1,10 @@ #include #define cr_assert assert -#define cr_assert_eq(a,b) cr_assert((a) == (b)) -#define cr_assert_lt(a,b) cr_assert((a) < (b)) -#define cr_fatal assert +#define cr_assert_eq(a, b) cr_assert((a) == (b)) +#define cr_assert_lt(a, b) cr_assert((a) < (b)) +#define cr_fatal(s) \ + do { \ + fprintf(stderr, s "\n"); \ + exit(1); \ + } while (0) diff --git a/misc/spoofed_criterion/test_runner.c b/misc/spoofed_criterion/test_runner.c index 8d4de51dd..fcad7c365 100644 --- a/misc/spoofed_criterion/test_runner.c +++ b/misc/spoofed_criterion/test_runner.c @@ -16,6 +16,9 @@ int main() { pid_t pid = fork(); bool in_child = pid == 0; if (in_child) { + if (test_info->init) { + (*test_info->init)(); + } (*test_info->test)(); return 0; } @@ -27,11 +30,10 @@ int main() { return 2; } int exit_status = WEXITSTATUS(stat); - if (exit_status == test_info->exit_code) { - return 0; - } else { + if (exit_status != test_info->exit_code) { fprintf(stderr, "forked test child exited with status %d, but %d was expected\n", exit_status, test_info->exit_code); return 1; } } + return 0; }