2 libtap - Write tests in C
3 Copyright 2012 Jake Gelbman <gelbman@gmail.com>
4 This file is licensed under the LGPL
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 exit_status (void);
42 void tap_skip (int n, const char *fmt, ...);
43 void tap_todo (int ignore, const char *fmt, ...);
44 void tap_end_todo (void);
48 #define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
49 #define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
50 #define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
51 #define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
52 #define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
53 #define plan(...) tap_plan(__VA_ARGS__, NULL)
54 #define done_testing() return exit_status()
55 #define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
56 #define pass(...) ok(1, "" __VA_ARGS__)
57 #define fail(...) ok(0, "" __VA_ARGS__)
59 #define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
60 #define end_skip } while (0)
62 #define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
63 #define end_todo tap_end_todo()
65 #define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
66 #define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
69 #define like(...) tap_skip(1, "like is not implemented on Windows")
70 #define unlike tap_skip(1, "unlike is not implemented on Windows")
71 #define dies_ok_common(...) \
72 tap_skip(1, "Death detection is not supported on Windows")
74 #define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
75 #define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
76 int like_at_loc (int for_match, const char *file, int line,
77 const char *got, const char *expected,
78 const char *fmt, ...);
80 #include <sys/types.h>
82 int tap_test_died (int status);
83 #define dies_ok_common(for_death, code, ...) \
91 perror("fork error"); \
100 if (waitpid(cpid, NULL, 0) < 0) { \
101 perror("waitpid error"); \
104 it_died = tap_test_died(0); \
107 ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \