X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/7affb40735592998dc047f216b48f9b771e4df1a..319d7107dfbed2e6248f61ad463fa6ac55ebe178:/libtests/test.h diff --git a/libtests/test.h b/libtests/test.h index 7a0ef5d..48c8956 100644 --- a/libtests/test.h +++ b/libtests/test.h @@ -22,26 +22,21 @@ #ifndef TEST_H #define TEST_H -#include -#include "types.h" +#include "common.h" -#include -#include -#include #include #include -#include #include #include #include #include -#include #include #include #include #include #include #include +#include #include "mem.h" #include "log.h" @@ -73,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 { \ @@ -126,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); @@ -133,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); \ @@ -140,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