summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/assertions.c33
-rw-r--r--tests/main.c1
-rw-r--r--tests/tests.h1
3 files changed, 35 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;
+}
diff --git a/tests/main.c b/tests/main.c
index 5dfb679..32c6944 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -14,6 +14,7 @@ int main()
run_test(test_assert_msg);
run_test(test_assert_true);
run_test(test_assert_false);
+ run_test(test_assert_not_null);
return 0;
}
diff --git a/tests/tests.h b/tests/tests.h
index ca72b4a..46cfb2e 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -11,4 +11,5 @@ const char* test_LILY_LOCATION();
const char* test_assert_msg();
const char* test_assert_true();
const char* test_assert_false();
+const char* test_assert_not_null();
#endif