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