Added verbosity to the test suite. Now we can move on.

This commit is contained in:
Pietro Gagliardi 2019-05-05 15:59:59 -04:00
parent 3ebc58a5bf
commit bc0d3120c8
3 changed files with 38 additions and 7 deletions

View File

@ -293,6 +293,10 @@ static void runDefers(testingT *t)
(*(d->f))(t, d->data); (*(d->f))(t, d->data);
} }
static testingOptions opts = {
.Verbose = 0,
};
static void testsetRun(struct testset *set, int indent, int *anyFailed) static void testsetRun(struct testset *set, int indent, int *anyFailed)
{ {
size_t i; size_t i;
@ -300,35 +304,45 @@ static void testsetRun(struct testset *set, int indent, int *anyFailed)
const char *status; const char *status;
timerTime start, end; timerTime start, end;
char timerstr[timerDurationStringLen]; char timerstr[timerDurationStringLen];
int printStatus;
t = set->tests; t = set->tests;
for (i = 0; i < set->len; i++) { 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->indent = indent + 1;
t->verbose = opts.Verbose;
start = timerMonotonicNow(); start = timerMonotonicNow();
if (setjmp(t->returnNowBuf) == 0) if (setjmp(t->returnNowBuf) == 0)
(*(t->f))(t); (*(t->f))(t);
end = timerMonotonicNow(); end = timerMonotonicNow();
t->returned = 1; t->returned = 1;
runDefers(t); runDefers(t);
printStatus = t->verbose;
status = "PASS"; status = "PASS";
if (t->failed) { if (t->failed) {
status = "FAIL"; status = "FAIL";
printStatus = 1; // always print status on failure
*anyFailed = 1; *anyFailed = 1;
} else if (t->skipped) } else if (t->skipped)
// note that failed overrides skipped // note that failed overrides skipped
status = "SKIP"; status = "SKIP";
timerDurationString(timerTimeSub(end, start), timerstr); timerDurationString(timerTimeSub(end, start), timerstr);
outbufPrintf(NULL, indent, "--- %s: %s (%s)", status, t->name, timerstr); if (printStatus) {
outbufCopy(NULL, &(t->output)); outbufPrintf(NULL, indent, "--- %s: %s (%s)", status, t->name, timerstr);
outbufCopy(NULL, &(t->output));
}
t++; t++;
} }
} }
int testingMain(void) int testingMain(const struct testingOptions *options)
{ {
int anyFailed; int anyFailed;
if (options != NULL)
opts = *options;
// TODO see if this should run if all tests are skipped // TODO see if this should run if all tests are skipped
if ((testsBefore.len + tests.len + testsAfter.len) == 0) { if ((testsBefore.len + tests.len + testsAfter.len) == 0) {
fprintf(stderr, "warning: no tests to run\n"); fprintf(stderr, "warning: no tests to run\n");

View File

@ -40,7 +40,13 @@
#define testingTestAfter(Name) \ #define testingTestAfter(Name) \
testingprivMk(Test ## Name, testingT, t, testingprivRegisterTestAfter) 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; typedef struct testingT testingT;
#define testingTLogf(t, ...) \ #define testingTLogf(t, ...) \

View File

@ -1,4 +1,6 @@
// 10 april 2019 // 10 april 2019
#include <stdio.h>
#include <string.h>
#include "test.h" #include "test.h"
void timeoutMain(void *data) void timeoutMain(void *data)
@ -6,7 +8,16 @@ void timeoutMain(void *data)
uiMain(); 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);
} }