X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/b0a578cbad5b994e163de90e7ee91b423dba30fa..3943e9eceb6a7fb8d93c9fa8d23422eae8aabafd:/libtests/test.h diff --git a/libtests/test.h b/libtests/test.h index cb26b62..8af85d5 100644 --- a/libtests/test.h +++ b/libtests/test.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "mem.h" #include "log.h" @@ -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); \