More desirable sorting of tests: by line number per file, specifically. Also per-file, but that can remain unguaranteed if I ever spin this out into its own library.
This commit is contained in:
parent
16c6425200
commit
e5e60284fb
|
@ -2,6 +2,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#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);
|
||||
|
|
|
@ -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 <stdarg.h>
|
||||
|
||||
#define testingprivImplName(basename) testingprivImpl ## basename
|
||||
|
|
Loading…
Reference in New Issue