]> begriffs open source - libtap/blob - tap.h
first commit
[libtap] / tap.h
1 #ifndef __TAP_H__\r
2 #define __TAP_H__\r
3
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 \r
8 #define NO_PLAN   -1\r
9 #define ok(...)   ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
10 #define pass(...) ok(1, ## __VA_ARGS__)
11 #define fail(...) ok(0, ## __VA_ARGS__)
12
13 #define dies_ok_common(code, for_death, ...)                \
14     {                                                       \
15         tap_test_died(1);                                   \
16         int cpid = fork();                                  \
17         switch (cpid) {                                     \
18         case -1:                                            \
19             perror("fork error");                           \
20             exit(EXIT_FAILURE);                             \
21         case 0: /* child  */                                \
22             close(1); close(2);                             \
23             code                                            \
24             tap_test_died(0);                               \
25             exit(EXIT_SUCCESS);                             \
26         }                                                   \
27         if (waitpid(cpid, NULL, 0) < 0) {                   \
28             perror("waitpid error");                        \
29             exit(EXIT_FAILURE);                             \
30         }                                                   \
31         int it_died = tap_test_died(0);                     \
32         if (!it_died) {code}                                \
33         ok(for_death ? it_died : !it_died, ## __VA_ARGS__); \
34     }
35
36 #define dies_ok(code, ...)  dies_ok_common(code, 1, ## __VA_ARGS__)
37 #define lives_ok(code, ...) dies_ok_common(code, 0, ## __VA_ARGS__)
38
39 void plan          (int tests);\r
40 int  ok_at_loc     (const char *file, int line, int test, const char *fmt, ...);\r
41 int  diag          (const char *fmt, ...);\r
42 int  note          (const char *fmt, ...);\r
43 int  exit_status   (void);
44 int  tap_test_died (int b);\r
45 \r
46 #endif\r