Began handling all the other cases. diff() and diff_2str() go away next.
This commit is contained in:
parent
1cf545d369
commit
5d1e6a0cf2
|
@ -117,12 +117,12 @@ static void checkOrderFull(testingT *t, const char *file, long line, uint32_t fl
|
|||
return;
|
||||
for (i = 1; i < 6; i++)
|
||||
if (flag == orders[i].result) {
|
||||
diff2(t, "wrong order", "%" PRIu32 " (%s)",
|
||||
testingTErrorfFull(t, file, line, "wrong order:" diffx("%" PRIu32 " (%s)"),
|
||||
flag, orders[i].order,
|
||||
orders[0].result, orders[0].order);
|
||||
return;
|
||||
}
|
||||
diff2(t, "wrong result", "%" PRIu32 " (%s)",
|
||||
testingTErrorfFull(t, file, line, "wrong result:" diffx("%" PRIu32 " (%s)"),
|
||||
flag, "unknown order",
|
||||
orders[0].result, orders[0].order);
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ void catchProgrammerError(const char *prefix, const char *msg, const char *suffi
|
|||
{
|
||||
errorParams.caught = true;
|
||||
if (strstr(prefix, "programmer error") == NULL)
|
||||
testingTErrorf(errorParams.t, "%s prefix string doesn't contain \"programmer error\": %s", errorParams.exprstr, prefix);
|
||||
testingTErrorfFull(errorParams.t, errorParams.file, errorParams.line, "%s prefix string doesn't contain \"programmer error\": %s", errorParams.exprstr, prefix);
|
||||
if (internal)
|
||||
testingTErrorf(errorParams.t, "%s error is marked internal; should not have been", errorParams.exprstr);
|
||||
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);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
struct errorCase {
|
||||
const char *name;
|
||||
const char *file;
|
||||
long line;
|
||||
bool caught;
|
||||
char *prefixGot;
|
||||
bool internalGot;
|
||||
|
@ -112,16 +114,16 @@ static void freeCases(struct errorCase *first)
|
|||
static void reportCases(testingT *t, struct errorCase *p)
|
||||
{
|
||||
while (p != NULL) {
|
||||
testingTLogf(t, "*** %s", p->name);
|
||||
testingTLogfFull(t, p->file, p->line, "*** %s", p->name);
|
||||
if (!p->caught) {
|
||||
testingTErrorf(t, "%s did not throw a programmer error; should have", p->name);
|
||||
testingTErrorfFull(t, p->file, p->line, "%s did not throw a programmer error; should have", p->name);
|
||||
p = p->next;
|
||||
continue;
|
||||
}
|
||||
if (p->prefixGot != NULL)
|
||||
testingTErrorf(t, "%s prefix string doesn't contain \"programmer error\": %s", p->name, p->prefixGot);
|
||||
testingTErrorfFull(t, p->file, p->line, "%s prefix string doesn't contain \"programmer error\": %s", p->name, p->prefixGot);
|
||||
if (p->internalGot)
|
||||
testingTErrorf(t, "%s error is marked internal; should not have been", p->name);
|
||||
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);
|
||||
|
@ -134,6 +136,8 @@ static void reportCases(testingT *t, struct errorCase *p)
|
|||
if (caseError != NULL) \
|
||||
return first; \
|
||||
current->name = #f "()"; \
|
||||
current->file = __FILE__; \
|
||||
current->line = __LINE__; \
|
||||
current->msgWant = "attempt to call " #f "() " allcallsMsgSuffix; \
|
||||
f(__VA_ARGS__); \
|
||||
if (first == NULL) \
|
||||
|
|
10
test/test.h
10
test/test.h
|
@ -10,11 +10,9 @@
|
|||
#include "lib/thread.h"
|
||||
#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)
|
||||
#define diff2(t, clause, fmts, got1, got2, want1, want2) testingTErrorf(t, "%s:\ngot " fmts "\nwant " fmts, clause, got1, got2, want1, want2)
|
||||
#define diffFatal(t, clause, fmt, got, want) testingTFatalf(t, "%s:\ngot " fmt "\nwant " fmt, clause, got, want)
|
||||
#define diff2Fatal(t, clause, fmts, got1, got2, want1, want2) testingTFatalf(t, "%s:\ngot " fmts "\nwant " fmts, clause, got1, got2, want1, want2)
|
||||
|
||||
// main.c
|
||||
extern void timeoutMain(void *data);
|
||||
|
@ -32,6 +30,8 @@ extern void timeoutMain(void *data);
|
|||
}
|
||||
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;
|
||||
|
@ -43,12 +43,14 @@ extern void catchProgrammerError(const char *prefix, const char *msg, const char
|
|||
testingTLogf(t, "*** %s", #expr); \
|
||||
uiprivTestHookReportProgrammerError(catchProgrammerError); \
|
||||
errorParams.t = tt; \
|
||||
errorParams.file = __FILE__; \
|
||||
errorParams.line = __LINE__; \
|
||||
errorParams.exprstr = #expr ":"; \
|
||||
errorParams.msgWant = mw; \
|
||||
errorParams.caught = false; \
|
||||
expr; \
|
||||
if (!errorParams.caught) \
|
||||
testingTErrorf(t, "%s did not throw a programmer error; should have", #expr); \
|
||||
testingTErrorfFull(t, errorParams.file, errorParams.line, "%s did not throw a programmer error; should have", #expr); \
|
||||
uiprivTestHookReportProgrammerError(NULL); \
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue