4 #include <sys/mman.h>
\r
7 static int expected_tests = NO_PLAN;
\r
8 static int failed_tests;
\r
9 static int current_test;
\r
11 void plan (int tests) {
\r
12 expected_tests = tests;
\r
13 if (tests != NO_PLAN)
\r
14 printf("1..%d\n", tests);
\r
17 int ok_at_loc (const char *file, int line, int test, const char *fmt, ...) {
23 vasprintf(&name, fmt, args);
\r
27 printf("%sok %d%s%s\n",
35 diag(" Failed test '%s'\n at %s line %d.", name, file, line);
\r
37 diag(" Failed test at %s line %d.", file, line);
\r
46 static void diag_to_fh_v (FILE *fh, const char *fmt, va_list args) {
\r
51 vasprintf(&mesg, fmt, args);
\r
54 for (i = 0; *line; i++) {
\r
56 if (!c || c == '\n') {
\r
58 fprintf(fh, "# %s\n", line);
\r
70 int diag (const char *fmt, ...) {
73 diag_to_fh_v(stderr, fmt, args);
78 int note (const char *fmt, ...) {
81 diag_to_fh_v(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 /* Create a shared memory int to keep track of whether a piece of code
105 executed dies. to be used in the dies_ok and lives_ok macros */
106 int tap_test_died (int b) {
107 static int *test_died = NULL;
110 test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
111 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
114 int prev = *test_died;