-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path318_test-tapish.h
32 lines (27 loc) · 1.53 KB
/
318_test-tapish.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
/*
* Macros for test emission. Compatible with the Test Anything Protocol if
* TEST_PREFIX is defined to be the empty string.
*/
/* Isn't this gross */
#define TEST_ID_(x) x
#define TEST_CONCAT_(a,b) a b
#ifndef TEST_NAME
#error Define TEST_NAME before including test-tapish
#endif
#ifndef TEST_PREFIX_PREFIX
#define TEST_PREFIX_PREFIX "TAPME: "
#endif
/* Prefix for test harness aid, since QEMU and other tools output, too */
#define TEST_PREFIX TEST_CONCAT_(TEST_CONCAT_(TEST_PREFIX_PREFIX, TEST_NAME), " ")
/* Primitives */
#define TEST_STRT(n) do { printf(2, TEST_PREFIX "1..%d\n" , n ); } while(0);
#define TEST_FINI(msg, ...) do { printf(2, TEST_PREFIX "ok - " msg "\n", ##__VA_ARGS__); } while(0);
#define TEST_FAIL(msg, ...) do { printf(2, TEST_PREFIX "not ok - " msg "\n", ##__VA_ARGS__); } while(0);
#define TEST_EXIT(msg, ...) do { printf(2, TEST_PREFIX "Bail out! " msg "\n", ##__VA_ARGS__); exit(); } while(0);
#define TEST_DIAG(msg, ...) do { printf(2, TEST_PREFIX "# " msg "\n", ##__VA_ARGS__); } while(0);
/* Conditionals */
#define TEST_FAIL_IF(cond, msg, ...) if(cond) { TEST_FAIL(msg, ##__VA_ARGS__); }
#define TEST_EXIT_IF(cond, msg, ...) if(cond) { TEST_EXIT(msg, ##__VA_ARGS__); }
#define TEST_DIAG_IF(cond, msg, ...) if(cond) { TEST_DIAG(msg, ##__VA_ARGS__); }
#define TEST_FAIL_IF_THEN(cond, then, msg, ...) if(cond) { TEST_FAIL(msg, ##__VA_ARGS__); then; }
#define TEST_DIAG_IF_THEN(cond, then, msg, ...) if(cond) { TEST_DIAG(msg, ##__VA_ARGS__); then; }