summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-12-30 14:03:26 -0600
committersanine <sanine.not@pm.me>2022-12-30 14:03:26 -0600
commitb8c647c9250b514a5daa11ea731691b19944aa4e (patch)
treef3074710bc4f99bc9cdd4f8fe33313a0e8890bfa /tests
parente48761f7ca1dba622b54b7f2223854645996fc30 (diff)
add CHECK and REQUIRE comparison assertions
Diffstat (limited to 'tests')
-rw-r--r--tests/assertions.c37
-rw-r--r--tests/tests.h1
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/assertions.c b/tests/assertions.c
index 5a32854..39db7bd 100644
--- a/tests/assertions.c
+++ b/tests/assertions.c
@@ -135,3 +135,40 @@ const char * test_REQUIRE()
return "test function did not longjump!";
}
}
+
+
+void f_test_REQUIRE_EQ()
+{
+ REQUIRE_EQ(2, 2, "%d");
+ REQUIRE_EQ(2, 4, "%d");
+ REQUIRE_EQ(2, 1, "%d");
+}
+
+const char * test_REQUIRE_EQ()
+{
+ lily_g.HEAD.next = NULL;
+ lily_g.TAIL = &(lily_g.HEAD);
+ lily_g.failed = 0;
+ int test_failed = setjmp(lily_g.env);
+
+ if (test_failed) {
+ if (!lily_g.failed)
+ return "test did not mark itself as failed";
+
+ if (lily_g.HEAD.next == NULL)
+ return "test did not generate any messages";
+
+ if (strcmp(lily_g.HEAD.next->msg, "REQUIRE failed: 2 == 4 (2 == 4)") != 0)
+ return "test generated incorrect message";
+
+ if (lily_g.HEAD.next->next != NULL)
+ return "test generated too many messages";
+
+ lily_msg_destroy(lily_g.HEAD.next);
+ return 0;
+ }
+ else {
+ f_test_REQUIRE_EQ();
+ return "test function did not longjump!";
+ }
+}
diff --git a/tests/tests.h b/tests/tests.h
index 393da87..c450e13 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_REQUIRE) \
+ X(test_REQUIRE_EQ) \
#define X(test) const char * test();
TESTS