Added TestDefer(), which we need to bring back the events tests.
This commit is contained in:
parent
3f3de363b5
commit
cdc570082c
36
test/main.c
36
test/main.c
|
@ -11,6 +11,22 @@ static int testcmp(const void *aa, const void *bb)
|
||||||
return strcmp(a->name, b->name);
|
return strcmp(a->name, b->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct defer {
|
||||||
|
void (*f)(void *data);
|
||||||
|
void *data;
|
||||||
|
struct defer *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct defer *defers = NULL;
|
||||||
|
|
||||||
|
static void runDefers(void)
|
||||||
|
{
|
||||||
|
struct defer *d;
|
||||||
|
|
||||||
|
for (d = defers; d != NULL; d = d->next)
|
||||||
|
(*(d->f))(d->data);
|
||||||
|
}
|
||||||
|
|
||||||
static int testingprivRet = 0;
|
static int testingprivRet = 0;
|
||||||
|
|
||||||
void TestFail(void)
|
void TestFail(void)
|
||||||
|
@ -29,6 +45,22 @@ void TestSkipNow(void)
|
||||||
exit(77);
|
exit(77);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestDefer(void (*f)(void *data), void *data)
|
||||||
|
{
|
||||||
|
struct defer *d;
|
||||||
|
|
||||||
|
d = (struct defer *) malloc(sizeof (struct defer));
|
||||||
|
if (d != NULL) {
|
||||||
|
fprintf(stderr, "** internal error: memory exhausted in TestDefer()\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
memset(d, 0, sizeof (struct defer));
|
||||||
|
d->f = f;
|
||||||
|
d->data = data;
|
||||||
|
d->next = defers;
|
||||||
|
defers = d;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *basename(const char *file)
|
static const char *basename(const char *file)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
|
@ -71,6 +103,10 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
testingprivRet = 0;
|
testingprivRet = 0;
|
||||||
|
if (atexit(runDefers) != 0) {
|
||||||
|
fprintf(stderr, "atexit(runDefers) failed (errno %d); can't test\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
(*(t->f))();
|
(*(t->f))();
|
||||||
return testingprivRet;
|
return testingprivRet;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// 27 february 2018
|
// 27 february 2018
|
||||||
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -62,6 +63,8 @@ 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 TestDefer(void (*f)(void *data), void *data);
|
||||||
|
|
||||||
#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, ...),
|
||||||
|
|
Loading…
Reference in New Issue