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 <h2o/memory.h>
5
6//
7//
8//
9
10#include <htils/basictypes.h>
11
12#define COLOR_GREEN "\x1b[32m"
13#define COLOR_CYAN "\x1b[36m"
14#define COLOR_RED "\x1b[31m"
15#define COLOR_RESET "\x1b[0m"
16
17//
18//
19//
20
23#define H2OTILS_TEST_ASSERT(cond, msg) \
24 do { \
25 if (!(cond)) { \
26 fprintf(stderr, " %sFAIL%s: %s:%d: %s\n", COLOR_RED, COLOR_RESET, \
27 __FILE__, __LINE__, msg); \
28 return (msg); \
29 } \
30 } while (0)
31
33#define H2OTILS_TEST(name) \
34 static const cstr *h2otils_test_##name(h2o_mem_pool_t *pool)
35
37#define H2OTILS_TEST_RUN(name) \
38 do { \
39 test_count++; \
40 \
41 h2o_mem_pool_t pool; \
42 h2o_mem_init_pool(&pool); \
43 fprintf(stderr, "Running test: %s...\n", #name); \
44 const cstr *result = h2otils_test_##name(&pool); \
45 h2o_mem_clear_pool(&pool); \
46 if (!result) \
47 fprintf(stderr, " %sPASS%s: %s\n", COLOR_GREEN, COLOR_RESET, #name); \
48 else if (result[0] == '@') { \
49 fprintf(stderr, " %sSKIPPED%s: %s\n", COLOR_CYAN, COLOR_RESET, #name); \
50 skips++; \
51 } else \
52 (failures)++; \
53 } while (0)
54
57#define H2OTILS_TEST_RESULT() \
58 do { \
59 if (failures > 0) { \
60 fprintf(stderr, "\n%u Tests %sFAILED%s.\n", failures, COLOR_RED, \
61 COLOR_RESET); \
62 fprintf(stderr, "%sSKIPPED%s %u tests.\n", COLOR_CYAN, COLOR_RESET, \
63 skips); \
64 return 1; \
65 } \
66 \
67 fprintf(stderr, "\nAll %u tests %sPASSED%s.\n", test_count, COLOR_GREEN, \
68 COLOR_RESET); \
69 fprintf(stderr, "%sSKIPPED%s %u tests.\n", COLOR_CYAN, COLOR_RESET, \
70 skips); \
71 return 0; \
72 } while (0)
73
75#define H2OTILS_TEST_PASS null
76
78#define H2OTILS_TEST_SKIP "@"
79
80#endif // !H2OTILS_TEST_H