-
Notifications
You must be signed in to change notification settings - Fork 0
/
miniunit.h
51 lines (47 loc) · 2.39 KB
/
miniunit.h
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define mu_assert(test...) \
do \
{ \
if (!(VA_FIRST(test))) \
{ \
printf(BORED FAIL ENDL \
"|\\_[" BORED "FAIL" RST \
"] at " BOWHT "./%s:%d" RST \
" for '" BOYEL "%s" RST "' ", \
__FILE__, __LINE__, VA_FIRST_STR(test)); \
if (VA_NARG(test) == 1) \
printf(BORED FAIL); \
else \
printf(BORED FAIL " " FMAG VA_REST(test)); \
printf(ENDL); \
return 1; \
} \
} while (0)
static int n_test; /* number of tests */
static int n_pass; /* number of tests passed */
static int n_fail; /* number of tests failed */
#define mu_run_test(test) \
do \
{ \
++n_test; \
printf("|- " BOWHT "%s" FBLK " ./%s:%d ... " RST, \
#test, __FILE__, __LINE__); \
if (!test) \
{ \
++n_pass; \
printf(BOGRN PASS ENDL); \
} \
else \
++n_fail; \
} while (0)
void mu_test_results()
{
printf("\\_________________________________\n");
printf(BOGRN "%d " PASS RST " and ", n_pass);
printf(n_fail ? BORED "%d " FAIL : BOLD FBLK "%d " FAIL, n_fail);
printf(RST " in " BOWHT "%d" RST " TEST(S)" ENDL, n_test);
if (n_pass == n_test)
printf(BOGRN "==== ALL TESTS PASSED ====" ENDL);
else
printf(BORED "#### %d TEST(S) FAILED ####" ENDL, n_fail);
}
#endif /* MINI_UNIT_H */