Cleaned up programmer error testing code.
This commit is contained in:
parent
7808b3ee94
commit
7cb4f010d4
|
@ -70,7 +70,7 @@ static void wantBlocked(struct handler *h)
|
|||
h->wantBlocked = true;
|
||||
}
|
||||
|
||||
// TODO carry over the file nad line numbers somehow
|
||||
// TODO carry over the file and line numbers somehow
|
||||
static void run(testingT *t, uiEvent *e, void *sender, void *args, struct handler *handlers, int n, int wantRunCount)
|
||||
{
|
||||
int i;
|
||||
|
@ -684,36 +684,8 @@ testingTest(EventBlocksHonoredWithDifferentSenders)
|
|||
runGlobalSubtests(t, &p);
|
||||
}
|
||||
|
||||
static struct {
|
||||
testingT *t;
|
||||
const char *msgWant;
|
||||
bool caught;
|
||||
} errorParams;
|
||||
|
||||
static void catchProgrammerError(const char *prefix, const char *msg, const char *suffix, bool internal)
|
||||
{
|
||||
errorParams.caught = true;
|
||||
if (strstr(prefix, "programmer error") == NULL)
|
||||
testingTErrorf(errorParams.t, "prefix string doesn't contain \"programmer error\": %s", prefix);
|
||||
if (internal)
|
||||
testingTErrorf(errorParams.t, "error is marked internal; should not have been");
|
||||
if (strstr(msg, errorParams.msgWant) == NULL)
|
||||
diff(errorParams.t, "message doesn't contain expected substring",
|
||||
"%s", msg, errorParams.msgWant);
|
||||
}
|
||||
|
||||
testingTest(EventErrors)
|
||||
{
|
||||
uiprivTestHookReportProgrammerError(catchProgrammerError);
|
||||
|
||||
testingTLogf(t, "*** uiNewEvent(NULL)");
|
||||
errorParams.t = t;
|
||||
errorParams.msgWant = "invalid null pointer for uiEventOptions passed into uiNewEvent()";
|
||||
errorParams.caught = false;
|
||||
if (uiNewEvent(NULL) != NULL)
|
||||
testingTErrorf(t, "uiNewEvent(NULL) returned non-NULL; wanted NULL");
|
||||
if (!errorParams.caught)
|
||||
testingTErrorf(t, "uiNewEvent(NULL) did not throw a programmer error; should have");
|
||||
|
||||
uiprivTestHookReportProgrammerError(NULL);
|
||||
testProgrammerError(t, uiNewEvent(NULL),
|
||||
"invalid null pointer for uiEventOptions passed into uiNewEvent()");
|
||||
}
|
||||
|
|
14
test/main.c
14
test/main.c
|
@ -8,6 +8,20 @@ void timeoutMain(void *data)
|
|||
uiMain();
|
||||
}
|
||||
|
||||
struct errorParams errorParams;
|
||||
|
||||
void catchProgrammerError(const char *prefix, const char *msg, const char *suffix, bool internal)
|
||||
{
|
||||
errorParams.caught = true;
|
||||
if (strstr(prefix, "programmer error") == NULL)
|
||||
testingTErrorf(errorParams.t, "%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);
|
||||
if (strstr(msg, errorParams.msgWant) == NULL)
|
||||
diff_2str(errorParams.t, errorParams.exprstr, "message doesn't contain expected substring",
|
||||
"%s", msg, errorParams.msgWant);
|
||||
}
|
||||
|
||||
static void runSetORingResults(testingSet *set, const struct testingOptions *options, int *anyRun, int *anyFailed)
|
||||
{
|
||||
int ar, af;
|
||||
|
|
21
test/test.h
21
test/test.h
|
@ -25,6 +25,27 @@ extern void timeoutMain(void *data);
|
|||
testingTErrorf(t, "uiMain() timed out (%s)", timeoutstr); \
|
||||
} \
|
||||
}
|
||||
struct errorParams {
|
||||
testingT *t;
|
||||
// TODO this shouldn't have a colon in it but the diff() macros above necessitate it
|
||||
const char *exprstr;
|
||||
const char *msgWant;
|
||||
bool caught;
|
||||
};
|
||||
extern struct errorParams errorParams;
|
||||
extern void catchProgrammerError(const char *prefix, const char *msg, const char *suffix, bool internal);
|
||||
#define testProgrammerError(tt, expr, mw) { \
|
||||
testingTLogf(t, "*** %s", #expr); \
|
||||
uiprivTestHookReportProgrammerError(catchProgrammerError); \
|
||||
errorParams.t = tt; \
|
||||
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); \
|
||||
uiprivTestHookReportProgrammerError(NULL); \
|
||||
}
|
||||
|
||||
// init.c
|
||||
extern testingSet *beforeTests;
|
||||
|
|
Loading…
Reference in New Issue