-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit_test.h
More file actions
70 lines (57 loc) · 2.37 KB
/
unit_test.h
File metadata and controls
70 lines (57 loc) · 2.37 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef UNIT_TEST_H
#define UNIT_TEST_H
#include <cstddef>
#include <cstdio>
#define XCONCAT(lhs, rhs) lhs##rhs
#define CONCAT(lhs, rhs) XCONCAT(lhs, rhs)
#define XSTRINGIFY(s) #s
#define STRINGIFY(s) XSTRINGIFY(s)
/* FOREGROUND */
#define RST "\x1B[0m"
#define KBOLD "\x1B[1m"
#define KUNDL "\x1B[4m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#define FRED(x) KRED x RST
#define FGRN(x) KGRN x RST
#define FYEL(x) KYEL x RST
#define FBLU(x) KBLU x RST
#define FMAG(x) KMAG x RST
#define FCYN(x) KCYN x RST
#define FWHT(x) KWHT x RST
#define BOLD(x) KBOLD x RST
#define UNDL(x) KUNDL x RST
#define REPORT_ASSERTION_FAILED(cond) \
do { \
fprintf( \
stderr, \
BOLD(FRED("[TEST] `%s` failed")) "\nAssertion failed in file `%s`, " \
"line `%d`. Condition: `%s`\n", \
__func__, __FILE__, __LINE__, STRINGIFY(cond)); \
} while (0)
#define TEST_PASSED() \
do { \
fprintf(stderr, BOLD(FGRN("[TEST] `%s` passed successfully")) "\n", \
__func__); \
return; \
} while (0)
#define ASSERT(cond) \
do { \
if (!(cond)) { \
REPORT_ASSERTION_FAILED(cond); \
return; \
} \
} while (0)
#define UNIT_TEST(name) void test_##name()
using TestFn = void (*)();
inline void run_tests(TestFn tests[], size_t num_tests) {
for (size_t i = 0U; i != num_tests; ++i) {
tests[i]();
}
}
#endif