Lely core libraries  2.2.5
tap.h
Go to the documentation of this file.
1 
21 #ifndef LELY_TAP_TAP_H_
22 #define LELY_TAP_TAP_H_
23 
24 #include <lely/features.h>
25 
26 #ifdef __GNUC__
27 #pragma GCC diagnostic ignored "-Wformat-zero-length"
28 #endif
29 
31 #ifdef __cplusplus
32 #define TAP_ARGS_HAS_COMMA(...) \
33  TAP_ARGS_AT_127(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
34  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
35  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
36  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
37  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
38  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
39  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
40  1, 1, 1, 1, 0)
41 #define TAP_ARGS_AT_127(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \
42  _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, \
43  _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, \
44  _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, \
45  _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
46  _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, \
47  _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, \
48  _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95, _96, \
49  _97, _98, _99, _100, _101, _102, _103, _104, _105, _106, _107, \
50  _108, _109, _110, _111, _112, _113, _114, _115, _116, _117, \
51  _118, _119, _120, _121, _122, _123, _124, _125, _126, ...) \
52  TAP_ARGS_AT_127_(__VA_ARGS__, )
53 #define TAP_ARGS_AT_127_(_127, ...) _127
54 #else
55 #define TAP_ARGS_HAS_COMMA(...) \
56  TAP_ARGS_AT_63(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
57  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
58  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
59  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
60 #define TAP_ARGS_AT_63(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \
61  _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, \
62  _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, \
63  _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, \
64  _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
65  _61, _62, ...) \
66  TAP_ARGS_AT_63_(__VA_ARGS__, )
67 #define TAP_ARGS_AT_63_(_63, ...) _63
68 #endif // __cplusplus
69 
71 #define TAP_ARGS_DEFAULT(arg, ...) \
72  TAP_ARGS_DEFAULT_(TAP_ARGS_HAS_COMMA(__VA_ARGS__), arg, __VA_ARGS__)
73 #define TAP_ARGS_DEFAULT_(n, ...) TAP_ARGS_DEFAULT__(n, __VA_ARGS__)
74 #define TAP_ARGS_DEFAULT__(n, ...) TAP_ARGS_DEFAULT_##n(__VA_ARGS__)
75 #define TAP_ARGS_DEFAULT_0(arg, ...) __VA_ARGS__, arg
76 #define TAP_ARGS_DEFAULT_1(arg, ...) __VA_ARGS__
77 
85 #define tap_plan(...) tap_plan_(TAP_ARGS_DEFAULT("", __VA_ARGS__))
86 #define tap_plan_(...) tap_plan__(__VA_ARGS__)
87 #define tap_plan__(n, ...) tap_plan_impl(n, "" __VA_ARGS__)
88 
96 #define tap_test(...) tap_test_(TAP_ARGS_DEFAULT("", __VA_ARGS__))
97 #define tap_test_(...) tap_test__(__VA_ARGS__)
98 #define tap_test__(expr, ...) \
99  tap_test_impl(!!(expr), #expr, __FILE__, __LINE__, "" __VA_ARGS__)
100 
109 #define tap_pass(...) tap_test_impl(1, "", __FILE__, __LINE__, "" __VA_ARGS__)
110 
119 #define tap_fail(...) tap_test_impl(0, "", __FILE__, __LINE__, "" __VA_ARGS__)
120 
126 #define tap_todo(...) tap_todo_(TAP_ARGS_DEFAULT("", __VA_ARGS__))
127 #define tap_todo_(...) tap_todo__(__VA_ARGS__)
128 #define tap_todo__(expr, ...) \
129  tap_test_impl(!!(expr), #expr, __FILE__, __LINE__, \
130  " # TODO " __VA_ARGS__)
131 
136 #define tap_skip(...) tap_skip_(TAP_ARGS_DEFAULT("", __VA_ARGS__))
137 #define tap_skip_(...) tap_skip__(__VA_ARGS__)
138 #define tap_skip__(expr, ...) tap_pass(" # SKIP " __VA_ARGS__)
139 
145 #define tap_diag(...) tap_diag_impl("# " __VA_ARGS__)
146 
153 #define tap_abort(...) tap_abort_impl("" __VA_ARGS__)
154 
159 // clang-format off
160 #define tap_assert(expr) \
161  ((expr) ? (void)0 \
162  : tap_abort("%s:%d: Assertion `%s' failed.", __FILE__, \
163  __LINE__, #expr))
164 // clang-format on
165 
166 #ifdef __cplusplus
167 extern "C" {
168 #endif
169 
170 void tap_plan_impl(int n, const char *format, ...) format_printf__(2, 3);
171 int tap_test_impl(int test, const char *expr, const char *file, int line,
172  const char *format, ...) format_printf__(5, 6);
173 void tap_diag_impl(const char *format, ...) format_printf__(1, 2);
174 _Noreturn void tap_abort_impl(const char *format, ...) format_printf__(1, 2);
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif // !LELY_TAP_TAP_H_
features.h
file
A regular file handle.
Definition: file.c:39
_Noreturn
#define _Noreturn
A function declared with a _Noreturn function specifier SHALL not return to its caller.
Definition: features.h:214