diff --git a/test/initmain.c b/test/initmain.c index a9984ef8..5b09d030 100644 --- a/test/initmain.c +++ b/test/initmain.c @@ -2,11 +2,11 @@ #include "../ui.h" #include "testing.h" -testingTest(Init) +testingTestBefore(Init) { } -testingTest(Uninit) +testingTestAfter(Uninit) { } diff --git a/test/testing.c b/test/testing.c index c3e58909..3ff2688d 100644 --- a/test/testing.c +++ b/test/testing.c @@ -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; diff --git a/test/testing.h b/test/testing.h index 2393a66d..7bcdb8c9 100644 --- a/test/testing.h +++ b/test/testing.h @@ -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)))