diff options
Diffstat (limited to 'tests/upb_test.h')
-rw-r--r-- | tests/upb_test.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/tests/upb_test.h b/tests/upb_test.h index 652977b..60714ba 100644 --- a/tests/upb_test.h +++ b/tests/upb_test.h @@ -9,25 +9,35 @@ #include <stdio.h> #include <stdlib.h> +#include <stdint.h> #ifdef __cplusplus extern "C" { #endif int num_assertions = 0; +uint32_t testhash = 0; + +#define PRINT_FAILURE(expr) \ + fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \ + fprintf(stderr, "expr: %s\n", #expr); \ + if (testhash) { \ + fprintf(stderr, "assertion failed running test %x. " \ + "Run with the arg %x to run only this test.\n", \ + testhash, testhash); \ + } + #define ASSERT(expr) do { \ ++num_assertions; \ if (!(expr)) { \ - fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \ - fprintf(stderr, "expr: %s\n", #expr); \ + PRINT_FAILURE(expr) \ abort(); \ } \ } while (0) #define ASSERT_NOCOUNT(expr) do { \ if (!(expr)) { \ - fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \ - fprintf(stderr, "expr: %s\n", #expr); \ + PRINT_FAILURE(expr) \ abort(); \ } \ } while (0) @@ -35,8 +45,7 @@ int num_assertions = 0; #define ASSERT_STATUS(expr, status) do { \ ++num_assertions; \ if (!(expr)) { \ - fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \ - fprintf(stderr, "expr: %s\n", #expr); \ + PRINT_FAILURE(expr) \ fprintf(stderr, "failed status: %s\n", upb_status_getstr(status)); \ abort(); \ } \ |