summaryrefslogtreecommitdiff
path: root/tests/assertions.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-12-27 17:28:29 -0600
committersanine <sanine.not@pm.me>2021-12-27 17:28:29 -0600
commit342f577c24439977985e2de89fe512e504489735 (patch)
tree6df409b7ee4a494450fb125bd89b63396398da4d /tests/assertions.c
parentfaafb95fdda07167770c7823f6b37d99474e1836 (diff)
add test for assert_not_null
Diffstat (limited to 'tests/assertions.c')
-rw-r--r--tests/assertions.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/assertions.c b/tests/assertions.c
index ad9fc18..d1ba141 100644
--- a/tests/assertions.c
+++ b/tests/assertions.c
@@ -102,3 +102,36 @@ const char *test_assert_false()
return 0;
}
+
+
+const char *test_assert_not_null()
+{
+ int a = 5;
+
+ int val = setjmp(_lily_globals.env);
+ if (val != 0)
+ return "true assertion failed incorrectly!";
+
+ lily_assert_not_null(&a);
+
+ int passed_thru = 0;
+ _lily_globals.error_msg = NULL;
+ _lily_globals.error_location = "";
+ val = setjmp(_lily_globals.env);
+
+ int *ptr = NULL;
+
+ if (passed_thru == 0) {
+ passed_thru = 1;
+ lily_assert_not_null(ptr);
+ return "false assertion incorrectly succeeded!";
+ }
+ else {
+ if (strcmp(_lily_globals.error_msg, "ptr is NULL") != 0)
+ return "false assertion produced incorrect error message!";
+ if (strcmp(_lily_globals.error_location, "tests/assertions.c:126") != 0)
+ return "false assertion produced incorrect error location!";
+ }
+
+ return 0;
+}