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.
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)
{
const struct test *a = (const struct test *) aa;
const struct test *b = (const struct test *) bb;
const struct testingprivCase *a = (const struct testingprivCase *) aa;
const struct testingprivCase *b = (const struct testingprivCase *) bb;
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[])
{
struct test *t;
struct test want;
struct testingprivCase *t;
struct testingprivCase want;
if (argc != 2) {
fprintf(stderr, "usage: %s TestName\n", argv[0]);
return 1;
}
qsort(tests, lenTests, sizeof (struct test), testcmp);
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) {
fprintf(stderr, "%s: no such test\n", argv[1]);
return 1;

View File

@ -18,31 +18,9 @@ extern "C" {
#define testingprivImplName(basename) testingprivImpl ## 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) \
void testingprivImplName(Test ## Name)(void); \
static void testingprivScaffoldName(Test ## Name)(void) \
static void testingprivImplName(Test ## Name)(void); \
void testingprivScaffoldName(Test ## Name)(void) \
{ \
uiInitError err; \
memset(&err, 0, sizeof (uiInitError)); \
@ -53,17 +31,15 @@ extern "C" {
} \
testingprivImplName(Test ## Name)(); \
} \
testingprivMkCtor(Test ## Name) \
void testingprivImplName(Test ## Name)(void)
static void testingprivImplName(Test ## Name)(void)
#define TestNoInit(Name) \
void testingprivImplName(Test ## Name)(void); \
static void testingprivScaffoldName(Test ## Name)(void) \
static void testingprivImplName(Test ## Name)(void); \
void testingprivScaffoldName(Test ## Name)(void) \
{ \
testingprivImplName(Test ## Name)(); \
} \
testingprivMkCtor(Test ## Name) \
void testingprivImplName(Test ## Name)(void)
static void testingprivImplName(Test ## Name)(void)
extern void TestFail(void);
extern void TestFailNow(void);
@ -86,7 +62,6 @@ extern void TestSkipNow(void);
(testingprivLogfFullThen(stderr, TestSkipNow, __FILE__, __LINE__, __VA_ARGS__))
// TODO TestSkipfFull (after resolving above TODO)
extern void testingprivRegisterTest(const char *name, void (*f)(void));
#include "../sharedbits/printfwarn_header.h"
sharedbitsPrintfFunc(
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 size_t testingprivNumCases;'''
headerEntryFmt = 'extern void testingprivImplName(Test{})(void);'
headerEntryFmt = 'extern void testingprivScaffoldName(Test{})(void);'
class headerCommand:
filename = None
@ -84,7 +84,7 @@ command.register(headerCommand)
sourceHeader = '''// Generated by testlist.py; do not edit
#include "test.h"
const struct testingprivCase testingprivCases[] = {'''
sourceEntryFmt = ' {{ "Test{0}", testingprivImplName(Test{0}) }},'
sourceEntryFmt = ' {{ "Test{0}", testingprivScaffoldName(Test{0}) }},'
sourceFooter = '''}};
const size_t testingprivNumCases = {};'''