libmpm

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

commit f8c8f284dea470a77194541c0c214beeb9db4d63
parent 2352733d457fa14120f59339ca541fa93dfff3b1
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed, 12 Apr 2017 20:09:12 +0200

Add(Packer): Defaults for compilation section

Diffstat:
Minc/packer.h | 4++++
Msrc/packer.c | 17++++++++++++++---
Atests/packer/right_1/package.json | 24++++++++++++++++++++++++
Mtests/test_packer.c | 12+++++++++++-
4 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/inc/packer.h b/inc/packer.h @@ -27,6 +27,10 @@ # define PACKER_DEF_EXT ".mpx" # define PACKER_MPX_MAGIC "MPX" +# define PACKER_MAKE_DEF "make" +# define PACKER_TEST_DEF "test" +# define PACKER_INST_DEF "install" + typedef enum packer_type_e { PACKER_TYPE_DIRECTORY, PACKER_TYPE_ARCHIVE diff --git a/src/packer.c b/src/packer.c @@ -246,19 +246,30 @@ MPX_STATIC bool packer_read_config_comp(packer_t *ctx, struct json_object *obj) { if (json_object_get_type(tmp) != json_type_string) goto cleanup; - ctx->header->compilation->make = strdup(json_object_get_string(tmp)); + if (json_object_get_string_len(tmp) == 0) + ctx->header->compilation->make = strdup(PACKER_MAKE_DEF); + else + ctx->header->compilation->make = strdup(json_object_get_string(tmp)); } else if (strcmp(name, PACKER_CONF_COMP_TEST_TOKEN) == 0) { if (json_object_get_type(tmp) != json_type_string) goto cleanup; - ctx->header->compilation->test = strdup(json_object_get_string(tmp)); + + if (json_object_get_string_len(tmp) == 0) + ctx->header->compilation->test = strdup(PACKER_TEST_DEF); + else + ctx->header->compilation->test = strdup(json_object_get_string(tmp)); } else if (strcmp(name, PACKER_CONF_COMP_INST_TOKEN) == 0) { if (json_object_get_type(tmp) != json_type_string) goto cleanup; - ctx->header->compilation->install = strdup(json_object_get_string(tmp)); + + if (json_object_get_string_len(tmp) == 0) + ctx->header->compilation->test = strdup(PACKER_INST_DEF); + else + ctx->header->compilation->install = strdup(json_object_get_string(tmp)); } /* Wrong token */ else diff --git a/tests/packer/right_1/package.json b/tests/packer/right_1/package.json @@ -0,0 +1,24 @@ +{ + "package": { + "name": "test", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "make -j2 -something", + "test": "check-all", + "install": "not-posix" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -68,7 +68,6 @@ TEST(packer_wrong_main_1) { return TEST_SUCCESS; } - TEST(packer_right) { packer_t *ptr; @@ -78,6 +77,16 @@ TEST(packer_right) { return TEST_SUCCESS; } +TEST(packer_right_1) { + packer_t *ptr; + + ptr = packer_init_dir("packer/right_1/"); + TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened"); + packer_free(ptr); + return TEST_SUCCESS; +} + + TEST(packer_wrong_package_section_1) { packer_t *ptr; @@ -305,6 +314,7 @@ void register_test_packer(void) { reg_test("packer", packer_read_dir_no_configuration); reg_test("packer", packer_wrong_main_1); reg_test("packer", packer_right); + reg_test("packer", packer_right_1); reg_test("packer", packer_wrong_package_section_1); reg_test("packer", packer_wrong_package_section_2); reg_test("packer", packer_wrong_package_section_3);