diff options
author | sanine <sanine.not@pm.me> | 2023-02-04 11:23:37 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-02-04 11:23:37 -0600 |
commit | 7c93fe6bc9f061484d28115e9fa1ec5f89ce5924 (patch) | |
tree | 847a46f89fcb9b2e53c84e39a3e153f4dbd7b010 /tests/assertions.c | |
parent | c7bf6fcccd50ded889b7cfb853af51e7c5f28d45 (diff) |
fix segfault when comparing NULL strings
Diffstat (limited to 'tests/assertions.c')
-rw-r--r-- | tests/assertions.c | 64 |
1 files changed, 64 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!"; + } + +} |