2 libtap - Write tests in C
3 Copyright 2012 Jake Gelbman <gelbman@gmail.com>
4 This file is licensed under the GPLv2 or any later version
16 #define va_copy __va_copy
18 #define va_copy(d, s) ((d) = (s))
26 int vok_at_loc (const char *file, int line, int test, const char *fmt,
28 int ok_at_loc (const char *file, int line, int test, const char *fmt,
30 int is_at_loc (const char *file, int line, const char *got,
31 const char *expected, const char *fmt, ...);
32 int isnt_at_loc (const char *file, int line, const char *got,
33 const char *expected, const char *fmt, ...);
34 int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
35 int b, const char *fmt, ...);
36 int cmp_mem_at_loc (const char *file, int line, const void *got,
37 const void *expected, size_t n, const char *fmt, ...);
38 int bail_out (int ignore, const char *fmt, ...);
39 void tap_plan (int tests, const char *fmt, ...);
40 int diag (const char *fmt, ...);
41 int note (const char *fmt, ...);
42 int exit_status (void);
43 void tap_skip (int n, const char *fmt, ...);
44 void tap_todo (int ignore, const char *fmt, ...);
45 void tap_end_todo (void);
49 #define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
50 #define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
51 #define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
52 #define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
53 #define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
54 #define plan(...) tap_plan(__VA_ARGS__, NULL)
55 #define done_testing() return exit_status()
56 #define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
57 #define pass(...) ok(1, "" __VA_ARGS__)
58 #define fail(...) ok(0, "" __VA_ARGS__)
60 #define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
61 #define end_skip } while (0)
63 #define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
64 #define end_todo tap_end_todo()
66 #define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
67 #define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
70 #define like(...) tap_skip(1, "like is not implemented on Windows")
71 #define unlike tap_skip(1, "unlike is not implemented on Windows")
72 #define dies_ok_common(...) \
73 tap_skip(1, "Death detection is not supported on Windows")
75 #define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
76 #define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
77 int like_at_loc (int for_match, const char *file, int line,
78 const char *got, const char *expected,
79 const char *fmt, ...);
81 #include <sys/types.h>
83 int tap_test_died (int status);
84 #define dies_ok_common(for_death, code, ...) \
92 perror("fork error"); \
101 if (waitpid(cpid, NULL, 0) < 0) { \
102 perror("waitpid error"); \
105 it_died = tap_test_died(0); \
108 ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \