X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/05b75f8d50b83e943af3be4071449304d82dbdcd..2fadbbc60560fe8562d7b6e652f8788c1d084d5f:/libtests/test.h diff --git a/libtests/test.h b/libtests/test.h index cb26b62..48c8956 100644 --- a/libtests/test.h +++ b/libtests/test.h @@ -30,13 +30,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include "mem.h" #include "log.h" @@ -68,6 +68,7 @@ extern long long tests, errors; extern int fail_first; extern int verbose; +extern int skipped; /** @brief Checks that @p expr is nonzero */ #define insist(expr) do { \ @@ -121,6 +122,21 @@ extern int verbose; ++tests; \ } while(0) +#define check_fatal(WHAT) do { \ + void (*const save_exitfn)(int) attribute((noreturn)) = exitfn; \ + \ + exitfn = test_exitfn; \ + if(setjmp(fatal_env) == 0) { \ + fprintf(stderr, "Expect an error:\n "); \ + (void)(WHAT); \ + fprintf(stderr, "\n%s:%d: %s unexpectedly returned\n", \ + __FILE__, __LINE__, #WHAT); \ + count_error(); \ + } \ + ++tests; \ + exitfn = save_exitfn; \ +} while(0) + void count_error(void); const char *format(const char *s); const char *format_utf32(const uint32_t *s); @@ -128,6 +144,9 @@ uint32_t *ucs4parse(const char *s); const char *do_printf(const char *fmt, ...); void test_init(int argc, char **argv); +extern jmp_buf fatal_env; +void test_exitfn(int) attribute((noreturn)); + #define TEST(name) \ int main(int argc, char **argv) { \ test_init(argc, argv); \ @@ -135,7 +154,11 @@ void test_init(int argc, char **argv); if(errors || verbose) \ fprintf(stderr, "test_"#name": %lld errors out of %lld tests\n", \ errors, tests); \ - return !!errors; \ + if(errors) \ + return 1; \ + if(skipped) \ + return 77; \ + return 0; \ } \ \ struct swallow_semicolon