10 /* global variable testnum? */
11 static int test = 0; /* the test number */
12 static int planned = 0;
13 static int intodo = 0;
15 void begin_todo(void) {
23 void plan(int tests) {
26 printf("1..%d\n", tests);
29 static void print_lazy_plan(void) {
30 printf("1..%d\n", test);
34 void plan_lazy(void) {
37 atexit(print_lazy_plan);
40 void skip_all(const char *why, ...) {
46 vfprintf(stdout, why, args);
52 static void vfmtline(int pass, const char *directive, const char *fmt, va_list args) {
53 printf("%sok %d", pass ? "" : "not ", ++test);
54 if (fmt && !directive) {
58 printf(" # %s", directive);
62 vfprintf(stdout, fmt, args);
68 static void fmtline(int pass, const char *info, const char *fmt, ...) {
72 vfmtline(pass, info, fmt, args);
77 void okv(int pass, const char *fmt, va_list args) {
78 vfmtline(pass, intodo ? "TODO" : 0, fmt, args);
81 void ok(int pass, char *fmt, ...) {
89 void ok_block(unsigned long count, int pass, const char *fmt, ...) {
100 okv(pass, fmt, copy);
106 void skip(const char *why, ...) {
110 vfmtline(1, "SKIP", why, args);
114 void skip_block(unsigned long count, const char *why, ...) {
121 vfmtline(1, "SKIP", why, args);
128 void bail(const char *fmt, ...) {
133 vfprintf(stdout, fmt, args);
141 void sysbail(const char *fmt, ...) {
146 vfprintf(stdout, fmt, args);
149 printf(": %s\n", strerror(errno));
154 void sysdiag(const char *fmt, ...) {
156 if (!fmt) { return; }
159 vfprintf(stdout, fmt, args);
161 printf(": %s\n", strerror(errno));
164 void diag(const char *fmt, ...) {
166 if (!fmt) { return; }
169 vfprintf(stdout, fmt, args);
174 void is_hex(unsigned long wanted, unsigned long seen, const char *fmt, ...) {
178 okv(wanted == seen, fmt, args);
181 ok(wanted == seen, NULL);
183 if (wanted != seen) {
184 diag("wanted: %ld", wanted);
185 diag("got : %ld", seen);
190 void is_int(long wanted, long seen, const char *fmt, ...) {
194 okv(wanted == seen, fmt, args);
197 ok(wanted == seen, NULL);
199 if (wanted != seen) {
200 diag("wanted: %ld", wanted);
201 diag("got : %ld", seen);
205 void is_double(double wanted, double seen, double eps, const char *fmt, ...) {
209 pass = fabs(wanted - seen) <= eps;
212 okv(pass, fmt, args);
215 ok(wanted == seen, NULL);
218 diag("wanted: %f", wanted);
219 diag("got : %f", seen);
223 void is_string(const char *wanted, const char *seen, const char *fmt, ...) {
227 pass = !strcmp(wanted,seen);
230 okv(pass, fmt, args);
233 ok(wanted == seen, NULL);
236 diag("wanted: %s", wanted);
237 diag("got : %s", seen);