summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-12-19 19:42:05 -0600
committersanine <sanine.not@pm.me>2022-12-19 19:42:05 -0600
commit5070426785a69dc0b5bd3bbf1cfe7968329b732c (patch)
tree83b5b69caae59e90bf09959bb56f2febd3896551 /tests
parent6c52ff16d6a9abd9292c311f6dc736f37b69dfe9 (diff)
add basic assertion macros
Diffstat (limited to 'tests')
-rw-r--r--tests/assertions.c79
-rw-r--r--tests/main.c2
-rw-r--r--tests/tests.h2
3 files changed, 83 insertions, 0 deletions
diff --git a/tests/assertions.c b/tests/assertions.c
new file mode 100644
index 0000000..6ad855a
--- /dev/null
+++ b/tests/assertions.c
@@ -0,0 +1,79 @@
+#include "lily-test.h"
+#include "tests.h"
+
+
+const char * test_CHECK()
+{
+ lily_g.HEAD.next = NULL;
+ lily_g.TAIL = &(lily_g.HEAD);
+ lily_g.failed = 0;
+ CHECK(1 == 0);
+ CHECK(0 == 0);
+ CHECK(4 == 3);
+
+ if (lily_g.HEAD.next == NULL)
+ return "CHECK did not append any failure messages";
+ lily_test_msg_t *m = lily_g.HEAD.next;
+
+ if (strcmp(m->msg, "1 == 0") != 0)
+ return "first assert has wrong message";
+
+ if (m->next == NULL)
+ return "only one message appended";
+ m = m->next;
+
+ if (strcmp(m->msg, "4 == 3") != 0)
+ return "second message is incorrect";
+
+ if (m->next != NULL)
+ return "more than two messages appended!";
+
+ if (!lily_g.failed)
+ return "test did not fail!";
+
+ lily_msg_destroy(lily_g.HEAD.next);
+
+ return 0;
+}
+
+
+int aR, bR;
+static void f_test_REQUIRE()
+{
+ aR = 5;
+ REQUIRE(2+2 == 5);
+ bR = 5;
+}
+
+const char * test_REQUIRE()
+{
+ lily_g.HEAD.next = NULL;
+ lily_g.TAIL = &(lily_g.HEAD);
+ lily_g.failed = 0;
+ aR = 0; bR = 0;
+ int test_failed = setjmp(lily_g.env);
+
+ if (test_failed) {
+ if (!lily_g.failed)
+ return "test did not fail!";
+
+ if (lily_g.HEAD.next == NULL)
+ return "test did not generate any messages";
+
+ if (strcmp(lily_g.HEAD.next->msg, "2+2 == 5") != 0)
+ return "test generated incorrect message";
+
+ if (lily_g.HEAD.next->next != NULL)
+ return "test generated too many messages";
+
+ if (bR == 5)
+ return "test kept executing after failed REQUIRE";
+
+ lily_msg_destroy(lily_g.HEAD.next);
+ return 0;
+ }
+ else {
+ f_test_REQUIRE();
+ return "test function did not longjump!";
+ }
+}
diff --git a/tests/main.c b/tests/main.c
index 1598190..f1a6de6 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -3,6 +3,8 @@
#include <string.h>
#include <stdlib.h>
+#define LILY_IMPLEMENTATION
+#include "lily-test.h"
#include "tests.h"
int main()
diff --git a/tests/tests.h b/tests/tests.h
index 481260e..06c35af 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -12,6 +12,8 @@ int validate_message(const char* received, const char* expected,
X(test_LILY_COUNTER) \
X(test_LILY_COUNTER_DECREMENT) \
X(test_auto_registration) \
+ X(test_CHECK) \
+ X(test_REQUIRE) \
#define X(test) const char * test();
TESTS