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;
|
return;
|
||||||
for (i = 1; i < 6; i++)
|
for (i = 1; i < 6; i++)
|
||||||
if (flag == orders[i].result) {
|
if (flag == orders[i].result) {
|
||||||
diff2(t, "wrong order", "%" PRIu32 " (%s)",
|
testingTErrorfFull(t, file, line, "wrong order:" diffx("%" PRIu32 " (%s)"),
|
||||||
flag, orders[i].order,
|
flag, orders[i].order,
|
||||||
orders[0].result, orders[0].order);
|
orders[0].result, orders[0].order);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
diff2(t, "wrong result", "%" PRIu32 " (%s)",
|
testingTErrorfFull(t, file, line, "wrong result:" diffx("%" PRIu32 " (%s)"),
|
||||||
flag, "unknown order",
|
flag, "unknown order",
|
||||||
orders[0].result, orders[0].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;
|
errorParams.caught = true;
|
||||||
if (strstr(prefix, "programmer error") == NULL)
|
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)
|
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)
|
if (strstr(msg, errorParams.msgWant) == NULL)
|
||||||
diff_2str(errorParams.t, errorParams.exprstr, "message doesn't contain expected substring",
|
diff_2str(errorParams.t, errorParams.exprstr, "message doesn't contain expected substring",
|
||||||
"%s", msg, errorParams.msgWant);
|
"%s", msg, errorParams.msgWant);
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
struct errorCase {
|
struct errorCase {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
const char *file;
|
||||||
|
long line;
|
||||||
bool caught;
|
bool caught;
|
||||||
char *prefixGot;
|
char *prefixGot;
|
||||||
bool internalGot;
|
bool internalGot;
|
||||||
|
@ -112,16 +114,16 @@ static void freeCases(struct errorCase *first)
|
||||||
static void reportCases(testingT *t, struct errorCase *p)
|
static void reportCases(testingT *t, struct errorCase *p)
|
||||||
{
|
{
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
testingTLogf(t, "*** %s", p->name);
|
testingTLogfFull(t, p->file, p->line, "*** %s", p->name);
|
||||||
if (!p->caught) {
|
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;
|
p = p->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (p->prefixGot != NULL)
|
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)
|
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)
|
if (p->msgGot != NULL)
|
||||||
diff_2str(t, p->name, "message doesn't contain expected substring",
|
diff_2str(t, p->name, "message doesn't contain expected substring",
|
||||||
"%s", p->msgGot, p->msgWant);
|
"%s", p->msgGot, p->msgWant);
|
||||||
|
@ -134,6 +136,8 @@ static void reportCases(testingT *t, struct errorCase *p)
|
||||||
if (caseError != NULL) \
|
if (caseError != NULL) \
|
||||||
return first; \
|
return first; \
|
||||||
current->name = #f "()"; \
|
current->name = #f "()"; \
|
||||||
|
current->file = __FILE__; \
|
||||||
|
current->line = __LINE__; \
|
||||||
current->msgWant = "attempt to call " #f "() " allcallsMsgSuffix; \
|
current->msgWant = "attempt to call " #f "() " allcallsMsgSuffix; \
|
||||||
f(__VA_ARGS__); \
|
f(__VA_ARGS__); \
|
||||||
if (first == NULL) \
|
if (first == NULL) \
|
||||||
|
|
10
test/test.h
10
test/test.h
|
@ -10,11 +10,9 @@
|
||||||
#include "lib/thread.h"
|
#include "lib/thread.h"
|
||||||
#include "lib/timer.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(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 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
|
// main.c
|
||||||
extern void timeoutMain(void *data);
|
extern void timeoutMain(void *data);
|
||||||
|
@ -32,6 +30,8 @@ extern void timeoutMain(void *data);
|
||||||
}
|
}
|
||||||
struct errorParams {
|
struct errorParams {
|
||||||
testingT *t;
|
testingT *t;
|
||||||
|
const char *file;
|
||||||
|
long line;
|
||||||
// TODO this shouldn't have a colon in it but the diff() macros above necessitate it
|
// TODO this shouldn't have a colon in it but the diff() macros above necessitate it
|
||||||
const char *exprstr;
|
const char *exprstr;
|
||||||
const char *msgWant;
|
const char *msgWant;
|
||||||
|
@ -43,12 +43,14 @@ extern void catchProgrammerError(const char *prefix, const char *msg, const char
|
||||||
testingTLogf(t, "*** %s", #expr); \
|
testingTLogf(t, "*** %s", #expr); \
|
||||||
uiprivTestHookReportProgrammerError(catchProgrammerError); \
|
uiprivTestHookReportProgrammerError(catchProgrammerError); \
|
||||||
errorParams.t = tt; \
|
errorParams.t = tt; \
|
||||||
|
errorParams.file = __FILE__; \
|
||||||
|
errorParams.line = __LINE__; \
|
||||||
errorParams.exprstr = #expr ":"; \
|
errorParams.exprstr = #expr ":"; \
|
||||||
errorParams.msgWant = mw; \
|
errorParams.msgWant = mw; \
|
||||||
errorParams.caught = false; \
|
errorParams.caught = false; \
|
||||||
expr; \
|
expr; \
|
||||||
if (!errorParams.caught) \
|
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); \
|
uiprivTestHookReportProgrammerError(NULL); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue