Added rudimentary test ordering, for the Init and Uninit tests.

This commit is contained in:
Pietro Gagliardi 2019-04-10 20:17:40 -04:00
parent 1b046e763b
commit 59b449b920
3 changed files with 34 additions and 3 deletions

View File

@ -2,11 +2,11 @@
#include "../ui.h"
#include "testing.h"
testingTest(Init)
testingTestBefore(Init)
{
}
testingTest(Uninit)
testingTestAfter(Uninit)
{
}

View File

@ -26,6 +26,10 @@ struct testingT {
static testingT *tests = NULL;
static testingT *testsTail = NULL;
static testingT *testsBefore = NULL;
static testingT *testsBeforeTail = NULL;
static testingT *testsAfter = NULL;
static testingT *testsAfterTail = NULL;
static testingT *newTest(const char *name, void (*f)(testingT *), testingT *prev)
{
@ -55,6 +59,26 @@ void testingprivRegisterTest(const char *name, void (*f)(testingT *))
tests = t;
}
void testingprivRegisterTestBefore(const char *name, void (*f)(testingT *))
{
testingT *t;
t = newTest(name, f, testsBeforeTail);
testsBeforeTail = t;
if (testsBefore == NULL)
testsBefore = t;
}
void testingprivRegisterTestAfter(const char *name, void (*f)(testingT *))
{
testingT *t;
t = newTest(name, f, testsAfterTail);
testsAfterTail = t;
if (testsAfter == NULL)
testsAfter = t;
}
static void runDefers(testingT *t)
{
struct defer *d;
@ -99,7 +123,9 @@ int testingMain(void)
}
anyFailed = 0;
runTestSet(testsBefore, &anyFailed);
runTestSet(tests, &anyFailed);
runTestSet(testsAfter, &anyFailed);
if (anyFailed) {
printf("FAIL\n");
return 1;

View File

@ -38,6 +38,10 @@
#define testingTest(Name) \
testingprivMk(Test ## Name, testingT, t, testingprivRegisterTest)
#define testingTestBefore(Name) \
testingprivMk(Test ## Name, testingT, t, testingprivRegisterTestBefore)
#define testingTestAfter(Name) \
testingprivMk(Test ## Name, testingT, t, testingprivRegisterTestAfter)
extern int testingMain(void);
@ -64,7 +68,8 @@ extern void testingTSkipNow(testingT *t);
extern void testingTDefer(testingT *t, void (*f)(testingT *t, void *data), void *data);
extern void testingprivRegisterTest(const char *, void (*)(testingT *));
extern void testingprivRegisterManualTest(const char *, void (*)(testingT *));
extern void testingprivRegisterTestBefore(const char *, void (*)(testingT *));
extern void testingprivRegisterTestAfter(const char *, void (*)(testingT *));
// see https://stackoverflow.com/questions/32399191/va-args-expansion-using-msvc
#define testingprivExpand(x) x
#define testingprivTLogfThen(then, t, ...) ((testingprivTLogfFull(t, __FILE__, __LINE__, __VA_ARGS__)), (then(t)))