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);
}
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++) {
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);
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");

View File

@ -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, ...) \

View File

@ -1,4 +1,6 @@
// 10 april 2019
#include <stdio.h>
#include <string.h>
#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);
}