2 libtap - Write tests in C
3 Copyright 2012 Jake Gelbman <gelbman@gmail.com>
4 This file is licensed under the LGPL
10 #define AC_RED "\x1b[31m"
11 #define AC_GREEN "\x1b[32m"
12 #define AC_YELLOW "\x1b[33m"
13 #define AC_BLUE "\x1b[34m"
14 #define AC_MAGENTA "\x1b[35m"
15 #define AC_CYAN "\x1b[36m"
16 #define AC_RESET "\x1b[0m"
18 #define AC_CLR(color, text) AC_##color text AC_RESET
19 #define AC_OK(text) AC_CLR(GREEN, text)
20 #define AC_BAD(text) AC_CLR(RED, text)
28 #define va_copy __va_copy
30 #define va_copy(d, s) ((d) = (s))
38 int vok_at_loc (const char *file, int line, int test, const char *fmt,
40 int ok_at_loc (const char *file, int line, int test, const char *fmt,
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 int cmp_mem_at_loc (const char *file, int line, const void *got,
49 const void *expected, size_t n, const char *fmt, ...);
50 int bail_out (int ignore, const char *fmt, ...);
51 void tap_plan (int tests, const char *fmt, ...);
52 int diag (const char *fmt, ...);
53 int note (const char *fmt, ...);
54 int exit_status (void);
55 void tap_skip (int n, const char *fmt, ...);
56 void tap_todo (int ignore, const char *fmt, ...);
57 void tap_end_todo (void);
61 #define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
62 #define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
63 #define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
64 #define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
65 #define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
66 #define plan(...) tap_plan(__VA_ARGS__, NULL)
67 #define done_testing() return exit_status()
68 #define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
69 #define pass(...) ok(1, "" __VA_ARGS__)
70 #define fail(...) ok(0, "" __VA_ARGS__)
72 #define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
73 #define end_skip } while (0)
75 #define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
76 #define end_todo tap_end_todo()
78 #define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
79 #define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
82 #define like(...) tap_skip(1, "like is not implemented on Windows")
83 #define unlike tap_skip(1, "unlike is not implemented on Windows")
84 #define dies_ok_common(...) \
85 tap_skip(1, "Death detection is not supported on Windows")
87 #define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
88 #define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
89 int like_at_loc (int for_match, const char *file, int line,
90 const char *got, const char *expected,
91 const char *fmt, ...);
93 #include <sys/types.h>
95 int tap_test_died (int status);
96 #define dies_ok_common(for_death, code, ...) \
104 perror("fork error"); \
113 if (waitpid(cpid, NULL, 0) < 0) { \
114 perror("waitpid error"); \
117 it_died = tap_test_died(0); \
120 ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \