aboutsummaryrefslogtreecommitdiff
path: root/tests/test_util.h
blob: 1d8c80ed228e4704c1b97849085e505e32df4ed4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 */