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 have, unsigned long want, const char *fmt, ...) {
181 okv(pass, fmt, args);
187 diag("wanted: %ld", want);
188 diag("got : %ld", have);
192 void is_int(long have, long want, const char *fmt, ...) {
199 okv(pass, fmt, args);
205 diag("wanted: %ld", want);
206 diag("got : %ld", have);
210 void is_double(double have, double want, double eps, const char *fmt, ...) {
214 pass = fabs(want - have) <= eps;
217 okv(pass, fmt, args);
223 diag("wanted: %f", want);
224 diag("got : %f", have);
228 void is_compare(void *have, void *want,
229 int (*cmp)(void *,void *),
235 pass = !cmp(have, want);
238 okv(pass, fmt, args);
243 /* no way to print them with out more functions
245 diag("wanted: %s", want);
246 diag("got : %s", have);
251 int is_string(const char *have, const char *want, const char *fmt, ...) {
255 pass = !strcmp(have,want);
258 okv(pass, fmt, args);
264 diag("wanted: %s", want);
265 diag("got : %s", have);