Stored the full options struct in testingT, so options can be passed to subtests; this also avoids the need to pass them into testingprivTRun().

This commit is contained in:
Pietro Gagliardi 2019-05-20 21:22:02 -04:00
parent 3c9ff9c4bc
commit 6412d8365f
1 changed files with 15 additions and 9 deletions

View File

@ -31,6 +31,8 @@ struct testingT {
char *computedName; char *computedName;
void (*f)(testingT *, void *); void (*f)(testingT *, void *);
void *data; void *data;
// for sorting tests in a set; not used by subtests
const char *file; const char *file;
long line; long line;
@ -44,8 +46,10 @@ struct testingT {
struct defer *defers; struct defer *defers;
int defersRun; int defersRun;
// execution options
testingOptions opts;
// output // output
int verbose;
testingprivOutbuf *outbuf; testingprivOutbuf *outbuf;
}; };
@ -119,16 +123,15 @@ static const testingOptions defaultOptions = {
.Verbose = 0, .Verbose = 0,
}; };
static int testingprivTRun(testingT *t, const testingOptions *options, testingprivOutbuf *parentbuf) static int testingprivTRun(testingT *t, testingprivOutbuf *parentbuf)
{ {
const char *status; const char *status;
timerTime start, end; timerTime start, end;
char timerstr[timerDurationStringLen]; char timerstr[timerDurationStringLen];
int printStatus; int printStatus;
if (options->Verbose) if (t->opts.Verbose)
testingprivOutbufPrintf(parentbuf, "=== RUN %s\n", t->name); testingprivOutbufPrintf(parentbuf, "=== RUN %s\n", t->name);
t->verbose = options->Verbose;
t->outbuf = testingprivNewOutbuf(); t->outbuf = testingprivNewOutbuf();
start = timerMonotonicNow(); start = timerMonotonicNow();
@ -138,7 +141,7 @@ static int testingprivTRun(testingT *t, const testingOptions *options, testingpr
t->returned = 1; t->returned = 1;
runDefers(t); runDefers(t);
printStatus = t->verbose; printStatus = t->opts.Verbose;
status = "PASS"; status = "PASS";
if (t->failed) { if (t->failed) {
status = "FAIL"; status = "FAIL";
@ -157,7 +160,8 @@ static int testingprivTRun(testingT *t, const testingOptions *options, testingpr
return t->failed; return t->failed;
} }
static void testingprivSetRun(testingSet *set, const testingOptions *options, testingprivOutbuf *outbuf, int *anyFailed) // TODO rename all options to opts and all format to fmt
static void testingprivSetRun(testingSet *set, const testingOptions *opts, testingprivOutbuf *outbuf, int *anyFailed)
{ {
size_t i; size_t i;
testingT *t; testingT *t;
@ -165,7 +169,8 @@ static void testingprivSetRun(testingSet *set, const testingOptions *options, te
testingprivArrayQsort(&(set->tests), testcmp); testingprivArrayQsort(&(set->tests), testcmp);
t = (testingT *) (set->tests.buf); t = (testingT *) (set->tests.buf);
for (i = 0; i < set->tests.len; i++) { for (i = 0; i < set->tests.len; i++) {
if (testingprivTRun(t, options, outbuf) != 0) t->opts = *opts;
if (testingprivTRun(t, outbuf) != 0)
*anyFailed = 1; *anyFailed = 1;
t++; t++;
} }
@ -280,11 +285,12 @@ void testingTRun(testingT *t, const char *subname, void (*subfunc)(testingT *t,
} }
subt = testingprivNew(testingT); subt = testingprivNew(testingT);
initTest(subt, subfunc, data, xxxxxx); initTest(subt, subfunc, data, NULL, 0);
subt->computedName = testingSmprintf("%s/%s", t->name, testingprivOutbufString(rewrittenName)); subt->computedName = testingSmprintf("%s/%s", t->name, testingprivOutbufString(rewrittenName));
testingprivOutbufFree(rewrittenName); testingprivOutbufFree(rewrittenName);
if (testingprivTRun(subt, xxxxxx, t->outbuf) != 0) subt->opts = t->opts;
if (testingprivTRun(subt, t->outbuf) != 0)
t->failed = 1; t->failed = 1;
uiprivFree(subt->computedName); uiprivFree(subt->computedName);