-
Notifications
You must be signed in to change notification settings - Fork 2
/
Test.h
75 lines (60 loc) · 1.61 KB
/
Test.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
71
72
73
74
75
/* Test.h */
/* Lightweight TAP (Test Anything Protocol) emitter in C macros. */
/* SYNOPSIS
#include "../Test.h"
int
main(int argc, char * argv[])
{
plan(1);
ok(1==1, "1 is equal to 1");
is_ii(2 + 2, 4, "2 plus 2 equals 4");
return 0;
}
*/
/* DEFINITIONS
plan(i);
diag(s);
is_ii(i1, i2, "integers match");
is_ss(s1, s2, "strings match");
ok(b, "any boolean expression");
TODO: is_pp(p1, p2, "pointers match");
TODO: done_testing();
*/
#include <stdio.h> /* printf */
#include <string.h> /* strcmp */
int _test_number=0; /* yes, namespace pollution. patches welcome ;-) */
#define plan(count) printf("1..%d\n", count)
#define \
ok(flag,desc) \
printf("%sok %d - %s\n", \
flag?"":"not ",++_test_number,desc); \
fflush(stdout)
#define \
is_ii(got,expected,desc) \
printf("%sok %d - %s\n", \
got==expected?"":"not ",++_test_number,desc); \
if(got!=expected) \
printf("# got : %d\n# expected : %d\n", got, expected); \
fflush(stdout)
#define \
is_ll(got,expected,desc) \
printf("%sok %d - %s\n", \
got==expected?"":"not ",++_test_number,desc); \
if(got!=expected) \
printf("# got : %ld\n# expected : %ld\n", got, expected); \
fflush(stdout)
#define \
is_ss(got,expected,desc) \
printf("%sok %d - %s\n", \
strcmp(got,expected)?"not ":"",++_test_number,desc); \
fflush(stdout)
#define \
isnt_pp(got,expected,desc) \
printf("%sok %d - %s\n", \
(got!=expected)?"":"not ", ++_test_number, desc); \
fflush(stdout)
#define \
diag(message) \
printf("# %s\n", message); \
fflush(stdout)
/* end of Test.h */