X-Git-Url: https://pd.if.org/git/?p=ctap;a=blobdiff_plain;f=ctap.c;h=02fadf17232d5861cee04286225ea54cf23ca1c1;hp=6238747fd33eeb28acd2822e1e031f2cf4b0331b;hb=HEAD;hpb=31dfcc882434a7f85258d98d5a9d80cb4c83ab65 diff --git a/ctap.c b/ctap.c index 6238747..02fadf1 100644 --- a/ctap.c +++ b/ctap.c @@ -10,6 +10,15 @@ /* global variable testnum? */ static int test = 0; /* the test number */ static int planned = 0; +static int intodo = 0; + +void begin_todo(void) { + intodo = 1; +} + +void end_todo(void) { + intodo = 0; +} void plan(int tests) { test = 0; @@ -32,7 +41,7 @@ void skip_all(const char *why, ...) { printf("1..0"); if (why) { va_list args; - printf(" # skip "); + printf(" # SKIP "); va_start(args, why); vfprintf(stdout, why, args); va_end(args); @@ -40,79 +49,80 @@ void skip_all(const char *why, ...) { printf("\n"); } -void okv(int pass, const char *fmt, va_list args) { +static void vfmtline(int pass, const char *directive, const char *fmt, va_list args) { printf("%sok %d", pass ? "" : "not ", ++test); + if (fmt && !directive) { + printf(" -"); + } + if (directive) { + printf(" # %s", directive); + } if (fmt) { - printf(" # "); + printf(" "); vfprintf(stdout, fmt, args); } printf("\n"); } +#if 0 +static void fmtline(int pass, const char *info, const char *fmt, ...) { + va_list args; + + va_start(args,fmt); + vfmtline(pass, info, fmt, args); + va_end(args); +} +#endif + +void okv(int pass, const char *fmt, va_list args) { + vfmtline(pass, intodo ? "TODO" : 0, fmt, args); +} + void ok(int pass, char *fmt, ...) { va_list args; - printf("%sok %d", pass ? "" : "not ", ++test); - if (fmt) { - printf(" # "); - va_start(args, fmt); - vfprintf(stdout, fmt, args); - va_end(args); - } - printf("\n"); + va_start(args, fmt); + okv(pass, fmt, args); + va_end(args); } void ok_block(unsigned long count, int pass, const char *fmt, ...) { + va_list args; + va_list copy; + if (count == 0) { return; } - if (fmt) { - va_list args; - va_list copy; - va_start(args, fmt); - while (count--) { - va_copy(copy, args); - okv(pass, fmt, copy); - va_end(copy); - } - va_end(args); - } else { - while (count--) { - ok(pass, NULL); - } + + va_start(args, fmt); + while (count--) { + va_copy(copy, args); + okv(pass, fmt, copy); + va_end(copy); } + va_end(args); } void skip(const char *why, ...) { va_list args; - printf("ok %d # skip", ++test); - if (why) { - printf(" "); - va_start(args, why); - vfprintf(stdout, why, args); - va_end(args); - } - printf("\n"); + va_start(args, why); + vfmtline(1, "SKIP", why, args); + va_end(args); } void skip_block(unsigned long count, const char *why, ...) { - if (why) { - va_list args; - va_list copy; - va_start(args, why); - while (count--) { - va_copy(copy, args); - printf("ok %d # skip", ++test); - printf(" "); - vfprintf(stdout, why, copy); - va_end(copy); - printf("\n"); - } - va_end(args); - } else { - printf("ok %d # skip\n", ++test); + va_list args; + va_list copy; + va_start(args, why); + + while (count--) { + va_copy(copy, args); + vfmtline(1, "SKIP", why, args); + va_end(copy); } + + va_end(args); } void bail(const char *fmt, ...) { @@ -161,69 +171,97 @@ void diag(const char *fmt, ...) { printf("\n"); } -void is_hex(unsigned long wanted, unsigned long seen, const char *fmt, ...) { +void is_hex(unsigned long have, unsigned long want, const char *fmt, ...) { va_list args; + int pass; + + pass = have == want; if (fmt) { va_start(args, fmt); - okv(wanted == seen, fmt, args); + okv(pass, fmt, args); va_end(args); } else { - ok(wanted == seen, NULL); + ok(pass, NULL); } - if (wanted != seen) { - diag("wanted: %ld", wanted); - diag("got : %ld", seen); + if (!pass) { + diag("wanted: %ld", want); + diag("got : %ld", have); } } +void is_int(long have, long want, const char *fmt, ...) { + va_list args; + int pass; + + pass = have == want; + if (fmt) { + va_start(args, fmt); + okv(pass, fmt, args); + va_end(args); + } else { + ok(pass, NULL); + } + if (!pass) { + diag("wanted: %ld", want); + diag("got : %ld", have); + } +} -void is_int(long wanted, long seen, const char *fmt, ...) { +void is_double(double have, double want, double eps, const char *fmt, ...) { + int pass; va_list args; + + pass = fabs(want - have) <= eps; if (fmt) { va_start(args, fmt); - okv(wanted == seen, fmt, args); + okv(pass, fmt, args); va_end(args); } else { - ok(wanted == seen, NULL); + ok(pass, NULL); } - if (wanted != seen) { - diag("wanted: %ld", wanted); - diag("got : %ld", seen); + if (!pass) { + diag("wanted: %f", want); + diag("got : %f", have); } } -void is_double(double wanted, double seen, double eps, const char *fmt, ...) { +void is_compare(void *have, void *want, + int (*cmp)(void *,void *), + const char *fmt, ... + ) { int pass; va_list args; - pass = fabs(wanted - seen) <= eps; + pass = !cmp(have, want); if (fmt) { va_start(args, fmt); okv(pass, fmt, args); va_end(args); } else { - ok(wanted == seen, NULL); + ok(pass, NULL); } + /* no way to print them with out more functions if (!pass) { - diag("wanted: %f", wanted); - diag("got : %f", seen); + diag("wanted: %s", want); + diag("got : %s", have); } + */ } -void is_string(const char *wanted, const char *seen, const char *fmt, ...) { +void is_string(const char *have, const char *want, const char *fmt, ...) { int pass; va_list args; - pass = !strcmp(wanted,seen); + pass = !strcmp(have,want); if (fmt) { va_start(args, fmt); okv(pass, fmt, args); va_end(args); } else { - ok(wanted == seen, NULL); + ok(pass, NULL); } if (!pass) { - diag("wanted: %s", wanted); - diag("got : %s", seen); + diag("wanted: %s", want); + diag("got : %s", have); } }