]> begriffs open source - libtap/blob - tap.h
Only use one ifdef __cplusplus in tap.h and remove gnu .t executable extension.
[libtap] / tap.h
1 #ifndef __TAP_H__
2 #define __TAP_H__
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #ifndef va_copy
9 #define va_copy(d,s) ((d) = (s))
10 #endif
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stdarg.h>
15
16 #define NO_PLAN          -1
17 #define ok(...)          ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
18
19 #ifdef _WIN32
20 #define pass(...)        ok_at_loc(__FILE__, __LINE__, 1, __VA_ARGS__, NULL)
21 #define fail(...)        ok_at_loc(__FILE__, __LINE__, 0, __VA_ARGS__, NULL)
22 #else
23 #define pass(...)        ok(1, ## __VA_ARGS__)
24 #define fail(...)        ok(0, ## __VA_ARGS__)
25 #endif
26
27 #define is(...)          is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
28 #define isnt(...)        isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
29 #define cmp_ok(...)      cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
30
31 int     vok_at_loc      (const char *file, int line, int test, const char *fmt,
32                          va_list args);
33 void    plan            (int tests);
34 int     ok_at_loc       (const char *file, int line, int test, const char *fmt,
35                          ...);
36 int     diag            (const char *fmt, ...);
37 int     note            (const char *fmt, ...);
38 int     exit_status     (void);
39 void    skippy          (int n, const char *fmt, ...);
40 void    ctodo           (int ignore, const char *fmt, ...);
41 void    cendtodo        (void);
42 int     is_at_loc       (const char *file, int line, const char *got,
43                          const char *expected, const char *fmt, ...);
44 int     isnt_at_loc     (const char *file, int line, const char *got,
45                          const char *expected, const char *fmt, ...);
46 int     cmp_ok_at_loc   (const char *file, int line, int a, const char *op,
47                          int b, const char *fmt, ...);
48
49 #ifdef _WIN32
50 #define like(...)   skippy(1, "like is not implemented on MSWin32")
51 #define unlike(...) like()
52 #else
53 #define like(...)   like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
54 #define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
55 int     like_at_loc     (int for_match, const char *file, int line,
56                          const char *got, const char *expected,
57                          const char *fmt, ...);
58 #endif
59
60 #define skip(test, ...)  do {if (test) {skippy(__VA_ARGS__, NULL); break;}
61 #define endskip          } while (0)
62
63 #define todo(...)        ctodo(0, ## __VA_ARGS__, NULL)
64 #define endtodo          cendtodo()
65
66 #define dies_ok(code, ...)  dies_ok_common(code, 1, ## __VA_ARGS__)
67 #define lives_ok(code, ...) dies_ok_common(code, 0, ## __VA_ARGS__)
68
69 #ifdef _WIN32
70 #define dies_ok_common(...) \
71     skippy(1, "Death detection is not supported on MSWin32")
72 #else
73 #include <unistd.h>
74 #include <sys/types.h>
75 #include <sys/wait.h>
76 int tap_test_died (int status);
77 #define dies_ok_common(code, for_death, ...)                \
78     do {                                                    \
79         tap_test_died(1);                                   \
80         int cpid = fork();                                  \
81         switch (cpid) {                                     \
82         case -1:                                            \
83             perror("fork error");                           \
84             exit(EXIT_FAILURE);                             \
85         case 0: /* child  */                                \
86             close(1); close(2);                             \
87             code                                            \
88             tap_test_died(0);                               \
89             exit(EXIT_SUCCESS);                             \
90         }                                                   \
91         if (waitpid(cpid, NULL, 0) < 0) {                   \
92             perror("waitpid error");                        \
93             exit(EXIT_FAILURE);                             \
94         }                                                   \
95         int it_died = tap_test_died(0);                     \
96         if (!it_died) {code}                                \
97         ok(for_death ? it_died : !it_died, ## __VA_ARGS__); \
98     } while (0)
99 #endif
100
101 #ifdef __cplusplus
102 }
103 #endif
104
105 #endif
106