summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-12-31 14:00:24 -0600
committersanine <sanine.not@pm.me>2022-12-31 14:00:24 -0600
commit590b2997f93006112be93807b7e7a36d56d52809 (patch)
tree5f6ce405813c9a288109177798c60407fa19f7f8
parent8f2536a0d2e653cb393eb81292ce4d029129d404 (diff)
add CHECK_EQS
-rw-r--r--lily-test.h6
-rw-r--r--tests/assertions.c30
-rw-r--r--tests/tests.h1
3 files changed, 37 insertions, 0 deletions
diff --git a/lily-test.h b/lily-test.h
index c26237a..6aafb8f 100644
--- a/lily-test.h
+++ b/lily-test.h
@@ -160,6 +160,12 @@ void lily_check(int x, const char *location, const char *fmt, ...);
xstr, ystr, xstr, x, ystr, y, lily_g.epsilon)
#define CHECK_EQF(x, y, fmt) LILY_CHECK_EQF(x, y, #x, #y, fmt)
+#define LILY_CHECK_EQS(x, y, xstr, ystr) \
+ lily_check(strcmp(x, y) == 0, LILY_LOCATION, \
+ "CHECK failed: %s == %s\n %s = \"%s\"\n %s = \"%s\"", \
+ xstr, ystr, xstr, x, ystr, y)
+#define CHECK_EQS(x, y) LILY_CHECK_EQS(x, y, #x, #y)
+
void lily_require(int x, const char *location, const char *fmt, ...);
#define LILY_REQUIRE_(str, x, location) \
diff --git a/tests/assertions.c b/tests/assertions.c
index 6d0c0e1..e79ae44 100644
--- a/tests/assertions.c
+++ b/tests/assertions.c
@@ -122,6 +122,36 @@ const char * test_CHECK_EQF()
}
+const char * test_CHECK_EQS()
+{
+ lily_g.HEAD.next = NULL;
+ lily_g.TAIL = &(lily_g.HEAD);
+ lily_g.failed = 0;
+
+ const char *a = "hi";
+ const char *b = "bye";
+ CHECK_EQS(a, b);
+ CHECK_EQS("hi hi"+3, a);
+
+ if (lily_g.HEAD.next == NULL)
+ return "CHECK_EQS did not append any failure message";
+
+ if (lily_g.HEAD.next->next != NULL)
+ return "CHECK_EQS appended more than one message";
+
+ if (strcmp(
+ lily_g.HEAD.next->msg,
+ "CHECK failed: a == b\n a = \"hi\"\n b = \"bye\""
+ ) != 0)
+ return "incorrect message";
+
+ lily_msg_destroy(lily_g.HEAD.next);
+ return 0;
+}
+
+
+
+
int aR, bR;
static void f_test_REQUIRE()
{
diff --git a/tests/tests.h b/tests/tests.h
index 631044e..d6d95d1 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -16,6 +16,7 @@ int validate_message(const char* received, const char* expected,
X(test_CHECK) \
X(test_CHECK_EQ) \
X(test_CHECK_EQF) \
+ X(test_CHECK_EQS) \
X(test_REQUIRE) \
X(test_REQUIRE_EQ) \