libmpm

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

commit 54428ebd5b0350025c3142ca2fcf06170e5ecc68
parent b55c6c6d902746f2ebfc11be903a2e8ca648979f
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 28 May 2017 15:54:04 +0200

Add(Tests): Add tests for packer_file, and fix some bugs here and there

Diffstat:
Minc/compile.h | 2+-
Msrc/compile.c | 3---
Msrc/packer_file.c | 10++++------
Mtests/packer/compilation/package.json | 5++++-
Atests/packer/compilation/srcs/configure | 2++
Atests/somefile | 0
Mtests/test_compile.c | 4++--
Mtests/test_packer.c | 26++++++++++++++++++++++++++
8 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/inc/compile.h b/inc/compile.h @@ -24,7 +24,7 @@ # define PATCH_CMD "patch -Ni" -# define CONFIGURE_CMD "configure" +# define CONFIGURE_CMD "./configure" typedef enum { INST_STATE_NONE = 0, diff --git a/src/compile.c b/src/compile.c @@ -28,7 +28,6 @@ compile_t *package_install_init(packer_t *ctx) { ret->package = ctx; ret->state = INST_STATE_NONE; - set_execute_flags(COMP_FLAGS_STDOUT); getcwd(ret->old_pwd, sizeof(ret->old_pwd)); if (chdir(ctx->out_dir) != 0) { @@ -120,8 +119,6 @@ bool configure_package(compile_t *ctx) { if (chdir(PACKER_SRC_DIR) == -1) goto end; - /* TODO: Conserve rights in archive */ - list_add(cmd, "sh", 3); list_add(cmd, CONFIGURE_CMD, sizeof(CONFIGURE_CMD) + 1); list_for_each(ctx->package->header->compilation->configure, tmp, opt) { diff --git a/src/packer_file.c b/src/packer_file.c @@ -177,7 +177,6 @@ bool get_file_information(packer_file_t *file) { bool packer_file_from_binary_to_disk(const char *content, off_t *ctr) { z_stream stream; packer_file_t file; - int ret; bool status = false; unsigned char out[_CHUNK_SIZE]; FILE *fd; @@ -213,9 +212,7 @@ bool packer_file_from_binary_to_disk(const char *content, off_t *ctr) { /* Ignore hash */ *ctr += crypto_hash_sha256_BYTES; - ret = inflateInit(&stream); - if (ret != Z_OK) - goto cleanup; + inflateInit(&stream); stream.avail_in = file.compressed_size; stream.next_in = (unsigned char *)content + *ctr; @@ -226,7 +223,7 @@ bool packer_file_from_binary_to_disk(const char *content, off_t *ctr) { { stream.avail_out = _CHUNK_SIZE; stream.next_out = out; - ret = inflate(&stream, Z_NO_FLUSH); + inflate(&stream, Z_NO_FLUSH); if (_CHUNK_SIZE - stream.avail_out > 0) fwrite(out, _CHUNK_SIZE - stream.avail_out, 1, fd); } @@ -239,7 +236,8 @@ bool packer_file_from_binary_to_disk(const char *content, off_t *ctr) { status = true; cleanup: - fclose(fd); + if (fd != NULL) + fclose(fd); free(file.fn); return status; } diff --git a/tests/packer/compilation/package.json b/tests/packer/compilation/package.json @@ -5,7 +5,10 @@ "description": "This is a description. Yeah I know, mind blowing." }, "compilation": { - "configure": null, + "configure": [ + {"something": "value"}, + "single-opt" + ], "make": "", "test": "", "install": "" diff --git a/tests/packer/compilation/srcs/configure b/tests/packer/compilation/srcs/configure @@ -0,0 +1,2 @@ +#!/bin/sh +echo "Configure !" diff --git a/tests/somefile b/tests/somefile diff --git a/tests/test_compile.c b/tests/test_compile.c @@ -6,8 +6,8 @@ TEST(init_compile) { packer_t *ptr; set_mkdir_fail(-1); - recursive_delete("/tmp/ncurses-6.0"); - ptr = packer_init_dir("packer/ncurses/"); + recursive_delete("/tmp/test-2.0"); + ptr = packer_init_dir("packer/compilation/"); TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened"); TEST_ASSERT(packer_create_archive(ptr, PACKAGE_OUTPUT_FN) == true, "An error happened"); diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -545,6 +545,30 @@ TEST(packer_extract_archive_2) { return TEST_SUCCESS; } +TEST(packer_file_from_binary_to_disk) { + off_t ctr = 0; + + set_strdup_fail(0); + TEST_ASSERT(packer_file_from_binary_to_disk("Content", &ctr) == false, "Error did not raise"); + + set_strdup_fail(1); + TEST_ASSERT(packer_file_from_binary_to_disk("/tmp/somedir/somefile", &ctr) == false, "Error did not raise"); + + return TEST_SUCCESS; +} + +TEST(get_file_information) { + packer_file_t *file; + + file = malloc(sizeof(file)); + file->fn = strdup(PACKAGE_OUTPUT_FN); + + set_stat_fail(0); + TEST_ASSERT(get_file_information(file) == false, "Error did not raise"); + + return TEST_SUCCESS; +} + TEST(packer_create_archive_cleanup) { recursive_delete("/tmp/test-2.0"); unlink(PACKAGE_OUTPUT_FN); @@ -597,5 +621,7 @@ void register_test_packer(void) { reg_test("packer", packer_extract_archive_1); reg_test("packer", packer_extract_archive_2); reg_test("packer", packer_read_archive_header); + reg_test("packer", packer_file_from_binary_to_disk); + reg_test("packer", get_file_information); reg_test("packer", packer_create_archive_cleanup); }