2 * Copyright © 2015, 2023 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.
21 static unsigned plan, total, passed, xpassed, failed, xfailed;
23 void tap_plan(unsigned expected_tests)
26 tap_bail_out("tap_plan: tests already planned!");
28 tap_bail_out("tap_plan: no tests to run!");
30 plan = expected_tests;
31 printf("1..%u\n", plan);
38 } else if (total != plan) {
39 tap_bail_out("tap_done: planned %u tests, ran %u", plan, total);
42 assert(total == passed + xpassed + failed + xfailed);
43 exit(failed || xpassed);
46 void tap_vbail_out(const char *fmt, va_list ap)
48 printf("Bail out!%*s", fmt != NULL, "");
55 void tap_bail_out(const char *fmt, ...)
60 tap_vbail_out(fmt, ap);
64 void tap_vskip_all(const char *fmt, va_list ap)
67 tap_bail_out("tap_skip_all: already started tests");
69 printf("1..0 # skip%*s", fmt != NULL, "");
76 void tap_skip_all(const char *fmt, ...)
81 tap_vskip_all(fmt, ap);
85 void tap_vdiag(const char *fmt, va_list ap)
87 printf("#%*s", fmt != NULL, "");
93 void tap_diag(const char *fmt, ...)
102 int tap_vresult(int ok, const char *fmt, va_list ap)
106 printf("ok %u%*s", ++total, fmt != NULL, "");
112 tap_bail_out("cannot handle so many tests");
120 int tap_result(int ok, const char *fmt, ...)
126 ret = tap_vresult(ok, fmt, ap);