lib

morphux C utility library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/lib

commit 3c38fb787a0c11adcff424d8afba7d98bce69c7a
parent 4e9bebc209bcf804e7d82c3af30e5be25821feb2
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed, 24 May 2017 13:42:42 +0200

Fix(Tests): Fix some wrong tests

Diffstat:
Mtests/test_args.c | 1+
Mtests/test_tests.c | 29++++++++++++++++++++++++-----
Mtests/test_util.c | 7++++---
3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/tests/test_args.c b/tests/test_args.c @@ -153,6 +153,7 @@ TEST(opts_unhandled_2) { DUP_ALL_OUTPUTS(fd); TEST_ASSERT(read_opt(sizeof(av), av, opt, &lst) == 0, "Not handling properly unknown arguments"); + exit(0); } else { WAIT_AND_CLOSE(pid, st, fd); TEST_ASSERT((WEXITSTATUS(st) == 1), "Wrong return"); diff --git a/tests/test_tests.c b/tests/test_tests.c @@ -212,17 +212,36 @@ TEST(test_fail_mkdir) { TEST(test_fail_fork) { pid_t ret; + int status; ret = fork(); - TEST_ASSERT(ret != -1, "Should have succeed"); if (ret == 0) - exit(0); + { + _exit(0); + } + else if (ret == -1) + { + TEST_ASSERT(ret != -1, "Should have succeed"); + } + else + { + waitpid(ret, &status, 0); + } set_fork_fail(1); ret = fork(); - TEST_ASSERT(ret != -1, "Should have succeed"); if (ret == 0) - exit(0); + { + _exit(0); + } + else if (ret == -1) + { + TEST_ASSERT(ret != -1, "Should have succeed"); + } + else + { + waitpid(ret, &status, 0); + } ret = fork(); TEST_ASSERT(ret == -1, "Should have failed"); @@ -252,5 +271,5 @@ void register_tests_tests(void) { reg_test("fake_functions", test_fail_strcat); reg_test("fake_functions", test_fail_cleanup); reg_test("fake_functions", test_fail_mkdir); - reg_test("fake_functions", test_fail_fork); + reg_test("fake_functions", test_fail_fork); } diff --git a/tests/test_util.c b/tests/test_util.c @@ -65,18 +65,19 @@ TEST(str_list_to_array) { }; for (size_t i = 0; i < sizeof(strings) / sizeof(strings[0]); i++) - list_add(head, strings[i], sizeof(strings[i])); + list_add(head, strings[i], strlen(strings[i]) + 1); set_malloc_fail(0); TEST_ASSERT(str_list_to_array(head) == NULL, "Malloc failed did not return an error"); set_strdup_fail(1); TEST_ASSERT(str_list_to_array(head) == NULL, "Failed copy did not return an error"); + tmp = str_list_to_array(head); TEST_ASSERT(tmp != NULL, "An error happened"); for (size_t i = 0; i < sizeof(strings) / sizeof(strings[0]); i++) { - TEST_ASSERT_FMT(strcmp(strings[i], tmp[i]) == 0, "Strings are different (%s/%s)", strings[i], tmp[i]); + TEST_ASSERT((strcmp(strings[i], tmp[i]) == 0), "Strings are different"); free(tmp[i]); } free(tmp); @@ -103,7 +104,7 @@ TEST(exec_list) { }; for (size_t i = 0; i < sizeof(strings) / sizeof(strings[0]); i++) - list_add(head, strings[i], sizeof(strings[i])); + list_add(head, strings[i], strlen(strings[i]) + 1); set_malloc_fail(0); TEST_ASSERT(exec_list(head) == 1, "Malloc failed did not return an error");