From bd666b8ec97248d29302feb6f027d5810d47aedd Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 20 May 2019 20:56:47 -0400 Subject: [PATCH] Started writing subtests. I'll need to make a few more structural changes to the test scaffolding for this. --- test/lib/testing.c | 50 +++++++++++++++++++++++++++++++++++++++++++++- test/lib/testing.h | 1 + 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/test/lib/testing.c b/test/lib/testing.c index 27d9af4f..7abc6867 100644 --- a/test/lib/testing.c +++ b/test/lib/testing.c @@ -3,6 +3,7 @@ #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif +#include #include #include #include @@ -55,7 +56,6 @@ static void initTest(testingT *t, const char *name, void (*f)(testingT *), const { memset(t, 0, sizeof (testingT)); t->name = name; - t->computedName = testingprivStrdup(name); t->f = f; t->file = file; t->line = line; @@ -83,6 +83,7 @@ void testingprivSetRegisterTest(testingSet **pset, const char *name, void (*f)(t } t = (testingT *) testingprivArrayAppend(&(set->tests), 1); initTest(t, name, f, file, line); + t->computedName = testingprivStrdup(name); } static int testcmp(const void *a, const void *b) @@ -238,3 +239,50 @@ void testingTDefer(testingT *t, void (*f)(testingT *t, void *data), void *data) d->next = t->defers; t->defers = d; } + +void testingTRun(testingT *t, const char *subname, void (*subfunc)(testingT *t, void *data), void *data) +{ + testingT *subt; + testingprivOutbuf *rewrittenName; + + rewrittenName = testingprivNewOutbuf(); + while (*subname != "") { + const char *replaced; + + replaced = NULL; + switch (*subname) { + case ' ': + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + replaced = "_"; + break; + case '\a': + replaced = "\\a"; + break; + case '\b': + replaced = "\\b"; + break; + } + if (replaced != NULL) + testingprivOutbufPrintf(rewrittenName, "%s", replaced); + else if (isprint(*subname)) + testingprivOutbufPrintf(rewrittenName, "%c", *subname); + else + testingprivOutbufPrintf(rewrittenName, "\\x%x", (unsigned int) (*subname)); + subname++; + } + + subt = testingprivNew(testingT); + initTest(subt, xxxxx); + subt->computedName = testingSmprintf("%s/%s", t->name, testingprivOutbufString(rewrittenName)); + testingprivOutbufFree(rewrittenName); + + if (testingprivTRun(subt, xxxxxx, t->outbuf) != 0) + t->failed = 1; + + uiprivFree(subt->computedName); + uiprivFree(subt); +} diff --git a/test/lib/testing.h b/test/lib/testing.h index 55198588..3bdf9dce 100644 --- a/test/lib/testing.h +++ b/test/lib/testing.h @@ -68,6 +68,7 @@ extern void testingTFail(testingT *t); extern void testingTFailNow(testingT *t); extern void testingTSkipNow(testingT *t); extern void testingTDefer(testingT *t, void (*f)(testingT *t, void *data), void *data); +extern void testingTRun(testingT *t, const char *subname, void (*subfunc)(testingT *t, void *data), void *data); extern void testingprivSetRegisterTest(testingSet **pset, const char *, void (*)(testingT *), const char *, long); // see https://stackoverflow.com/questions/32399191/va-args-expansion-using-msvc