And integrated the new test stuff. All right!

This commit is contained in:
Pietro Gagliardi 2020-02-16 18:42:02 -05:00
parent 18c7eae71e
commit 3f3de363b5
3 changed files with 13 additions and 66 deletions

View File

@ -3,37 +3,10 @@
// Do not put any test cases in this file; they will not be run. // Do not put any test cases in this file; they will not be run.
struct test {
const char *name;
void (*f)(void);
};
static struct test *tests = NULL;
static size_t lenTests = 0;
static size_t capTests = 0;
void testingprivRegisterTest(const char *name, void (*f)(void))
{
if (lenTests == capTests) {
struct test *newtests;
capTests += 32;
newtests = (struct test *) realloc(tests, capTests * sizeof (struct test));
if (newtests == NULL) {
fprintf(stderr, "memory exhausted registering test %s\n", name);
exit(1);
}
tests = newtests;
}
tests[lenTests].name = name;
tests[lenTests].f = f;
lenTests++;
}
static int testcmp(const void *aa, const void *bb) static int testcmp(const void *aa, const void *bb)
{ {
const struct test *a = (const struct test *) aa; const struct testingprivCase *a = (const struct testingprivCase *) aa;
const struct test *b = (const struct test *) bb; const struct testingprivCase *b = (const struct testingprivCase *) bb;
return strcmp(a->name, b->name); return strcmp(a->name, b->name);
} }
@ -84,16 +57,15 @@ void testingprivLogfFullThen(FILE *f, void (*then)(void), const char *filename,
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct test *t; struct testingprivCase *t;
struct test want; struct testingprivCase want;
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "usage: %s TestName\n", argv[0]); fprintf(stderr, "usage: %s TestName\n", argv[0]);
return 1; return 1;
} }
qsort(tests, lenTests, sizeof (struct test), testcmp);
want.name = argv[1]; want.name = argv[1];
t = (struct test *) bsearch(&want, tests, lenTests, sizeof (struct test), testcmp); t = (struct testingprivCase *) bsearch(&want, testingprivCases, testingprivNumCases, sizeof (struct testingprivCase), testcmp);
if (t == NULL) { if (t == NULL) {
fprintf(stderr, "%s: no such test\n", argv[1]); fprintf(stderr, "%s: no such test\n", argv[1]);
return 1; return 1;

View File

@ -18,31 +18,9 @@ extern "C" {
#define testingprivImplName(basename) testingprivImpl ## basename #define testingprivImplName(basename) testingprivImpl ## basename
#define testingprivScaffoldName(basename) testingprivScaffold ## basename #define testingprivScaffoldName(basename) testingprivScaffold ## basename
// references:
// - https://gitlab.gnome.org/GNOME/glib/blob/master/glib/gconstructor.h
// - https://gitlab.gnome.org/GNOME/glib/blob/master/gio/glib-compile-resources.c
// - https://msdn.microsoft.com/en-us/library/bb918180.aspx
#define testingprivCtorName(basename) testingprivCtor ## basename
#define testingprivCtorPtrName(basename) testingprivCtorPtr ## basename
#if defined(__GNUC__)
#define testingprivMkCtor(basename) \
__attribute__((constructor)) static void testingprivCtorName(basename)(void) { testingprivRegisterTest(#basename, testingprivScaffoldName(basename)); }
#elif defined(_MSC_VER)
#define testingprivMkCtor(basename) \
static int testingprivCtorName(basename)(void) { testingprivRegisterTest(#basename, testingprivScaffoldName(basename)); return 0; } \
__pragma(section(".CRT$XCU",read)) \
__declspec(allocate(".CRT$XCU")) static int (*testingprivCtorPtrName(basename))(void) = testingprivCtorName(basename);
#elif defined(__SUNPRO_C)
#define testingprivMkCtor(basename) \
static void testingprivCtorName(basename)(void) { testingprivRegisterTest(#basename, testingprivScaffoldName(basename)); } \
_Pragma(init(testingprivCtorName(basename)))
#else
#error unknown compiler for making constructors in C; cannot continue
#endif
#define Test(Name) \ #define Test(Name) \
void testingprivImplName(Test ## Name)(void); \ static void testingprivImplName(Test ## Name)(void); \
static void testingprivScaffoldName(Test ## Name)(void) \ void testingprivScaffoldName(Test ## Name)(void) \
{ \ { \
uiInitError err; \ uiInitError err; \
memset(&err, 0, sizeof (uiInitError)); \ memset(&err, 0, sizeof (uiInitError)); \
@ -53,17 +31,15 @@ extern "C" {
} \ } \
testingprivImplName(Test ## Name)(); \ testingprivImplName(Test ## Name)(); \
} \ } \
testingprivMkCtor(Test ## Name) \ static void testingprivImplName(Test ## Name)(void)
void testingprivImplName(Test ## Name)(void)
#define TestNoInit(Name) \ #define TestNoInit(Name) \
void testingprivImplName(Test ## Name)(void); \ static void testingprivImplName(Test ## Name)(void); \
static void testingprivScaffoldName(Test ## Name)(void) \ void testingprivScaffoldName(Test ## Name)(void) \
{ \ { \
testingprivImplName(Test ## Name)(); \ testingprivImplName(Test ## Name)(); \
} \ } \
testingprivMkCtor(Test ## Name) \ static void testingprivImplName(Test ## Name)(void)
void testingprivImplName(Test ## Name)(void)
extern void TestFail(void); extern void TestFail(void);
extern void TestFailNow(void); extern void TestFailNow(void);
@ -86,7 +62,6 @@ extern void TestSkipNow(void);
(testingprivLogfFullThen(stderr, TestSkipNow, __FILE__, __LINE__, __VA_ARGS__)) (testingprivLogfFullThen(stderr, TestSkipNow, __FILE__, __LINE__, __VA_ARGS__))
// TODO TestSkipfFull (after resolving above TODO) // TODO TestSkipfFull (after resolving above TODO)
extern void testingprivRegisterTest(const char *name, void (*f)(void));
#include "../sharedbits/printfwarn_header.h" #include "../sharedbits/printfwarn_header.h"
sharedbitsPrintfFunc( sharedbitsPrintfFunc(
extern void testingprivLogfFullThen(FILE *f, void (*then)(void), const char *filename, long line, const char *fmt, ...), extern void testingprivLogfFullThen(FILE *f, void (*then)(void), const char *filename, long line, const char *fmt, ...),

View File

@ -54,7 +54,7 @@ struct testingprivCase {
}; };
extern const struct testingprivCase testingprivCases[]; extern const struct testingprivCase testingprivCases[];
extern const size_t testingprivNumCases;''' extern const size_t testingprivNumCases;'''
headerEntryFmt = 'extern void testingprivImplName(Test{})(void);' headerEntryFmt = 'extern void testingprivScaffoldName(Test{})(void);'
class headerCommand: class headerCommand:
filename = None filename = None
@ -84,7 +84,7 @@ command.register(headerCommand)
sourceHeader = '''// Generated by testlist.py; do not edit sourceHeader = '''// Generated by testlist.py; do not edit
#include "test.h" #include "test.h"
const struct testingprivCase testingprivCases[] = {''' const struct testingprivCase testingprivCases[] = {'''
sourceEntryFmt = ' {{ "Test{0}", testingprivImplName(Test{0}) }},' sourceEntryFmt = ' {{ "Test{0}", testingprivScaffoldName(Test{0}) }},'
sourceFooter = '''}}; sourceFooter = '''}};
const size_t testingprivNumCases = {};''' const size_t testingprivNumCases = {};'''