From db8770da7bb9f8763b35480e6e900289aebb45a8 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 16 Jan 2022 13:55:53 -0600 Subject: add test for lily_assert_int_equal --- tests/assertions.c | 33 +++++++++++++++++++++++++++++++++ tests/main.c | 1 + tests/tests.h | 1 + 3 files changed, 35 insertions(+) diff --git a/tests/assertions.c b/tests/assertions.c index 4952943..ae72fa6 100644 --- a/tests/assertions.c +++ b/tests/assertions.c @@ -241,3 +241,36 @@ const char *test_assert_ptr_not_equal() return 0; } + + +const char *test_assert_int_equal() +{ + int a = 56; + int b = 56; + + int val = setjmp(_lily_globals.env); + if (val != 0) + return "true assertion failed incorrectly!"; + + lily_assert_int_equal(a, b); + + int passed_thru = 0; + _lily_globals.error_msg = NULL; + _lily_globals.error_location = ""; + val = setjmp(_lily_globals.env); + a = 25; + + if (passed_thru == 0) { + passed_thru = 1; + lily_assert_int_equal(a, b); + return "false assertion succeeded incorrectly!"; + } + 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; +} diff --git a/tests/main.c b/tests/main.c index b16e058..9752c34 100644 --- a/tests/main.c +++ b/tests/main.c @@ -18,6 +18,7 @@ int main() run_test(test_assert_null); run_test(test_assert_ptr_equal); run_test(test_assert_ptr_not_equal); + run_test(test_assert_int_equal); return 0; } diff --git a/tests/tests.h b/tests/tests.h index 6a7d173..b54534c 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -15,4 +15,5 @@ const char* test_assert_not_null(); const char* test_assert_null(); const char* test_assert_ptr_equal(); const char* test_assert_ptr_not_equal(); +const char* test_assert_int_equal(); #endif -- cgit v1.2.1