X-Git-Url: https://git.distorted.org.uk/~mdw/mLib/blobdiff_plain/c5e0e40378b7e209521d2e9a52f055575a948313..3efcfd2df21aa11bd9d1ba5ea2f5f490fd4d5b84:/test/tvec-output.c diff --git a/test/tvec-output.c b/test/tvec-output.c index fbdb347..c4809bb 100644 --- a/test/tvec-output.c +++ b/test/tvec-output.c @@ -93,14 +93,12 @@ static int register_maxnamelen(const struct tvec_state *tv) /*----- Skeleton ----------------------------------------------------------*/ /* -static void ..._error(struct tvec_output *o, const char *msg, va_list *ap) -static void ..._notice(struct tvec_output *o, const char *msg, va_list *ap) -static void ..._bsession(struct tvec_output *o) +static void ..._bsession(struct tvec_output *o, struct tvec_state *tv) static int ..._esession(struct tvec_output *o) static void ..._bgroup(struct tvec_output *o) -static void ..._egroup(struct tvec_output *o, unsigned outcome) static void ..._skipgroup(struct tvec_output *o, const char *excuse, va_list *ap) +static void ..._egroup(struct tvec_output *o) static void ..._btest(struct tvec_output *o) static void ..._skip(struct tvec_output *o, const char *excuse, va_list *ap) static void ..._fail(struct tvec_output *o, const char *detail, va_list *ap) @@ -112,14 +110,16 @@ static void ..._bbench(struct tvec_output *o, static void ..._ebench(struct tvec_output *o, const char *ident, unsigned unit, const struct tvec_timing *t) +static void ..._error(struct tvec_output *o, const char *msg, va_list *ap) +static void ..._notice(struct tvec_output *o, const char *msg, va_list *ap) static void ..._destroy(struct tvec_output *o) static const struct tvec_outops ..._ops = { - ..._error, ..._notice, ..._bsession, ..._esession, ..._bgroup, ..._egroup, ..._skip, ..._btest, ..._skip, ..._fail, ..._dumpreg, ..._etest, ..._bbench, ..._ebench, + ..._error, ..._notice, ..._destroy }; */ @@ -151,6 +151,7 @@ static const struct tvec_outops ..._ops = { struct human_output { struct tvec_output _o; + struct tvec_state *tv; FILE *fp; dstr scoreboard; unsigned attr; @@ -207,7 +208,7 @@ static void clear_progress(struct human_output *h) size_t i, n; if (h->f&HOF_PROGRESS) { - n = strlen(h->_o.tv->test->name) + 2 + h->scoreboard.len; + n = strlen(h->tv->test->name) + 2 + h->scoreboard.len; for (i = 0; i < n; i++) fputs("\b \b", h->fp); h->f &= ~HOF_PROGRESS; } @@ -225,11 +226,11 @@ static void write_scoreboard_char(struct human_output *h, int ch) static void show_progress(struct human_output *h) { - struct tvec_state *tv = h->_o.tv; + struct tvec_state *tv = h->tv; const char *p, *l; if (tv->test && (h->f&HOF_TTY) && !(h->f&HOF_PROGRESS)) { - fprintf(h->fp, "%s: ", h->_o.tv->test->name); + fprintf(h->fp, "%s: ", tv->test->name); if (!(h->f&HOF_COLOUR)) dstr_write(&h->scoreboard, h->fp); else for (p = h->scoreboard.buf, l = p + h->scoreboard.len; p < l; p++) @@ -260,27 +261,8 @@ static void report_location(struct human_output *h, FILE *fp, #undef FLUSH } -static void human_report(struct tvec_output *o, const char *msg, va_list *ap) -{ - struct human_output *h = (struct human_output *)o; - struct tvec_state *tv = h->_o.tv; - dstr d = DSTR_INIT; - - dstr_vputf(&d, msg, ap); dstr_putc(&d, '\n'); - - clear_progress(h); fflush(h->fp); - fprintf(stderr, "%s: ", QUIS); - report_location(h, stderr, tv->infile, tv->lno); - fwrite(d.buf, 1, d.len, stderr); - - if (h->f&HOF_DUPERR) { - report_location(h, h->fp, tv->infile, tv->lno); - fwrite(d.buf, 1, d.len, h->fp); - } - show_progress(h); -} - -static void human_bsession(struct tvec_output *o) { ; } +static void human_bsession(struct tvec_output *o, struct tvec_state *tv) + { struct human_output *h = (struct human_output *)o; h->tv = tv; } static void report_skipped(struct human_output *h, unsigned n) { @@ -294,7 +276,7 @@ static void report_skipped(struct human_output *h, unsigned n) static int human_esession(struct tvec_output *o) { struct human_output *h = (struct human_output *)o; - struct tvec_state *tv = h->_o.tv; + struct tvec_state *tv = h->tv; unsigned all_win = tv->all[TVOUT_WIN], grps_win = tv->grps[TVOUT_WIN], all_lose = tv->all[TVOUT_LOSE], grps_lose = tv->grps[TVOUT_LOSE], @@ -326,58 +308,51 @@ static int human_esession(struct tvec_output *o) fputs(" found in input; tests may not have run correctly\n", h->fp); } - return (tv->f&TVSF_ERROR ? 2 : tv->all[TVOUT_LOSE] ? 1 : 0); + h->tv = 0; return (tv->f&TVSF_ERROR ? 2 : tv->all[TVOUT_LOSE] ? 1 : 0); } static void human_bgroup(struct tvec_output *o) { struct human_output *h = (struct human_output *)o; - h->maxlen = register_maxnamelen(h->_o.tv); + h->maxlen = register_maxnamelen(h->tv); dstr_reset(&h->scoreboard); show_progress(h); } -static void human_grpsumm(struct human_output *h, unsigned outcome) +static void human_skipgroup(struct tvec_output *o, + const char *excuse, va_list *ap) { - struct tvec_state *tv = h->_o.tv; - unsigned win = tv->curr[TVOUT_WIN], lose = tv->curr[TVOUT_LOSE], - skip = tv->curr[TVOUT_SKIP], run = win + lose; + struct human_output *h = (struct human_output *)o; - if (lose) { - assert(outcome == TVOUT_LOSE); - fprintf(h->fp, " %u/%u ", lose, run); - setattr(h, HA_LOSE); fputs("FAILED", h->fp); setattr(h, 0); - report_skipped(h, skip); + if (!(~h->f&(HOF_TTY | HOF_PROGRESS))) { + h->f &= ~HOF_PROGRESS; + setattr(h, HA_SKIP); fputs("skipped", h->fp); setattr(h, 0); } else { - assert(outcome == TVOUT_WIN); - fputc(' ', h->fp); setattr(h, HA_WIN); fputs("ok", h->fp); setattr(h, 0); - report_skipped(h, skip); + fprintf(h->fp, "%s: ", h->tv->test->name); + setattr(h, HA_SKIP); fputs("skipped", h->fp); setattr(h, 0); } + if (excuse) { fputs(": ", h->fp); vfprintf(h->fp, excuse, *ap); } fputc('\n', h->fp); } -static void human_egroup(struct tvec_output *o, unsigned outcome) +static void human_egroup(struct tvec_output *o) { struct human_output *h = (struct human_output *)o; + struct tvec_state *tv = h->tv; + unsigned win = tv->curr[TVOUT_WIN], lose = tv->curr[TVOUT_LOSE], + skip = tv->curr[TVOUT_SKIP], run = win + lose; if (h->f&HOF_TTY) h->f &= ~HOF_PROGRESS; - else fprintf(h->fp, "%s:", h->_o.tv->test->name); - human_grpsumm(h, outcome); -} - -static void human_skipgroup(struct tvec_output *o, - const char *excuse, va_list *ap) -{ - struct human_output *h = (struct human_output *)o; + else fprintf(h->fp, "%s:", h->tv->test->name); - if (!(~h->f&(HOF_TTY | HOF_PROGRESS))) { - h->f &= ~HOF_PROGRESS; - setattr(h, HA_SKIP); fputs("skipped", h->fp); setattr(h, 0); + if (lose) { + fprintf(h->fp, " %u/%u ", lose, run); + setattr(h, HA_LOSE); fputs("FAILED", h->fp); setattr(h, 0); + report_skipped(h, skip); } else { - fprintf(h->fp, "%s: ", h->_o.tv->test->name); - setattr(h, HA_SKIP); fputs("skipped", h->fp); setattr(h, 0); + fputc(' ', h->fp); setattr(h, HA_WIN); fputs("ok", h->fp); setattr(h, 0); + report_skipped(h, skip); } - if (excuse) { fputs(": ", h->fp); vfprintf(h->fp, excuse, *ap); } fputc('\n', h->fp); } @@ -388,7 +363,7 @@ static void human_skip(struct tvec_output *o, const char *excuse, va_list *ap) { struct human_output *h = (struct human_output *)o; - struct tvec_state *tv = h->_o.tv; + struct tvec_state *tv = h->tv; clear_progress(h); report_location(h, h->fp, tv->infile, tv->test_lno); @@ -402,7 +377,7 @@ static void human_fail(struct tvec_output *o, const char *detail, va_list *ap) { struct human_output *h = (struct human_output *)o; - struct tvec_state *tv = h->_o.tv; + struct tvec_state *tv = h->tv; clear_progress(h); report_location(h, h->fp, tv->infile, tv->test_lno); @@ -452,7 +427,7 @@ static void human_bbench(struct tvec_output *o, const char *ident, unsigned unit) { struct human_output *h = (struct human_output *)o; - struct tvec_state *tv = h->_o.tv; + struct tvec_state *tv = h->tv; clear_progress(h); fprintf(h->fp, "%s: %s: ", tv->test->name, ident); fflush(h->fp); @@ -466,6 +441,26 @@ static void human_ebench(struct tvec_output *o, tvec_benchreport(&file_printops, h->fp, unit, tm); fputc('\n', h->fp); } +static void human_report(struct tvec_output *o, const char *msg, va_list *ap) +{ + struct human_output *h = (struct human_output *)o; + struct tvec_state *tv = h->tv; + dstr d = DSTR_INIT; + + dstr_vputf(&d, msg, ap); dstr_putc(&d, '\n'); + + clear_progress(h); fflush(h->fp); + fprintf(stderr, "%s: ", QUIS); + report_location(h, stderr, tv->infile, tv->lno); + fwrite(d.buf, 1, d.len, stderr); + + if (h->f&HOF_DUPERR) { + report_location(h, h->fp, tv->infile, tv->lno); + fwrite(d.buf, 1, d.len, h->fp); + } + show_progress(h); +} + static void human_destroy(struct tvec_output *o) { struct human_output *h = (struct human_output *)o; @@ -476,11 +471,11 @@ static void human_destroy(struct tvec_output *o) } static const struct tvec_outops human_ops = { - human_report, human_report, human_bsession, human_esession, - human_bgroup, human_egroup, human_skipgroup, + human_bgroup, human_skipgroup, human_egroup, human_btest, human_skip, human_fail, human_dumpreg, human_etest, human_bbench, human_ebench, + human_report, human_report, human_destroy }; @@ -521,6 +516,7 @@ struct tvec_output *tvec_humanoutput(FILE *fp) struct tap_output { struct tvec_output _o; + struct tvec_state *tv; FILE *fp; dstr d; int maxlen; @@ -528,26 +524,6 @@ struct tap_output { #define TOF_FRESHLINE 1u }; -static void tap_report(struct tap_output *t, const char *msg, va_list *ap) -{ - struct tvec_state *tv = t->_o.tv; - - if (tv->infile) fprintf(t->fp, "%s:%u: ", tv->infile, tv->lno); - vfprintf(t->fp, msg, *ap); fputc('\n', t->fp); -} - -static void tap_error(struct tvec_output *o, const char *msg, va_list *ap) -{ - struct tap_output *t = (struct tap_output *)o; - fputs("Bail out! ", t->fp); tap_report(t, msg, ap); -} - -static void tap_notice(struct tvec_output *o, const char *msg, va_list *ap) -{ - struct tap_output *t = (struct tap_output *)o; - fputs("## ", t->fp); tap_report(t, msg, ap); -} - static int tap_writech(void *go, int ch) { struct tap_output *t = go; @@ -601,11 +577,17 @@ static int tap_nwritef(void *go, size_t maxsz, const char *p, ...) static const struct gprintf_ops tap_printops = { tap_writech, tap_writem, tap_nwritef }; -static void tap_bsession(struct tvec_output *o) { ; } +static void tap_bsession(struct tvec_output *o, struct tvec_state *tv) +{ + struct tap_output *t = (struct tap_output *)o; + + t->tv = tv; + fputs("TAP version 13\n", t->fp); +} static unsigned tap_grpix(struct tap_output *t) { - struct tvec_state *tv = t->_o.tv; + struct tvec_state *tv = t->tv; return (tv->grps[TVOUT_WIN] + tv->grps[TVOUT_LOSE] + @@ -615,7 +597,7 @@ static unsigned tap_grpix(struct tap_output *t) static int tap_esession(struct tvec_output *o) { struct tap_output *t = (struct tap_output *)o; - struct tvec_state *tv = t->_o.tv; + struct tvec_state *tv = t->tv; if (tv->f&TVSF_ERROR) { fputs("Bail out! " @@ -625,19 +607,29 @@ static int tap_esession(struct tvec_output *o) } fprintf(t->fp, "1..%u\n", tap_grpix(t)); - return (tv->all[TVOUT_LOSE] ? 1 : 0); + t->tv = 0; return (tv->all[TVOUT_LOSE] ? 1 : 0); } static void tap_bgroup(struct tvec_output *o) { struct tap_output *t = (struct tap_output *)o; - t->maxlen = register_maxnamelen(t->_o.tv); + t->maxlen = register_maxnamelen(t->tv); +} + +static void tap_skipgroup(struct tvec_output *o, + const char *excuse, va_list *ap) +{ + struct tap_output *t = (struct tap_output *)o; + + fprintf(t->fp, "ok %u %s # SKIP", tap_grpix(t), t->tv->test->name); + if (excuse) { fputc(' ', t->fp); vfprintf(t->fp, excuse, *ap); } + fputc('\n', t->fp); } -static void tap_egroup(struct tvec_output *o, unsigned outcome) +static void tap_egroup(struct tvec_output *o) { struct tap_output *t = (struct tap_output *)o; - struct tvec_state *tv = t->_o.tv; + struct tvec_state *tv = t->tv; unsigned grpix = tap_grpix(t), win = tv->curr[TVOUT_WIN], @@ -645,35 +637,22 @@ static void tap_egroup(struct tvec_output *o, unsigned outcome) skip = tv->curr[TVOUT_SKIP]; if (lose) { - assert(outcome == TVOUT_LOSE); - fprintf(t->fp, "not ok %u %s: FAILED %u/%u", + fprintf(t->fp, "not ok %u - %s: FAILED %u/%u", grpix, tv->test->name, lose, win + lose); if (skip) fprintf(t->fp, " (skipped %u)", skip); } else { - assert(outcome == TVOUT_WIN); - fprintf(t->fp, "ok %u %s: passed %u", grpix, tv->test->name, win); + fprintf(t->fp, "ok %u - %s: passed %u", grpix, tv->test->name, win); if (skip) fprintf(t->fp, " (skipped %u)", skip); } fputc('\n', t->fp); } -static void tap_skipgroup(struct tvec_output *o, - const char *excuse, va_list *ap) -{ - struct tap_output *t = (struct tap_output *)o; - - fprintf(t->fp, "ok %u %s # SKIP", tap_grpix(t), t->_o.tv->test->name); - if (excuse) - { fputc(' ', t->fp); vfprintf(t->fp, excuse, *ap); } - fputc('\n', t->fp); -} - static void tap_btest(struct tvec_output *o) { ; } static void tap_skip(struct tvec_output *o, const char *excuse, va_list *ap) { struct tap_output *t = (struct tap_output *)o; - struct tvec_state *tv = t->_o.tv; + struct tvec_state *tv = t->tv; fprintf(t->fp, "## %s:%u: `%s' skipped", tv->infile, tv->test_lno, tv->test->name); @@ -684,7 +663,7 @@ static void tap_skip(struct tvec_output *o, const char *excuse, va_list *ap) static void tap_fail(struct tvec_output *o, const char *detail, va_list *ap) { struct tap_output *t = (struct tap_output *)o; - struct tvec_state *tv = t->_o.tv; + struct tvec_state *tv = t->tv; fprintf(t->fp, "## %s:%u: `%s' FAILED", tv->infile, tv->test_lno, tv->test->name); @@ -720,13 +699,33 @@ static void tap_ebench(struct tvec_output *o, const struct bench_timing *tm) { struct tap_output *t = (struct tap_output *)o; - struct tvec_state *tv = t->_o.tv; + struct tvec_state *tv = t->tv; fprintf(t->fp, "## %s: %s: ", tv->test->name, ident); t->f &= ~TOF_FRESHLINE; tvec_benchreport(&tap_printops, t, unit, tm); fputc('\n', t->fp); } +static void tap_report(struct tap_output *t, const char *msg, va_list *ap) +{ + struct tvec_state *tv = t->tv; + + if (tv->infile) fprintf(t->fp, "%s:%u: ", tv->infile, tv->lno); + vfprintf(t->fp, msg, *ap); fputc('\n', t->fp); +} + +static void tap_error(struct tvec_output *o, const char *msg, va_list *ap) +{ + struct tap_output *t = (struct tap_output *)o; + fputs("Bail out! ", t->fp); tap_report(t, msg, ap); +} + +static void tap_notice(struct tvec_output *o, const char *msg, va_list *ap) +{ + struct tap_output *t = (struct tap_output *)o; + fputs("## ", t->fp); tap_report(t, msg, ap); +} + static void tap_destroy(struct tvec_output *o) { struct tap_output *t = (struct tap_output *)o; @@ -737,11 +736,11 @@ static void tap_destroy(struct tvec_output *o) } static const struct tvec_outops tap_ops = { - tap_error, tap_notice, tap_bsession, tap_esession, - tap_bgroup, tap_egroup, tap_skipgroup, + tap_bgroup, tap_skipgroup, tap_egroup, tap_btest, tap_skip, tap_fail, tap_dumpreg, tap_etest, tap_bbench, tap_ebench, + tap_error, tap_notice, tap_destroy };