diff --git a/test/testing.c b/test/testing.c index c91ec9e7..74efa335 100644 --- a/test/testing.c +++ b/test/testing.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "testing.h" #define testingprivNew(T) ((T *) malloc(sizeof (T))) @@ -79,6 +80,27 @@ void testingprivRegisterTestAfter(const char *name, void (*f)(testingT *), const testsetAdd(&testsAfter, name, f, file, line); } +static int testcmp(const void *a, const void *b) +{ + const testingT *ta = (const testingT *) a; + const testingT *tb = (const testingT *) b; + int ret; + + ret = strcmp(ta->file, tb->file); + if (ret != 0) + return ret; + if (ta->line < tb->line) + return -1; + if (ta->line > tb->line) + return 1; + return 0; +} + +static void testsetSort(struct testset *set) +{ + qsort(set->tests, set->len, sizeof (testingT), testcmp); +} + static void runDefers(testingT *t) { struct defer *d; @@ -126,6 +148,10 @@ int testingMain(void) return 0; } + testsetSort(&testsBefore); + testsetSort(&tests); + testsetSort(&testsAfter); + anyFailed = 0; testsetRun(&testsBefore, &anyFailed); testsetRun(&tests, &anyFailed); diff --git a/test/testing.h b/test/testing.h index 2f969be1..87ae3bf8 100644 --- a/test/testing.h +++ b/test/testing.h @@ -1,9 +1,5 @@ // 27 february 2018 -// TODO -// - https://blogs.msdn.microsoft.com/oldnewthing/20181107-00/?p=100155 https://blogs.msdn.microsoft.com/oldnewthing/20181108-00/?p=100165 https://blogs.msdn.microsoft.com/oldnewthing/20181109-00/?p=100175 -// - also in the above: note the unspecified order of data in the sub-segments... - #include #define testingprivImplName(basename) testingprivImpl ## basename