summaryrefslogtreecommitdiff
path: root/tests/assertions.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-12-22 00:27:43 -0600
committersanine <sanine.not@pm.me>2021-12-22 00:27:43 -0600
commitedb8c6114a20b806c56dd0225dd39e333ffb3ac3 (patch)
tree00ac174b41c0979a9c482e0cf68879341d4b7de0 /tests/assertions.c
parent7634dd65ac55a0fe4e7ed69cee7e3957f574a03e (diff)
re-implement basic lily_assert_msg() macro
Diffstat (limited to 'tests/assertions.c')
-rw-r--r--tests/assertions.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/assertions.c b/tests/assertions.c
new file mode 100644
index 0000000..0c443b5
--- /dev/null
+++ b/tests/assertions.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "lily-test.h"
+#include "tests.h"
+
+// basic assertion
+lily_test wrap_assert_msg(int statement, const char *message)
+{
+ // if you move the location of this line, BE SURE TO UPDATE THE
+ // TEST BELOW so that it expects the correct line!
+ lily_assert_msg(statement, message);
+ return LILY_SUCCESS;
+}
+
+const char* basic_assertion()
+{
+ lily_test result = wrap_assert_msg(1, "should succeed");
+ if (result.error != 0)
+ return "assert_msg() incorrectly returned non-zero error on true statement!";
+
+ result = wrap_assert_msg(0, "should fail");
+ if (result.error == 0)
+ return "assert_msg() incorrectly returned zero error on false statement!";
+ if (strcmp(result.message, "should fail") != 0)
+ return "assert_msg() returned with incorrect message!";
+ if (strcmp(result.location, "tests/assertions.c:12") != 0)
+ return "assert_msg() returned with incorrect location!";
+
+ return 0;
+}