]> begriffs open source - libtap/blob - tap.h
Fix README
[libtap] / tap.h
1 #ifndef __TAP_H__\r
2 #define __TAP_H__\r
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 \r
7 #define NO_PLAN   -1\r
8 #define ok(...)   ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
9 #define pass(...) ok(1, ## __VA_ARGS__)
10 #define fail(...) ok(0, ## __VA_ARGS__)
11 \r
12 void plan         (int tests);\r
13 int  ok_at_loc    (const char *file, int line, int test, const char *fmt, ...);\r
14 int  diag         (const char *fmt, ...);\r
15 int  note         (const char *fmt, ...);\r
16 int  exit_status  (void);\r
17 void skippy       (int test, const char *fmt, ...);
18 void ctodo        (int ignore, const char *fmt, ...);
19 void cendtodo     ();
20
21 #define skip(test, ...)  do {if (test) {skippy(__VA_ARGS__, NULL); break;}
22 #define endskip          } while (0)
23
24 #define todo(...)        ctodo(0, ## __VA_ARGS__, NULL)
25 #define endtodo          cendtodo()
26 \r
27 #ifdef _WIN32
28 #   define dies_ok_common(code, for_death, ...) \\r
29         ok(1, "# SKIP unable to test if code dies on windows");\r
30 #else\r
31 #   include <unistd.h>
32 #   include <sys/types.h>
33 #   include <sys/wait.h>
34     int tap_test_died (int status);
35 #   define dies_ok_common(code, for_death, ...)                 \\r
36         {                                                       \\r
37             tap_test_died(1);                                   \\r
38             int cpid = fork();                                  \\r
39             switch (cpid) {                                     \\r
40             case -1:                                            \\r
41                 perror("fork error");                           \\r
42                 exit(EXIT_FAILURE);                             \\r
43             case 0: /* child  */                                \\r
44                 close(1); close(2);                             \\r
45                 code                                            \\r
46                 tap_test_died(0);                               \\r
47                 exit(EXIT_SUCCESS);                             \\r
48             }                                                   \\r
49             if (waitpid(cpid, NULL, 0) < 0) {                   \\r
50                 perror("waitpid error");                        \\r
51                 exit(EXIT_FAILURE);                             \\r
52             }                                                   \\r
53             int it_died = tap_test_died(0);                     \\r
54             if (!it_died) {code}                                \\r
55             ok(for_death ? it_died : !it_died, ## __VA_ARGS__); \\r
56         }\r
57 #endif\r
58 \r
59 #define dies_ok(code, ...)  dies_ok_common(code, 1, ## __VA_ARGS__)\r
60 #define lives_ok(code, ...) dies_ok_common(code, 0, ## __VA_ARGS__)\r
61 \r
62 #endif\r