-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctest.h
70 lines (57 loc) · 1.57 KB
/
ctest.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef CTEST_H
#define CTEST_H
#ifdef CTEST_ENABLE
#include <stdio.h>
#include <stdlib.h>
int ctest_pass_count = 0, ctest_fail_count = 0;
int ctest_verbose = 0, ctest_color = 1;
int ctest_status = 0;
const char *ctest_fptr = NULL;
#define CTEST_VERBOSE(v) \
do { \
ctest_verbose = v; \
} while (0)
#define CTEST_COLOR(v) \
do { \
ctest_color = v; \
} while (0)
#define CTEST_EXIT() \
do { \
exit(ctest_status); \
} while (0)
#define CTEST_ASSERT(c, m) \
do { \
if (ctest_fptr == NULL) \
ctest_fptr = __func__; \
char *nl = ctest_fptr != __func__? "\n": ""; \
ctest_fptr = __func__; \
if (!(c)) { \
printf("%s%sFAIL%s: %s: " __FILE__ ":%d: %s: %s\n", \
nl, \
ctest_color? "\x1b[0;1;31m": "", \
ctest_color? "\x1b[0m": "", \
__func__, __LINE__, \
#c, m); \
ctest_fail_count++; \
ctest_status = 1; \
} else { \
if (ctest_verbose) \
printf("%s%s OK%s: %s: " __FILE__ ":%d: %s: %s\n", \
nl, \
ctest_color? "\x1b[0;32m": "", \
ctest_color? "\x1b[0m": "", \
__func__, __LINE__, \
#c, m); \
ctest_pass_count++; \
} \
} while (0)
#define CTEST_RESULTS() \
do { \
int t = ctest_pass_count + ctest_fail_count; \
printf("%sResults: %d/%d passing (%.1f%%).\n", \
ctest_fail_count > 0 || (t > 0 && ctest_verbose)? "\n": "", \
ctest_pass_count, t, \
100.0 * ctest_pass_count / t); \
} while (0)
#endif
#endif