Got rid of all the diff() macros; the replacement, currently called diffx(), just produces the requisite format string. Next up is renaming diffx() to diff() and making sure things work.

This commit is contained in:
Pietro Gagliardi 2019-06-02 01:51:40 -04:00
parent 5d1e6a0cf2
commit 0c673acf70
5 changed files with 15 additions and 18 deletions

View File

@ -94,11 +94,11 @@ static void runFull(testingT *t, const char *file, long line, uiEvent *e, void *
if (h->gotRun && h->wantRun) {
// only check these if it was correctly run, to reduce noise if the above failed
if (h->gotSender != h->wantSender)
diff_2str(t, "incorrect sender seen by", h->name,
"%p", h->gotSender, h->wantSender);
testingTErrorfFull(t, file, line, "incorrect sender seen by %s:" diffx("%p"),
h->name, h->gotSender, h->wantSender);
if (h->gotArgs != h->wantArgs)
diff_2str(t, "incorrect args seen by", h->name,
"%p", h->gotArgs, h->wantArgs);
testingTErrorfFull(t, file, line, "incorrect args seen by %s:" diffx("%p"),
h->name, h->gotArgs, h->wantArgs);
}
if (h->validID) {
// the following call will fail if the ID isn't valid
@ -111,8 +111,8 @@ static void runFull(testingT *t, const char *file, long line, uiEvent *e, void *
h++;
}
if (gotRunCount != wantRunCount)
diff(t, "incorrect number of handler runs",
"%d", gotRunCount, wantRunCount);
testingTErrorfFull(t, file, line, "incorrect number of handler runs:" diffx("%d"),
gotRunCount, wantRunCount);
}
#define run(t, e, sender, args, handlers, n, wantRunCount) runFull(t, __FILE__, __LINE__, e, sender, args, handlers, n, wantRunCount)

View File

@ -24,7 +24,7 @@ testingTestInSet(beforeTests, Init)
if (uiInit(&err, &err))
testingTErrorf(t, "uiInit() with non-NULL options succeeded; expected failure");
if (strcmp(err.Message, errInvalidOptions) != 0)
diff(t, "uiInit() with non-NULL options returned bad error message", "%s",
testingTErrorf(t, "uiInit() with non-NULL options returned bad error message:" diffx("%s"),
err.Message, errInvalidOptions);
}
@ -37,7 +37,7 @@ testingTest(InitAfterInitialized)
if (uiInit(NULL, &err))
testingTErrorf(t, "uiInit() after a previous successful call succeeded; expected failure");
if (strcmp(err.Message, errAlreadyInitialized) != 0)
diff(t, "uiInit() after a previous successful call returned bad error message", "%s",
testingTErrorf(t, "uiInit() after a previous successful call returned bad error message:" diffx("%s"),
err.Message, errAlreadyInitialized);
}
@ -69,7 +69,7 @@ testingTest(QueueMain)
uiQueueMain(queued, &p);
timeout_uiMain(t, 5 * timerSecond);
if (p.flag != 1)
diff(t, "uiQueueMain() didn't set flag properly", "%d",
testingTErrorf(t, "uiQueueMain() didn't set flag properly:" diffx("%d"),
p.flag, 1);
}
@ -165,7 +165,7 @@ testingTest(QueueMain_DifferentThread)
if (p.err != 0)
testingTErrorf(t, "error sleeping in thread to ensure a high likelihood the uiQueueMain() is run after uiMain() starts: " timerSysErrorFmt, timerSysErrorFmtArg(p.err));
if (p.flag != 1)
diff(t, "uiQueueMain() didn't set flag properly", "%d",
testingTErrorf(t, "uiQueueMain() didn't set flag properly:" diffx("%d"),
p.flag, 1);
}

View File

@ -16,8 +16,8 @@ void catchProgrammerError(const char *prefix, const char *msg, const char *suffi
if (internal)
testingTErrorfFull(errorParams.t, errorParams.file, errorParams.line, "%s error is marked internal; should not have been", errorParams.exprstr);
if (strstr(msg, errorParams.msgWant) == NULL)
diff_2str(errorParams.t, errorParams.exprstr, "message doesn't contain expected substring",
"%s", msg, errorParams.msgWant);
testingTErrorf(errorParams.t, errorParams.file, errorParams.line, "%s: message doesn't contain expected substring:" diffx("%s"),
errorParams.exprstr, msg, errorParams.msgWant);
}
static void runSetORingResults(testingSet *set, const struct testingOptions *options, bool *anyRun, bool *anyFailed)

View File

@ -125,8 +125,8 @@ static void reportCases(testingT *t, struct errorCase *p)
if (p->internalGot)
testingTErrorfFull(t, p->file, p->line, "%s error is marked internal; should not have been", p->name);
if (p->msgGot != NULL)
diff_2str(t, p->name, "message doesn't contain expected substring",
"%s", p->msgGot, p->msgWant);
testingTErrorfFull(t, p->file, p->line, "%s message doesn't contain expected substring:" diffx("%s"),
p->name, p->msgGot, p->msgWant);
p = p->next;
}
}

View File

@ -11,8 +11,6 @@
#include "lib/timer.h"
#define diffx(fmt) "\ngot " fmt "\nwant " fmt
#define diff(t, clause, fmt, got, want) testingTErrorf(t, "%s:\ngot " fmt "\nwant " fmt, clause, got, want)
#define diff_2str(t, clause, clause2, fmt, got, want) testingTErrorf(t, "%s %s:\ngot " fmt "\nwant " fmt, clause, clause2, got, want)
// main.c
extern void timeoutMain(void *data);
@ -32,7 +30,6 @@ struct errorParams {
testingT *t;
const char *file;
long line;
// TODO this shouldn't have a colon in it but the diff() macros above necessitate it
const char *exprstr;
const char *msgWant;
bool caught;
@ -45,7 +42,7 @@ extern void catchProgrammerError(const char *prefix, const char *msg, const char
errorParams.t = tt; \
errorParams.file = __FILE__; \
errorParams.line = __LINE__; \
errorParams.exprstr = #expr ":"; \
errorParams.exprstr = #expr; \
errorParams.msgWant = mw; \
errorParams.caught = false; \
expr; \