2 libtap - Write tests in C
3 Copyright 2012 Jake Gelbman <gelbman@gmail.com>
4 This file is licensed under the LGPL
10 #ifdef TAP_COLOR_OUTPUT
11 #define AC_RED "\x1b[31m"
12 #define AC_GREEN "\x1b[32m"
13 #define AC_YELLOW "\x1b[33m"
14 #define AC_BLUE "\x1b[34m"
15 #define AC_MAGENTA "\x1b[35m"
16 #define AC_CYAN "\x1b[36m"
17 #define AC_RESET "\x1b[0m"
19 #define AC_CLR(color, text) AC_##color text AC_RESET
20 #define AC_OK(text) AC_CLR(GREEN, text)
21 #define AC_BAD(text) AC_CLR(RED, text)
23 #define AC_OK(text) text
24 #define AC_BAD(text) text
33 #define va_copy __va_copy
35 #define va_copy(d, s) ((d) = (s))
43 int vok_at_loc (const char *file, int line, int test, const char *fmt,
45 int ok_at_loc (const char *file, int line, int test, const char *fmt,
47 int is_at_loc (const char *file, int line, const char *got,
48 const char *expected, const char *fmt, ...);
49 int isnt_at_loc (const char *file, int line, const char *got,
50 const char *expected, const char *fmt, ...);
51 int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
52 int b, const char *fmt, ...);
53 int cmp_mem_at_loc (const char *file, int line, const void *got,
54 const void *expected, size_t n, const char *fmt, ...);
55 int bail_out (int ignore, const char *fmt, ...);
56 void tap_plan (int tests, const char *fmt, ...);
57 int diag (const char *fmt, ...);
58 int note (const char *fmt, ...);
59 int exit_status (void);
60 void tap_skip (int n, const char *fmt, ...);
61 void tap_todo (int ignore, const char *fmt, ...);
62 void tap_end_todo (void);
66 #define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
67 #define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
68 #define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
69 #define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
70 #define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL);
71 #define plan(...) tap_plan(__VA_ARGS__, NULL)
72 #define done_testing() return exit_status()
73 #define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
74 #define pass(...) ok(1, "" __VA_ARGS__)
75 #define fail(...) ok(0, "" __VA_ARGS__)
77 #define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
78 #define end_skip } while (0)
80 #define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
81 #define end_todo tap_end_todo()
83 #define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
84 #define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
87 #define like(...) tap_skip(1, "like is not implemented on Windows")
88 #define unlike tap_skip(1, "unlike is not implemented on Windows")
89 #define dies_ok_common(...) \
90 tap_skip(1, "Death detection is not supported on Windows")
92 #define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
93 #define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
94 int like_at_loc (int for_match, const char *file, int line,
95 const char *got, const char *expected,
96 const char *fmt, ...);
98 #include <sys/types.h>
100 int tap_test_died (int status);
101 #define dies_ok_common(for_death, code, ...) \
109 perror("fork error"); \
118 if (waitpid(cpid, NULL, 0) < 0) { \
119 perror("waitpid error"); \
122 it_died = tap_test_died(0); \
125 ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \