htils
1
A small set of utilities for C programming.
Loading...
Searching...
No Matches
test.h
Go to the documentation of this file.
1
#ifndef H2OTILS_TEST_H
2
#define H2OTILS_TEST_H
3
4
#include <stdlib.h>
5
6
//
7
//
8
//
9
10
#include <h2o/memory.h>
11
12
//
13
//
14
//
15
16
#include <
htils/basictypes.h
>
17
18
#define COLOR_GREEN "\x1b[32m"
19
#define COLOR_CYAN "\x1b[36m"
20
#define COLOR_RED "\x1b[31m"
21
#define COLOR_RESET "\x1b[0m"
22
23
//
24
//
25
//
26
29
#define H2OTILS_TEST_ASSERT(cond, msg) \
30
do { \
31
if (!(cond)) { \
32
fprintf(stderr, " %sFAIL%s: %s:%d: %s\n", COLOR_RED, COLOR_RESET, \
33
__FILE__, __LINE__, msg); \
34
return (msg); \
35
} \
36
} while (0)
37
39
#define H2OTILS_TEST(name) \
40
static const cstr *h2otils_test_##name(h2o_mem_pool_t *pool)
41
43
#define H2OTILS_TEST_RUN(name) \
44
do { \
45
test_count++; \
46
\
47
h2o_mem_pool_t pool; \
48
h2o_mem_init_pool(&pool); \
49
fprintf(stderr, "Running test: %s...\n", #name); \
50
const cstr *result = h2otils_test_##name(&pool); \
51
\
52
if (!result) \
53
fprintf(stderr, " %sPASS%s: %s\n", COLOR_GREEN, COLOR_RESET, #name); \
54
else if (result[0] == '@') { \
55
fprintf(stderr, " %sSKIPPED%s: %s\n", COLOR_CYAN, COLOR_RESET, #name); \
56
skips++; \
57
} else \
58
(failures)++; \
59
} while (0)
60
63
#define H2OTILS_TEST_RESULT() \
64
do { \
65
if (failures > 0) { \
66
fprintf(stderr, "\n%u Tests %sFAILED%s.\n", failures, COLOR_RED, \
67
COLOR_RESET); \
68
fprintf(stderr, "%sSKIPPED%s %u tests.\n", COLOR_CYAN, COLOR_RESET, \
69
skips); \
70
return 1; \
71
} \
72
\
73
fprintf(stderr, "\nAll %u tests %sPASSED%s.\n", test_count, COLOR_GREEN, \
74
COLOR_RESET); \
75
fprintf(stderr, "%sSKIPPED%s %u tests.\n", COLOR_CYAN, COLOR_RESET, \
76
skips); \
77
return 0; \
78
} while (0)
79
81
#define H2OTILS_TEST_PASS null
82
84
#define H2OTILS_TEST_SKIP "@"
85
86
#endif
// !H2OTILS_TEST_H
basictypes.h
include
h2otils
test.h
Generated by
1.9.8