From 7486ff6b2520813a1f979ae1cce8ea4f3b85dd04 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 9 Jun 2019 13:44:46 -0400 Subject: [PATCH] Changed the programmer error tests to require a strict match. Now I want to restructure them to both be reusable and to not require global state. --- test/main.c | 6 ++++-- test/noinitwrongthread.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/main.c b/test/main.c index f7855bf3..fea908d9 100644 --- a/test/main.c +++ b/test/main.c @@ -11,11 +11,13 @@ 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) + if (strcmp(prefix, "libui programmer error") != 0) + // TODO use diff testingTErrorfFull(errorParams.t, errorParams.file, errorParams.line, "%s prefix string doesn't contain \"programmer error\": %s", errorParams.exprstr, prefix); 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) + if (strcmp(msg, errorParams.msgWant) != 0) + // TODO use diff testingTErrorfFull(errorParams.t, errorParams.file, errorParams.line, "%s: message doesn't contain expected substring:" diff("%s"), errorParams.exprstr, msg, errorParams.msgWant); } diff --git a/test/noinitwrongthread.c b/test/noinitwrongthread.c index 99a52ab5..6eed8027 100644 --- a/test/noinitwrongthread.c +++ b/test/noinitwrongthread.c @@ -57,7 +57,7 @@ static void catalogProgrammerError(const char *prefix, const char *msg, const ch size_t n; current->caught = true; - if (strstr(prefix, "programmer error") == NULL) { + if (strcmp(prefix, "libui programmer error") != 0) { n = strlen(prefix); current->prefixGot = (char *) malloc((n + 1) * sizeof (char)); if (current->prefixGot == NULL) { @@ -69,7 +69,7 @@ static void catalogProgrammerError(const char *prefix, const char *msg, const ch return; } current->internalGot = internal; - if (strstr(msg, current->msgWant) == NULL) { + if (strcmp(msg, current->msgWant) != 0) { n = strlen(msg); current->msgGot = (char *) malloc((n + 1) * sizeof (char)); if (current->msgGot == NULL) { @@ -121,10 +121,12 @@ static void reportCases(testingT *t, struct errorCase *p) continue; } if (p->prefixGot != NULL) + // TODO use diff testingTErrorfFull(t, p->file, p->line, "%s prefix string doesn't contain \"programmer error\": %s", p->name, p->prefixGot); if (p->internalGot) testingTErrorfFull(t, p->file, p->line, "%s error is marked internal; should not have been", p->name); if (p->msgGot != NULL) + // TODO use diff testingTErrorfFull(t, p->file, p->line, "%s message doesn't contain expected substring:" diff("%s"), p->name, p->msgGot, p->msgWant); p = p->next;