diff options
author | sanine <sanine.not@pm.me> | 2021-12-27 17:24:28 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2021-12-27 17:24:28 -0600 |
commit | faafb95fdda07167770c7823f6b37d99474e1836 (patch) | |
tree | 49644011b1a42e2559b78c8d3745f4c38280437f | |
parent | 0e16dbc5c78a2715fbbda5cae8a3b422d721b871 (diff) |
add test for lily_assert_false
-rw-r--r-- | lily-test.c | 3 | ||||
-rw-r--r-- | tests/assertions.c | 29 | ||||
-rw-r--r-- | tests/main.c | 1 | ||||
-rw-r--r-- | tests/tests.h | 2 |
4 files changed, 33 insertions, 2 deletions
diff --git a/lily-test.c b/lily-test.c index 9b54021..cae4657 100644 --- a/lily-test.c +++ b/lily-test.c @@ -1,6 +1,7 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "lily-test.h" struct lily_globals_t _lily_globals; @@ -66,7 +67,7 @@ void _lily_assert_true(const char *statement, bool value, const char *location) void _lily_assert_false(const char *statement, bool value, const char *location) { - lily_assert_msg(value, location, + lily_assert_msg(!value, location, "%s is not false", statement); } diff --git a/tests/assertions.c b/tests/assertions.c index 0a2875d..ad9fc18 100644 --- a/tests/assertions.c +++ b/tests/assertions.c @@ -73,3 +73,32 @@ const char *test_assert_true() return 0; } + + +const char *test_assert_false() +{ + int val = setjmp(_lily_globals.env); + if (val != 0) + return "true assertion failed incorrectly!"; + + lily_assert_false(false); + + int passed_thru = 0; + _lily_globals.error_msg = NULL; + _lily_globals.error_location = ""; + val = setjmp(_lily_globals.env); + + if (passed_thru == 0) { + passed_thru = 1; + lily_assert_false(true); + return "false assertion incorrectly succeeded!"; + } + 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; +} diff --git a/tests/main.c b/tests/main.c index 65683ee..5dfb679 100644 --- a/tests/main.c +++ b/tests/main.c @@ -13,6 +13,7 @@ int main() run_test(test_LILY_LOCATION); run_test(test_assert_msg); run_test(test_assert_true); + run_test(test_assert_false); return 0; } diff --git a/tests/tests.h b/tests/tests.h index 7962104..ca72b4a 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -10,5 +10,5 @@ int validate_message(const char* received, const char* expected, const char* test_LILY_LOCATION(); const char* test_assert_msg(); const char* test_assert_true(); - +const char* test_assert_false(); #endif |