diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/assertions.c | 64 | ||||
-rw-r--r-- | tests/tests.h | 2 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/assertions.c b/tests/assertions.c index 6951f58..280bb97 100644 --- a/tests/assertions.c +++ b/tests/assertions.c @@ -149,6 +149,33 @@ const char * test_CHECK_EQS() return 0; } +const char * test_CHECK_EQS_NULL() +{ + lily_g.HEAD.next = NULL; + lily_g.TAIL = &(lily_g.HEAD); + lily_g.failed = 0; + + const char *a = "hi"; + const char *b = "bye"; + CHECK_EQS(a, NULL); + CHECK_EQS(a, "hi"); + + if (lily_g.HEAD.next == NULL) + return "CHECK_EQS did not append any failure message"; + + if (lily_g.HEAD.next->next != NULL) + return "CHECK_EQS appended more than one message"; + + if (strcmp( + lily_g.HEAD.next->msg, + "CHECK failed: a == NULL\n a = \"hi\"\n NULL = \"(null)\"" + ) != 0) + return "incorrect message"; + + lily_msg_destroy(lily_g.HEAD.next); + return 0; +} + @@ -303,3 +330,40 @@ const char * test_REQUIRE_EQS() return "test continued to run!"; } } + +void f_test_REQUIRE_EQS_NULL() +{ + const char *a = "hi"; + const char *b = "bye"; + REQUIRE_EQS(a, NULL); + REQUIRE_EQS("hi hi"+3, a); +} +const char * test_REQUIRE_EQS_NULL() +{ + lily_g.HEAD.next = NULL; + lily_g.TAIL = &(lily_g.HEAD); + lily_g.failed = 0; + int test_failed = setjmp(lily_g.env); + + if (test_failed) { + if (lily_g.HEAD.next == NULL) + return "REQUIRE_EQS did not append any failure message"; + + if (lily_g.HEAD.next->next != NULL) + return "REQUIRE_EQS appended more than one message"; + + if (strcmp( + lily_g.HEAD.next->msg, + "REQUIRE failed: a == NULL\n a = \"hi\"\n NULL = \"(null)\"" + ) != 0) + return "incorrect message"; + + lily_msg_destroy(lily_g.HEAD.next); + return 0; + } + else { + f_test_REQUIRE_EQS_NULL(); + return "test continued to run!"; + } + +} diff --git a/tests/tests.h b/tests/tests.h index 4a02f66..448f14f 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -17,10 +17,12 @@ int validate_message(const char* received, const char* expected, X(test_CHECK_EQ) \ X(test_CHECK_EQF) \ X(test_CHECK_EQS) \ + X(test_CHECK_EQS_NULL) \ X(test_REQUIRE) \ X(test_REQUIRE_EQ) \ X(test_REQUIRE_EQF) \ X(test_REQUIRE_EQS) \ + X(test_REQUIRE_EQS_NULL) \ #define X(test) const char * test(); TESTS |