2 * Copyright © 2015 Nick Bowler
4 * Simple TAP output library for C programs.
6 * License WTFPL2: Do What The Fuck You Want To Public License, version 2.
7 * This is free software: you are free to do what the fuck you want to.
8 * There is NO WARRANTY, to the extent permitted by law.
17 static unsigned plan, total, passed, xpassed, failed, xfailed;
19 void tap_plan(unsigned expected_tests)
22 tap_bail_out("tap_plan: tests already planned!");
24 tap_bail_out("tap_plan: no tests to run!");
26 plan = expected_tests;
27 printf("1..%u\n", plan);
34 } else if (total != plan) {
35 tap_bail_out("tap_done: planned %u tests, ran %u", plan, total);
38 assert(total == passed + xpassed + failed + xfailed);
39 exit(failed || xpassed);
42 void tap_vbail_out(const char *fmt, va_list ap)
44 printf("Bail out!%*s", fmt != NULL, "");
51 void tap_bail_out(const char *fmt, ...)
56 tap_vbail_out(fmt, ap);
60 void tap_vskip_all(const char *fmt, va_list ap)
63 tap_bail_out("tap_skip_all: already started tests");
65 printf("1..0 # skip%*s", fmt != NULL, "");
72 void tap_skip_all(const char *fmt, ...)
77 tap_vskip_all(fmt, ap);
81 void tap_vdiag(const char *fmt, va_list ap)
83 printf("#%*s", fmt != NULL, "");
89 void tap_diag(const char *fmt, ...)
98 int tap_vresult(int ok, const char *fmt, va_list ap)
102 printf("ok %u%*s", ++total, fmt != NULL, "");
108 tap_bail_out("cannot handle so many tests");
116 int tap_result(int ok, const char *fmt, ...)
122 ret = tap_vresult(ok, fmt, ap);