Started changing the tests to use bool instead of int.

This commit is contained in:
Pietro Gagliardi 2019-05-30 10:33:39 -04:00
parent 9daef443b2
commit b9d445554a
3 changed files with 27 additions and 26 deletions

View File

@ -36,14 +36,14 @@ struct testingT {
long line; long line;
// test status // test status
int failed; bool failed;
int skipped; bool skipped;
int returned; bool returned;
jmp_buf returnNowBuf; jmp_buf returnNowBuf;
// deferred functions // deferred functions
struct defer *defers; struct defer *defers;
int defersRun; bool defersRun;
// execution options // execution options
testingOptions opts; testingOptions opts;
@ -112,7 +112,7 @@ static void runDefers(testingT *t)
if (t->defersRun) if (t->defersRun)
return; return;
t->defersRun = 1; t->defersRun = true;
for (d = t->defers; d != NULL; d = d->next) for (d = t->defers; d != NULL; d = d->next)
(*(d->f))(t, d->data); (*(d->f))(t, d->data);
} }
@ -121,7 +121,7 @@ static const testingOptions defaultOptions = {
.Verbose = 0, .Verbose = 0,
}; };
static int testingprivTRun(testingT *t, testingprivOutbuf *parentbuf) static bool testingprivTRun(testingT *t, testingprivOutbuf *parentbuf)
{ {
const char *status; const char *status;
timerTime start, end; timerTime start, end;
@ -136,7 +136,7 @@ static int testingprivTRun(testingT *t, testingprivOutbuf *parentbuf)
if (setjmp(t->returnNowBuf) == 0) if (setjmp(t->returnNowBuf) == 0)
(*(t->f))(t, t->data); (*(t->f))(t, t->data);
end = timerMonotonicNow(); end = timerMonotonicNow();
t->returned = 1; t->returned = true;
runDefers(t); runDefers(t);
printStatus = t->opts.Verbose; printStatus = t->opts.Verbose;
@ -155,11 +155,11 @@ static int testingprivTRun(testingT *t, testingprivOutbuf *parentbuf)
testingprivOutbufFree(t->outbuf); testingprivOutbufFree(t->outbuf);
t->outbuf = NULL; t->outbuf = NULL;
return t->failed; return !t->failed;
} }
// TODO rename all options to opts and all format to fmt // TODO rename all options to opts and all format to fmt
static void testingprivSetRun(testingSet *set, const testingOptions *opts, testingprivOutbuf *outbuf, int *anyFailed) static void testingprivSetRun(testingSet *set, const testingOptions *opts, testingprivOutbuf *outbuf, bool *anyFailed)
{ {
size_t i; size_t i;
testingT *t; testingT *t;
@ -168,16 +168,16 @@ static void testingprivSetRun(testingSet *set, const testingOptions *opts, testi
t = (testingT *) (set->tests.buf); t = (testingT *) (set->tests.buf);
for (i = 0; i < set->tests.len; i++) { for (i = 0; i < set->tests.len; i++) {
t->opts = *opts; t->opts = *opts;
if (testingprivTRun(t, outbuf) != 0) if (!testingprivTRun(t, outbuf))
*anyFailed = 1; *anyFailed = true;
t++; t++;
} }
} }
void testingSetRun(testingSet *set, const struct testingOptions *options, int *anyRun, int *anyFailed) void testingSetRun(testingSet *set, const struct testingOptions *options, bool *anyRun, bool *anyFailed)
{ {
*anyRun = 0; *anyRun = false;
*anyFailed = 0; *anyFailed = false;
if (set == NULL) if (set == NULL)
set = &mainTests; set = &mainTests;
if (options == NULL) if (options == NULL)
@ -185,7 +185,7 @@ void testingSetRun(testingSet *set, const struct testingOptions *options, int *a
if (set->tests.len == 0) if (set->tests.len == 0)
return; return;
testingprivSetRun(set, options, NULL, anyFailed); testingprivSetRun(set, options, NULL, anyFailed);
*anyRun = 1; *anyRun = true;
} }
void testingprivTLogfFull(testingT *t, const char *file, long line, const char *format, ...) void testingprivTLogfFull(testingT *t, const char *file, long line, const char *format, ...)
@ -219,14 +219,14 @@ void testingprivTLogvfFull(testingT *t, const char *file, long line, const char
void testingTFail(testingT *t) void testingTFail(testingT *t)
{ {
t->failed = 1; t->failed = true;
} }
static void returnNow(testingT *t) static void returnNow(testingT *t)
{ {
if (!t->returned) { if (!t->returned) {
// set this now so a FailNow inside a Defer doesn't longjmp twice // set this now so a FailNow inside a Defer doesn't longjmp twice
t->returned = 1; t->returned = true;
// run defers before calling longjmp() just to be safe // run defers before calling longjmp() just to be safe
runDefers(t); runDefers(t);
longjmp(t->returnNowBuf, 1); longjmp(t->returnNowBuf, 1);
@ -241,7 +241,7 @@ void testingTFailNow(testingT *t)
void testingTSkipNow(testingT *t) void testingTSkipNow(testingT *t)
{ {
t->skipped = 1; t->skipped = true;
returnNow(t); returnNow(t);
} }
@ -298,8 +298,8 @@ void testingTRun(testingT *t, const char *subname, void (*subfunc)(testingT *t,
subt = testingprivNew(testingT); subt = testingprivNew(testingT);
initTest(subt, fullName, subfunc, data, NULL, 0); initTest(subt, fullName, subfunc, data, NULL, 0);
subt->opts = t->opts; subt->opts = t->opts;
if (testingprivTRun(subt, t->outbuf) != 0) if (!testingprivTRun(subt, t->outbuf))
t->failed = 1; t->failed = true;
testingprivFree(subt); testingprivFree(subt);
testingprivFree(fullName); testingprivFree(fullName);

View File

@ -1,6 +1,7 @@
// 27 february 2018 // 27 february 2018
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#define testingprivImplName(basename) testingprivImpl ## basename #define testingprivImplName(basename) testingprivImpl ## basename
@ -45,7 +46,7 @@ struct testingOptions {
int Verbose; int Verbose;
}; };
extern void testingSetRun(testingSet *set, const struct testingOptions *options, int *anyRun, int *anyFailed); extern void testingSetRun(testingSet *set, const struct testingOptions *options, bool *anyRun, bool *anyFailed);
typedef struct testingT testingT; typedef struct testingT testingT;
#define testingTLogf(t, ...) \ #define testingTLogf(t, ...) \

View File

@ -22,21 +22,21 @@ void catchProgrammerError(const char *prefix, const char *msg, const char *suffi
"%s", msg, errorParams.msgWant); "%s", msg, errorParams.msgWant);
} }
static void runSetORingResults(testingSet *set, const struct testingOptions *options, int *anyRun, int *anyFailed) static void runSetORingResults(testingSet *set, const struct testingOptions *options, bool *anyRun, bool *anyFailed)
{ {
int ar, af; bool ar, af;
testingSetRun(set, options, &ar, &af); testingSetRun(set, options, &ar, &af);
if (ar) if (ar)
*anyRun = 1; *anyRun = true;
if (af) if (af)
*anyFailed = 1; *anyFailed = true;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
testingOptions opts; testingOptions opts;
int anyRun = 0, anyFailed = 0; bool anyRun = false, anyFailed = false;
uiInitError err; uiInitError err;
int ret; int ret;