Added testingTFail() and simplified the implementation of the logging macros.
This commit is contained in:
parent
b5570040b0
commit
70db51d23b
|
@ -70,12 +70,23 @@ extern "C" {
|
||||||
extern int testingMain(void);
|
extern int testingMain(void);
|
||||||
|
|
||||||
typedef struct testingT testingT;
|
typedef struct testingT testingT;
|
||||||
#define testingTLogf(t, ...) (testingprivTLogfFull(t, __FILE__, __LINE__, __VA_ARGS__))
|
#define testingTLogf(t, ...) \
|
||||||
#define testingTLogvf(t, format, ap) (testingprivTLogvfFull(t, __FILE__, __LINE__, format, ap))
|
testingprivExpand(testingprivTLogfThen((void), t, __VA_ARGS__))
|
||||||
#define testingTErrorf(t, ...) (testingprivTErrorfFull(t, __FILE__, __LINE__, __VA_ARGS__))
|
#define testingTLogvf(t, format, ap) \
|
||||||
#define testingTErrorvf(t, format, ap) (testingprivTErrorvfFull(t, __FILE__, __LINE__, format, ap))
|
testingprivTLogvfThen((void), t, format, ap)
|
||||||
#define testingTFatalf(t, ...) ((testingprivTErrorfFull(t, __FILE__, __LINE__, __VA_ARGS__)), (testingTFailNow(t)))
|
#define testingTErrorf(t, ...) \
|
||||||
#define testingTFatalvf(t, format, ap) ((testingprivTErrorvfFull(t, __FILE__, __LINE__, format, ap)), (testingTFailNow(t)))
|
testingprivExpand(testingprivTLogfThen(testingTFail, t, __VA_ARGS__))
|
||||||
|
#define testingTErrorvf(t, format, ap) \
|
||||||
|
testingprivTLogvfThen(testingTFail, t, format, ap)
|
||||||
|
#define testingTFatalf(t, ...) \
|
||||||
|
testingprivExpand(testingprivTLogfThen(testingTFailNow, t, __VA_ARGS__))
|
||||||
|
#define testingTFatalvf(t, format, ap) \
|
||||||
|
testingprivTLogvfThen(testingTFailNow, t, format, ap)
|
||||||
|
#define testingTSkipf(t, ...) \
|
||||||
|
testingprivExpand(testingprivTLogfThen(testingTSkipNow, t, __VA_ARGS__))
|
||||||
|
#define testingTSkipvf(t, format, ap) \
|
||||||
|
testingprivTLogvfThen(testingTSkipNow, t, format, ap)
|
||||||
|
extern void testingTFail(testingT *t);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define testingTFailNow(t) (throw testingprivFailNowException())
|
#define testingTFailNow(t) (throw testingprivFailNowException())
|
||||||
#define testingTSkipNow(t) (throw testingprivSkipNowException())
|
#define testingTSkipNow(t) (throw testingprivSkipNowException())
|
||||||
|
@ -86,10 +97,12 @@ typedef struct testingT testingT;
|
||||||
|
|
||||||
// TODO should __LINE__ arguments use intmax_t or uintmax_t instead of int?
|
// TODO should __LINE__ arguments use intmax_t or uintmax_t instead of int?
|
||||||
extern void testingprivRegisterTest(const char *, void (*)(testingT *));
|
extern void testingprivRegisterTest(const char *, void (*)(testingT *));
|
||||||
|
// see https://stackoverflow.com/questions/32399191/va-args-expansion-using-msvc
|
||||||
|
#define testingprivExpand(x) x
|
||||||
|
#define testingprivTLogfThen(then, t, ...) ((testingprivTLogfFull(t, __FILE__, __LINE__, __VA_ARGS__)), (then(t)))
|
||||||
|
#define testingprivTLogvfThen(then, t, format, ap) ((testingprivTLogvfFull(t, __FILE__, __LINE__, format, ap)), (then(t)))
|
||||||
extern void testingprivTLogfFull(testingT *, const char *, int, const char *, ...);
|
extern void testingprivTLogfFull(testingT *, const char *, int, const char *, ...);
|
||||||
extern void testingprivTLogvfFull(testingT *, const char *, int, const char *, va_list);
|
extern void testingprivTLogvfFull(testingT *, const char *, int, const char *, va_list);
|
||||||
extern void testingprivTErrorfFull(testingT *, const char *, int, const char *, ...);
|
|
||||||
extern void testingprivTErrorvfFull(testingT *, const char *, int, const char *, va_list);
|
|
||||||
extern void testingprivTDoFailNow(testingT *);
|
extern void testingprivTDoFailNow(testingT *);
|
||||||
extern void testingprivTDoSkipNow(testingT *);
|
extern void testingprivTDoSkipNow(testingT *);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ void testingprivRegisterTest(const char *name, void (*f)(testingT *))
|
||||||
t->name = name;
|
t->name = name;
|
||||||
t->f = f;
|
t->f = f;
|
||||||
t->failed = 0;
|
t->failed = 0;
|
||||||
|
t->skipped = 0;
|
||||||
t->next = tests;
|
t->next = tests;
|
||||||
tests = t;
|
tests = t;
|
||||||
}
|
}
|
||||||
|
@ -83,24 +84,14 @@ void testingprivTLogvfFull(testingT *t, const char *file, int line, const char *
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void testingprivTErrorfFull(testingT *t, const char *file, int line, const char *format, ...)
|
void testingTFail(testingT *t)
|
||||||
{
|
{
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
testingprivTErrorvfFull(t, file, line, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testingprivTErrorvfFull(testingT *t, const char *file, int line, const char *format, va_list ap)
|
|
||||||
{
|
|
||||||
testingprivTLogvfFull(t, file, line, format, ap);
|
|
||||||
t->failed = 1;
|
t->failed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testingprivTDoFailNow(testingT *t)
|
void testingprivTDoFailNow(testingT *t)
|
||||||
{
|
{
|
||||||
t->failed = 1;
|
testingTFail(t);
|
||||||
longjmp(t->returnNowBuf, 1);
|
longjmp(t->returnNowBuf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue