Commit | Line | Data |
---|---|---|
9f4a25d3 | 1 | /* |
9d16b343 MJ |
2 | * SPDX-License-Identifier: BSD-2-Clause |
3 | * | |
9f4a25d3 SM |
4 | * Copyright (C) 2004 Nik Clayton |
5 | * Copyright (C) 2017 Jérémie Galarneau | |
86a96e6c CB |
6 | */ |
7 | ||
7966af57 SM |
8 | #ifdef __cplusplus |
9 | extern "C" { | |
10 | #endif | |
11 | ||
86a96e6c CB |
12 | /* '## __VA_ARGS__' is a gcc'ism. C99 doesn't allow the token pasting |
13 | and requires the caller to add the final comma if they've ommitted | |
14 | the optional arguments */ | |
15 | #ifdef __GNUC__ | |
28f23191 JG |
16 | #define ok(e, test, ...) \ |
17 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__) : \ | |
18 | _gen_result(0, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__)) | |
19 | ||
20 | #define ok1(e) \ | |
21 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \ | |
22 | _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) | |
23 | ||
24 | #define pass(test, ...) ok(1, test, ##__VA_ARGS__) | |
25 | #define fail(test, ...) ok(0, test, ##__VA_ARGS__) | |
26 | ||
27 | #define skip_start(test, n, fmt, ...) \ | |
28 | do { \ | |
29 | if ((test)) { \ | |
30 | skip(n, fmt, ##__VA_ARGS__); \ | |
31 | continue; \ | |
86a96e6c | 32 | } |
f3af9f34 | 33 | #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* __GNUC__ */ |
28f23191 JG |
34 | #define ok(e, ...) \ |
35 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, __VA_ARGS__) : \ | |
36 | _gen_result(0, __func__, __FILE__, __LINE__, __VA_ARGS__)) | |
37 | ||
38 | #define ok1(e) \ | |
39 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \ | |
40 | _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) | |
41 | ||
42 | #define pass(...) ok(1, __VA_ARGS__) | |
43 | #define fail(...) ok(0, __VA_ARGS__) | |
44 | ||
45 | #define skip_start(test, n, ...) \ | |
46 | do { \ | |
47 | if ((test)) { \ | |
48 | skip(n, __VA_ARGS__); \ | |
49 | continue; \ | |
86a96e6c CB |
50 | } |
51 | #else /* __STDC_VERSION__ */ | |
28f23191 | 52 | #error "Needs gcc or C99 compiler for variadic macros." |
86a96e6c CB |
53 | #endif /* __STDC_VERSION__ */ |
54 | ||
28f23191 JG |
55 | #define skip_end() \ |
56 | } \ | |
57 | while (0) \ | |
58 | ; | |
86a96e6c | 59 | |
9f4a25d3 | 60 | #ifdef __MINGW_PRINTF_FORMAT |
28f23191 | 61 | #define TAP_PRINTF_FORMAT __MINGW_PRINTF_FORMAT |
9f4a25d3 | 62 | #else |
28f23191 | 63 | #define TAP_PRINTF_FORMAT printf |
9f4a25d3 SM |
64 | #endif |
65 | ||
28f23191 JG |
66 | __attribute__((format(TAP_PRINTF_FORMAT, 5, 6))) unsigned int |
67 | _gen_result(int, const char *, const char *, unsigned int, const char *, ...); | |
86a96e6c CB |
68 | |
69 | int plan_no_plan(void); | |
28f23191 | 70 | __attribute__((noreturn)) int plan_skip_all(const char *); |
86a96e6c CB |
71 | int plan_tests(unsigned int); |
72 | ||
28f23191 | 73 | __attribute__((format(TAP_PRINTF_FORMAT, 1, 2))) unsigned int diag(const char *, ...); |
9f4a25d3 | 74 | void diag_multiline(const char *); |
86a96e6c | 75 | |
28f23191 | 76 | __attribute__((format(TAP_PRINTF_FORMAT, 2, 3))) int skip(unsigned int, const char *, ...); |
86a96e6c | 77 | |
28f23191 | 78 | __attribute__((format(TAP_PRINTF_FORMAT, 1, 2))) void todo_start(const char *, ...); |
86a96e6c CB |
79 | void todo_end(void); |
80 | ||
81 | int exit_status(void); | |
7966af57 SM |
82 | |
83 | #ifdef __cplusplus | |
84 | } | |
85 | #endif |