浏览该文件的文档.
64#define VA_NARG(args...) VA_NARG_(0, ##args, VA_RSEQ_N())
65#define VA_NARG_(args...) VA_ARG_N(args)
66#define VA_ARG_N(_0, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, N, ...) N
67#define VA_RSEQ_N() 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
70#define VA_FIRST(args...) VA_FIRST_(args)
71#define VA_FIRST_(F, ...) F
74#define VA_FIRST_STR(args...) VA_FIRST_STR_(args)
75#define VA_FIRST_STR_(F, ...) #F
78#define VA_REST_(F, args...) args
79#define VA_REST(args...) VA_REST_(args)
112#define ut_set_quiet(num) \
115#define ut_assert(test...) \
119 if (!(VA_FIRST(test))) \
126 "| - " _bred("FAIL %d") " " _black("%s:%d") ": '" _yellow("%s") "' ", \
128 __FILE__, __LINE__, VA_FIRST_STR(test)); \
129 if (VA_NARG(test) == 1 || ut.quiet > 1) \
130 printf(_bred(UT_FAIL)); \
132 printf(_bred(UT_FAIL) "\n" \
133 "| : " VA_REST(test)); \
143 "| - " _bgreen("PASS %d") " " _black("%s:%d") ": '" _yellow("%s") "' ", \
145 __FILE__, __LINE__, VA_FIRST_STR(test)); \
146 if (VA_NARG(test) == 1 || ut.quiet > 1) \
147 printf(_bgreen(UT_PASS)); \
149 printf(_bgreen(UT_PASS) "\n" \
150 "| : " VA_REST(test)); \
156#define ut_dec_test(testname) \
157 int testname##_test()
159#define ut_def_test(testname, ...) \
160 int testname##_test() \
163 ut.u_t = 0, ut.u_p = 0, ut.u_f = 0; \
168 "|-" _bgreen(" %d " UT_PASS) " - ", \
170 printf(_bred("%d " UT_FAIL), ut.u_f); \
171 printf(" - " _bold("%d all") " \n|", ut.u_t); \
176#define ut_run_test(testname) \
179 if (ut.n_test == 0 && ut.quiet < 5) \
182 "|============== Unit tests ==============="); \
188 "|> " _bold("%s") _black(" %s:%d "), \
189 #testname, __FILE__, __LINE__); \
191 if (!testname##_test()) \
194 if (ut.quiet > 2 && ut.quiet < 5) \
196 printf(_bgreen(UT_PASS)); \
202 if (ut.quiet > 3 && ut.quiet < 5) \
204 printf(_bred(UT_FAIL)); \
209#define ut_print_test() \
215 "|============== Test Result =============="); \
217 "| " _bgreen("%d " UT_PASS) " and ", \
219 printf(_bred("%d " UT_FAIL), ut.n_fail); \
220 printf(" in " _bold("%d TEST(S)"), ut.n_test); \
221 if (ut.n_pass == ut.n_test) \
223 "|============" _green(" ALL TESTS PASSED ") "==========="); \
226 "|===========" _red(" %d TEST(S) FAILED ") "============" \