-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminiunit.h
More file actions
55 lines (46 loc) · 1.08 KB
/
Copy pathminiunit.h
File metadata and controls
55 lines (46 loc) · 1.08 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
/* Based on MinUnit: http://www.jera.com/techinfo/jtns/jtn002.html */
#ifndef MINUNIT_H
#define MINUNIT_H
#ifdef _WIN32
#include <stdlib.h>
#endif
#include <stdio.h>
#define mu_assert(message, test)\
do { if (!(test)) return message; } while (0)
// Modified for more interesting output
#define mu_run_test(test)\
do {\
const char *message = test();\
printf("-- %s%s\x1b[0m\n", message ? "\x1b[31m" : "\x1b[32m", #test);\
++tests_run;\
if (message) return message;\
} while (0)
// Defines a test function
#define TEST(name) const char * name()
#ifdef __cplusplus
extern "C" {
#endif
// Number of tests that ran
int tests_run;
// Function executing tests
const char *all_tests();
int main() {
#ifdef _WIN32
// Required on (atleast my) Windows to get terminal colors to work.
system("");
#endif
puts("RUNNING TESTS");
const char *result = all_tests();
if (result != 0) {
printf("%s\nABORT\n", result);
}
else {
puts("ALL TESTS PASSED");
}
printf("Tests run: %d\n", tests_run);
return result != 0;
}
#ifdef __cplusplus
}
#endif
#endif /* !MINUNIT_H */