6 static int expected_tests = NO_PLAN;
\r
7 static int failed_tests;
\r
8 static int current_test;
\r
10 void plan (int tests) {
\r
11 expected_tests = tests;
\r
12 if (tests != NO_PLAN)
\r
13 printf("1..%d\n", tests);
\r
16 static char *vstrdupf (const char *fmt, va_list args) {
18 int size = vsnprintf(NULL, 0, fmt, args) + 1;
20 vsprintf(str, fmt, args);
24 int ok_at_loc (const char *file, int line, int test, const char *fmt, ...) {
29 name = vstrdupf(fmt, args);
\r
32 printf("%sok %d%s%s\n",
39 diag(" Failed test '%s'\n at %s line %d.", name, file, line);
\r
41 diag(" Failed test at %s line %d.", file, line);
\r
49 static void vdiag_to_fh (FILE *fh, const char *fmt, va_list args) {
\r
54 mesg = vstrdupf(fmt, args);
\r
56 for (i = 0; *line; i++) {
\r
58 if (!c || c == '\n') {
\r
60 fprintf(fh, "# %s\n", line);
\r
70 int diag (const char *fmt, ...) {
73 vdiag_to_fh(stderr, fmt, args);
78 int note (const char *fmt, ...) {
81 vdiag_to_fh(stdout, fmt, args);
86 int exit_status () {
\r
87 int retval = EXIT_SUCCESS;
\r
88 if (expected_tests == NO_PLAN) {
\r
89 printf("1..%d\n", current_test);
\r
91 else if (current_test != expected_tests) {
\r
92 diag("Looks like you planned %d test%s but ran %d.",
\r
93 expected_tests, expected_tests > 1 ? "s" : "", current_test);
\r
94 retval = EXIT_FAILURE;
\r
97 diag("Looks like you failed %d test%s of %d run.",
\r
98 failed_tests, failed_tests > 1 ? "s" : "", current_test);
\r
99 retval = EXIT_FAILURE;
\r
104 void skippy (int n, const char *fmt, ...) {
108 why = vstrdupf(fmt, args);
111 printf("ok %d ", ++current_test);
112 note("skip %s\n", why);
118 # include <sys/mman.h>
119 /* Create a shared memory int to keep track of whether a piece of code
120 executed dies. to be used in the dies_ok and lives_ok macros */
121 int tap_test_died (int status) {
122 static int *test_died = NULL;
126 test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
127 MAP_SHARED | MAP_ANONYMOUS, -1, 0);