libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit 0c4b170bee3a1797d9a289a4faa60d04835cf972
parent 7726c5f05c9406a188810f82ce6df4959e7ed75c
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  4 Jul 2017 11:22:38 +0200

Fix(Tests): Fix some tests for coverage, and some inline ifs for coverage

Diffstat:
Minc/packer.h | 10++++------
Mtests/test_compile.c | 18+++++++++++++++++-
2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/inc/packer.h b/inc/packer.h @@ -129,8 +129,7 @@ static inline void packer_header_package_init(packer_header_t *ptr) { * \param ptr Pointer to the header structure */ static inline void packer_header_package_free(packer_header_t *ptr) { - if (ptr == NULL) - return ; + if (ptr == NULL) return ; /* Coverage */ FREE(ptr->package.name); FREE(ptr->package.version); @@ -157,8 +156,7 @@ static inline void packer_header_comp_init(packer_header_t *ptr) { * \param ptr Pointer to the header structure */ static inline void packer_header_comp_free(packer_header_t *ptr) { - if (ptr == NULL) - return ; + if (ptr == NULL) return ; /* Coverage */ list_free(ptr->compilation.configure, &vector_string_free); list_free(ptr->compilation.env, &vector_string_free); @@ -183,8 +181,8 @@ static inline void packer_header_deps_init(packer_header_t *ptr) { * \param ptr Pointer to the header structure */ static inline void packer_header_deps_free(packer_header_t *ptr) { - if (ptr == NULL) - return ; + if (ptr == NULL) return ; /* Coverage */ + list_free(ptr->dependencies.list, NULL); ptr->dependencies.list = NULL; } diff --git a/tests/test_compile.c b/tests/test_compile.c @@ -220,13 +220,19 @@ TEST(full_install_2) { packer_t *ctx = NULL; compile_t *ptr = NULL; + set_malloc_fail(-1); chdir(g_old_pwd); + SET_ERR_STR(""); + SET_ERR(0); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); - set_malloc_fail(0); + TEST_ASSERT(ctx != NULL, "Cannot create archive"); + + set_malloc_fail(18); TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); package_install_cleanup(ptr); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); + chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(0); @@ -234,36 +240,46 @@ TEST(full_install_2) { package_install_cleanup(ptr); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); + chdir(g_old_pwd); + system("ls -la"); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(1); TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); package_install_cleanup(ptr); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); + chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(2); TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); package_install_cleanup(ptr); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); + chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(3); TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); package_install_cleanup(ptr); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); + chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(4); TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); package_install_cleanup(ptr); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); + chdir(g_old_pwd); ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_fork_fail(5); TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); package_install_cleanup(ptr); recursive_delete(DEFAULT_EXTRACT_DIR "/test-2.0"); + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); + TEST_ASSERT(install_archive(ctx, ptr) == false, "Error did not raise"); + package_install_cleanup(ptr); + return TEST_SUCCESS; }