diff options
author | sanine <sanine.not@pm.me> | 2021-12-21 01:09:07 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2021-12-21 01:09:07 -0600 |
commit | aa206b75f8c89ab5e0fdeede558775ae7c072113 (patch) | |
tree | bde11cad316c377aa0433793175f9eb9eaaf667e /src | |
parent | 781b61d0d0131c880d54bd9667fb0b9c81643ba7 (diff) |
implement lily_assert_equal()
Diffstat (limited to 'src')
-rw-r--r-- | src/lily-test.h | 2 | ||||
-rw-r--r-- | src/test.c | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/lily-test.h b/src/lily-test.h index 8ce0f41..e8faf54 100644 --- a/src/lily-test.h +++ b/src/lily-test.h @@ -26,5 +26,7 @@ struct lily_test_data_t { "\n" lily_indent " [" __FILE__ ":" STR(__LINE__) "]"; \ } while(0) +#define lily_assert_equal(a, b) lily_assert((a) == (b), "'" #a "' is not equal to '" #b "'") + #endif @@ -77,9 +77,31 @@ lily_test check_assert() } +const char *assert_eq_true() +{ + lily_assert_equal(15, 15); + return 0; +} +const char *assert_eq_false() +{ + lily_assert_equal(14, 15); + return 0; +} + lily_test check_other_asserts() { - + if (assert_eq_true() != 0) + return "equality assertion returned non-zero when true!"; + const char *result = assert_eq_false(); + if (result == 0) + return "equality assertion returned zero when false!"; + char *message; + if (!get_message(&message, result)) + return "false equality assertion returned malformed message!"; + if (strcmp(message, "'14' is not equal to '15'") != 0) + return "false equality assertion returned incorrect message!"; + + return 0; } @@ -87,6 +109,7 @@ int main() { run_test("check LILY_INIT()", check_init); run_test("check basic assertion", check_assert); + run_test("check other asserts", check_other_asserts); printf("all tests finished.\n"); return 0; |