diff options
Diffstat (limited to 'tests/test_util.h')
| -rw-r--r-- | tests/test_util.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_util.h b/tests/test_util.h new file mode 100644 index 0000000..1d8c80e --- /dev/null +++ b/tests/test_util.h @@ -0,0 +1,29 @@ +/* Assertion harness for the C tests: every check reports, nothing aborts, and + * the process exit status is the verdict. Keeping going after a failure is + * deliberate; when a numeric change breaks several gates at once, the full + * list localises it faster than the first failure alone. */ + +#ifndef PYSEG_TEST_UTIL_H +#define PYSEG_TEST_UTIL_H + +#include <stdio.h> + +static int test_failures; +static int test_checks; + +#define TEST_ASSERT(cond, ...) \ + do { \ + ++test_checks; \ + if (!(cond)) { \ + ++test_failures; \ + fprintf(stderr, "FAIL %s:%d: ", __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + fputc('\n', stderr); \ + } \ + } while (0) + +#define TEST_REPORT() \ + (fprintf(stderr, "%s: %d checks, %d failed\n", __FILE__, test_checks, test_failures), \ + test_failures ? 1 : 0) + +#endif /* PYSEG_TEST_UTIL_H */ |
