From bc0d3120c840ad2ac0a92c4949f1ec472f6358ea Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 5 May 2019 15:59:59 -0400 Subject: [PATCH] Added verbosity to the test suite. Now we can move on. --- test/lib/testing.c | 22 ++++++++++++++++++---- test/lib/testing.h | 8 +++++++- test/main.c | 15 +++++++++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/test/lib/testing.c b/test/lib/testing.c index 72f26b1b..a4ecdcb2 100644 --- a/test/lib/testing.c +++ b/test/lib/testing.c @@ -293,6 +293,10 @@ static void runDefers(testingT *t) (*(d->f))(t, d->data); } +static testingOptions opts = { + .Verbose = 0, +}; + static void testsetRun(struct testset *set, int indent, int *anyFailed) { size_t i; @@ -300,35 +304,45 @@ static void testsetRun(struct testset *set, int indent, int *anyFailed) const char *status; timerTime start, end; char timerstr[timerDurationStringLen]; + int printStatus; t = set->tests; for (i = 0; i < set->len; i++) { - outbufPrintf(NULL, indent, "=== RUN %s", t->name); + if (opts.Verbose) + outbufPrintf(NULL, indent, "=== RUN %s", t->name); t->indent = indent + 1; + t->verbose = opts.Verbose; start = timerMonotonicNow(); if (setjmp(t->returnNowBuf) == 0) (*(t->f))(t); end = timerMonotonicNow(); t->returned = 1; runDefers(t); + printStatus = t->verbose; status = "PASS"; if (t->failed) { status = "FAIL"; + printStatus = 1; // always print status on failure *anyFailed = 1; } else if (t->skipped) // note that failed overrides skipped status = "SKIP"; timerDurationString(timerTimeSub(end, start), timerstr); - outbufPrintf(NULL, indent, "--- %s: %s (%s)", status, t->name, timerstr); - outbufCopy(NULL, &(t->output)); + if (printStatus) { + outbufPrintf(NULL, indent, "--- %s: %s (%s)", status, t->name, timerstr); + outbufCopy(NULL, &(t->output)); + } t++; } } -int testingMain(void) +int testingMain(const struct testingOptions *options) { int anyFailed; + if (options != NULL) + opts = *options; + // TODO see if this should run if all tests are skipped if ((testsBefore.len + tests.len + testsAfter.len) == 0) { fprintf(stderr, "warning: no tests to run\n"); diff --git a/test/lib/testing.h b/test/lib/testing.h index cd835974..151d5f14 100644 --- a/test/lib/testing.h +++ b/test/lib/testing.h @@ -40,7 +40,13 @@ #define testingTestAfter(Name) \ testingprivMk(Test ## Name, testingT, t, testingprivRegisterTestAfter) -extern int testingMain(void); +typedef struct testingOptions testingOptions; + +struct testingOptions { + int Verbose; +}; + +extern int testingMain(const struct testingOptions *options); typedef struct testingT testingT; #define testingTLogf(t, ...) \ diff --git a/test/main.c b/test/main.c index 9369ce08..d0245652 100644 --- a/test/main.c +++ b/test/main.c @@ -1,4 +1,6 @@ // 10 april 2019 +#include +#include #include "test.h" void timeoutMain(void *data) @@ -6,7 +8,16 @@ void timeoutMain(void *data) uiMain(); } -int main(void) +int main(int argc, char *argv[]) { - return testingMain(); + testingOptions opts; + + memset(&opts, 0, sizeof (testingOptions)); + if (argc == 2 && strcmp(argv[1], "-v") == 0) + opts.Verbose = 1; + else if (argc != 1) { + fprintf(stderr, "usage: %s [-v]\n", argv[0]); + return 1; + } + return testingMain(&opts); }