summaryrefslogtreecommitdiff
path: root/tests/assertions.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/assertions.c')
-rw-r--r--tests/assertions.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/tests/assertions.c b/tests/assertions.c
index ae72fa6..6471225 100644
--- a/tests/assertions.c
+++ b/tests/assertions.c
@@ -16,6 +16,7 @@ const char *test_LILY_LOCATION()
}
+/* overarching assert function */
const char *test_assert_msg()
{
int val = setjmp(_lily_globals.env);
@@ -38,7 +39,7 @@ const char *test_assert_msg()
else {
if (strcmp(_lily_globals.error_msg, "should fail!") != 0)
return "false assertion produced incorrect error message!";
- if (strcmp(_lily_globals.error_location, "tests/assertions.c:35"))
+ if (strcmp(_lily_globals.error_location, "tests/assertions.c:36"))
return "false assertion produced incorrect error location!";
}
@@ -46,6 +47,7 @@ const char *test_assert_msg()
}
+/* basic asserts */
const char *test_assert_true()
{
int val = setjmp(_lily_globals.env);
@@ -67,8 +69,6 @@ const char *test_assert_true()
else {
if (strcmp(_lily_globals.error_msg, "false is not true") != 0)
return "false assertion produced incorrect error message!";
- if (strcmp(_lily_globals.error_location, "tests/assertions.c:64") != 0)
- return "false assertion produced incorrect error location!";
}
return 0;
@@ -96,14 +96,13 @@ const char *test_assert_false()
else {
if (strcmp(_lily_globals.error_msg, "true is not false") != 0)
return "false assertion produced incorrect error message!";
- if (strcmp(_lily_globals.error_location, "tests/assertions.c:93") != 0)
- return "false assertion produced incorrect error location!";
}
return 0;
}
+/* pointer assertions */
const char *test_assert_not_null()
{
int a = 5;
@@ -129,8 +128,6 @@ const char *test_assert_not_null()
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;
@@ -163,8 +160,6 @@ const char *test_assert_null()
sprintf(buf, "&a (%p) is not NULL", &a);
if (strcmp(_lily_globals.error_msg, buf) != 0)
return "false assertion produced incorrect error message!";
- if (strcmp(_lily_globals.error_location, "tests/assertions.c:158") != 0)
- return "false assertion produced incorrect error location!";
}
return 0;
@@ -199,8 +194,6 @@ const char *test_assert_ptr_equal()
sprintf(buf, "&a (%p) is not equal to ptr (%p)", &a, &b);
if (strcmp(_lily_globals.error_msg, buf) != 0)
return "false assertion produced incorrect error message!";
- if (strcmp(_lily_globals.error_location, "tests/assertions.c:194") != 0)
- return "false assertion produced incorrect error location!";
}
return 0;
@@ -235,14 +228,13 @@ const char *test_assert_ptr_not_equal()
sprintf(buf, "&a (%p) is equal to ptr", &a);
if (strcmp(_lily_globals.error_msg, buf) != 0)
return "false assertion produced incorrect error message!";
- if (strcmp(_lily_globals.error_location, "tests/assertions.c:230") != 0)
- return "false assertion produced incorrect error location!";
}
return 0;
}
+/* integer assertions */
const char *test_assert_int_equal()
{
int a = 56;
@@ -268,8 +260,37 @@ const char *test_assert_int_equal()
else {
if (strcmp(_lily_globals.error_msg, "a (25) is not equal to b (56)") != 0)
return "false assertion produced incorrect error message!";
- if (strcmp(_lily_globals.error_location, "tests/assertions.c:265") != 0)
- return "false assertion produced incorrect error location!";
+ }
+
+ return 0;
+}
+
+
+const char *test_assert_int_not_equal()
+{
+ int a = 25;
+ int b = 26;
+
+ int val = setjmp(_lily_globals.env);
+ if (val != 0)
+ return "true assertion failed incorrectly!";
+
+ lily_assert_int_not_equal(a, b);
+
+ int passed_thru = 0;
+ _lily_globals.error_msg = NULL;
+ _lily_globals.error_location = "";
+ val = setjmp(_lily_globals.env);
+ b = 25;
+
+ if (passed_thru == 0) {
+ passed_thru = 1;
+ lily_assert_int_not_equal(a, b);
+ return "false assertion incorrectly succeeded!";
+ }
+ else {
+ if (strcmp(_lily_globals.error_msg, "a (25) is equal to b") != 0)
+ return "false assertion produced incorrect error message!";
}
return 0;