From aa206b75f8c89ab5e0fdeede558775ae7c072113 Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 21 Dec 2021 01:09:07 -0600 Subject: implement lily_assert_equal() --- src/lily-test.h | 2 ++ src/test.c | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src') 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 diff --git a/src/test.c b/src/test.c index 146f636..8a5d141 100644 --- a/src/test.c +++ b/src/test.c @@ -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; -- cgit v1.2.1