From 8f2536a0d2e653cb393eb81292ce4d029129d404 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 31 Dec 2022 13:52:55 -0600 Subject: modify error message format and add CHECK_EQF --- tests/assertions.c | 31 +++++++++++++++++++++++++++++-- tests/tests.h | 1 + 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/assertions.c b/tests/assertions.c index 39db7bd..6d0c0e1 100644 --- a/tests/assertions.c +++ b/tests/assertions.c @@ -87,7 +87,34 @@ const char * test_CHECK_EQ() if (lily_g.HEAD.next->next != NULL) return "CHECK_EQ appended more than one message"; - if (strcmp(lily_g.HEAD.next->msg, "CHECK failed: 4 == k (04 == 05)") != 0) + if (strcmp(lily_g.HEAD.next->msg, "CHECK failed: 4 == k\n 4 = 04\n k = 05") != 0) + return "incorrect message"; + + lily_msg_destroy(lily_g.HEAD.next); + return 0; +} + + +const char * test_CHECK_EQF() +{ + lily_g.HEAD.next = NULL; + lily_g.TAIL = &(lily_g.HEAD); + lily_g.failed = 0; + + lily_set_epsilon(0.2); + CHECK_EQF(0.5, 0.4, "%0.1f"); + CHECK_EQF(0.5, 0.0, "%0.1f"); + + if (lily_g.HEAD.next == NULL) + return "CHECK_EQF did not append any failure message"; + + if (lily_g.HEAD.next->next != NULL) + return "CHECK_EQF appended more than one message"; + + if (strcmp( + lily_g.HEAD.next->msg, + "CHECK failed: 0.5 == 0.0\n 0.5 = 0.5\n 0.0 = 0.0\n epsilon: 0.200000" + ) != 0) return "incorrect message"; lily_msg_destroy(lily_g.HEAD.next); @@ -158,7 +185,7 @@ const char * test_REQUIRE_EQ() if (lily_g.HEAD.next == NULL) return "test did not generate any messages"; - if (strcmp(lily_g.HEAD.next->msg, "REQUIRE failed: 2 == 4 (2 == 4)") != 0) + if (strcmp(lily_g.HEAD.next->msg, "REQUIRE failed: 2 == 4\n 2 = 2\n 4 = 4") != 0) return "test generated incorrect message"; if (lily_g.HEAD.next->next != NULL) diff --git a/tests/tests.h b/tests/tests.h index c450e13..631044e 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -15,6 +15,7 @@ int validate_message(const char* received, const char* expected, X(test_INFO) \ X(test_CHECK) \ X(test_CHECK_EQ) \ + X(test_CHECK_EQF) \ X(test_REQUIRE) \ X(test_REQUIRE_EQ) \ -- cgit v1.2.1