diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 8 | ||||
-rw-r--r-- | tests/include/testing.h | 15 | ||||
-rw-r--r-- | tests/test_artifactory.c | 5 | ||||
-rw-r--r-- | tests/test_conda.c | 6 | ||||
-rw-r--r-- | tests/test_environment.c | 4 | ||||
-rw-r--r-- | tests/test_template.c | 17 |
6 files changed, 36 insertions, 19 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bcc05ce..2b09e9e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,9 @@ find_program(BASH_PROGRAM bash) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/tests) set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests) -set(nix_gnu_cflags -Wno-format-truncation -Wno-error -Wno-unused-parameter -Wno-unused-result -Wno-discarded-qualifiers) -set(nix_clang_cflags -Wno-format-truncation -Wno-unused-parameter -Wno-unused-result -Wno-incompatible-pointer-types-discards-qualifiers) -set(win_msvc_cflags /Wall) +set(nix_gnu_cflags ${CMAKE_C_FLAGS} -Wno-format-truncation -Wno-error -Wno-unused-parameter -Wno-unused-result -Wno-discarded-qualifiers) +set(nix_clang_cflags ${CMAKE_C_FLAGS} -Wno-format-truncation -Wno-unused-parameter -Wno-unused-result -Wno-incompatible-pointer-types-discards-qualifiers) +set(win_msvc_cflags ${CMAKE_C_FLAGS} /Wall) file(GLOB source_files "test_*.c") file(GLOB rt_files "rt_*.sh") @@ -12,7 +12,7 @@ set(ext_pattern "(^.*/|\\.[^.]*$)") file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -if (BASH_PROGRAM AND BUILD_TESTING_RT) +if (BASH_PROGRAM AND TESTS_RT) foreach(rt_file ${rt_files}) file(REAL_PATH ${rt_file} rt_name) string(REGEX REPLACE ${ext_pattern} "" rt_name ${rt_file}) diff --git a/tests/include/testing.h b/tests/include/testing.h index 4c97bf2..ab24115 100644 --- a/tests/include/testing.h +++ b/tests/include/testing.h @@ -92,9 +92,10 @@ inline char *stasis_testing_read_ascii(const char *filename) { return NULL; } - char *result; + char *result = NULL; result = calloc(st.st_size + 1, sizeof(*result)); if (fread(result, sizeof(*result), st.st_size, fp) < 1) { + guard_free(result); perror(filename); fclose(fp); return NULL; @@ -211,7 +212,7 @@ inline void stasis_testing_teardown_workspace() { .lineno = __LINE__, \ .status = (COND), \ .msg_assertion = "ASSERT(" #COND ")", \ - .msg_reason = REASON } ); \ + .msg_reason = (REASON) } ); \ } while (0) #define STASIS_ASSERT_FATAL(COND, REASON) do { \ @@ -221,7 +222,7 @@ inline void stasis_testing_teardown_workspace() { .lineno = __LINE__, \ .status = (COND), \ .msg_assertion = "ASSERT FATAL (" #COND ")", \ - .msg_reason = REASON } \ + .msg_reason = (REASON) } \ ); \ if (stasis_test_results[stasis_test_results_i ? stasis_test_results_i - 1 : stasis_test_results_i].status == false) {\ exit(STASIS_TEST_SUITE_FATAL); \ @@ -236,7 +237,7 @@ inline void stasis_testing_teardown_workspace() { .status = true, \ .skip = (COND), \ .msg_assertion = "SKIP (" #COND ")", \ - .msg_reason = REASON } \ + .msg_reason = (REASON) } \ ); \ if (stasis_test_results[stasis_test_results_i ? stasis_test_results_i - 1 : stasis_test_results_i].skip == true) {\ return; \ @@ -244,9 +245,9 @@ inline void stasis_testing_teardown_workspace() { } while (0) #define STASIS_TEST_RUN(X) do { \ - for (size_t i = 0; i < sizeof(X) / sizeof(*X); i++) { \ - if (X[i]) { \ - X[i](); \ + for (size_t i = 0; i < sizeof(X) / sizeof(*(X)); i++) { \ + if ((X)[i]) { \ + (X)[i](); \ } \ } \ } while (0) diff --git a/tests/test_artifactory.c b/tests/test_artifactory.c index 4f41543..4af7eec 100644 --- a/tests/test_artifactory.c +++ b/tests/test_artifactory.c @@ -2,9 +2,7 @@ #include "artifactory.h" #include "delivery.h" -// Import private functions from core -extern int delivery_init_platform(struct Delivery *ctx); -extern int populate_delivery_cfg(struct Delivery *ctx, int render_mode); + struct JFRT_Auth gauth; struct JFRT_Auth gnoauth; @@ -78,6 +76,7 @@ int main(int argc, char *argv[]) { mkdir(ws, 0755); if (pushd(ws)) { SYSERROR("failed to change directory to %s", ws); + guard_free(basedir); STASIS_ASSERT_FATAL(true, "workspace creation failed"); } diff --git a/tests/test_conda.c b/tests/test_conda.c index 63a2781..81f593f 100644 --- a/tests/test_conda.c +++ b/tests/test_conda.c @@ -43,6 +43,8 @@ void test_conda_installation() { delivery_get_conda_installer_url(&ctx, install_url); delivery_get_conda_installer(&ctx, install_url); delivery_install_conda(ctx.conda.installer_path, ctx.storage.conda_install_prefix); + + guard_free(install_url); STASIS_ASSERT_FATAL(access(ctx.storage.conda_install_prefix, F_OK) == 0, "conda was not installed correctly"); STASIS_ASSERT_FATAL(conda_activate(ctx.storage.conda_install_prefix, "base") == 0, "unable to activate base environment"); STASIS_ASSERT_FATAL(conda_exec("info") == 0, "conda was not installed correctly"); @@ -155,7 +157,9 @@ void test_pip_index_provides() { void test_conda_get_active_environment() { conda_activate(ctx.storage.conda_install_prefix, "base"); - STASIS_ASSERT(strcmp(conda_get_active_environment(), "base") == 0, "base environment not active"); + char *active_env = conda_get_active_environment(); + STASIS_ASSERT(strcmp(active_env, "base") == 0, "base environment not active"); + guard_free(active_env); } void test_conda_provides() { diff --git a/tests/test_environment.c b/tests/test_environment.c index 134d061..43c3672 100644 --- a/tests/test_environment.c +++ b/tests/test_environment.c @@ -1,6 +1,6 @@ #include "testing.h" -extern char **environ; + void test_runtime_copy() { RuntimeEnv *env = runtime_copy(environ); @@ -27,7 +27,7 @@ void test_runtime_copy_empty() { void test_runtime() { RuntimeEnv *env = runtime_copy(environ); runtime_set(env, "CUSTOM_KEY", "Very custom"); - ssize_t idx = -1; + ssize_t idx; STASIS_ASSERT((idx = runtime_contains(env, "CUSTOM_KEY")) >= 0, "CUSTOM_KEY should exist in object"); STASIS_ASSERT(strcmp(strlist_item(env, idx), "CUSTOM_KEY=Very custom") == 0, "Incorrect index returned by runtime_contains"); diff --git a/tests/test_template.c b/tests/test_template.c index 79fce5e..596c2b7 100644 --- a/tests/test_template.c +++ b/tests/test_template.c @@ -47,9 +47,15 @@ void test_tpl_workflow() { tpl_reset(); tpl_register("hello_message", &data); - STASIS_ASSERT(strcmp(tpl_render("I said, \"{{ hello_message }}\""), "I said, \"Hello world!\"") == 0, "stored value in key is incorrect"); + char *result = NULL; + result = tpl_render("I said, \"{{ hello_message }}\""); + STASIS_ASSERT(strcmp(result, "I said, \"Hello world!\"") == 0, "stored value in key is incorrect"); + guard_free(result); + setenv("HELLO", "Hello environment!", 1); - STASIS_ASSERT(strcmp(tpl_render("{{ env:HELLO }}"), "Hello environment!") == 0, "environment variable content mismatch"); + result = tpl_render("{{ env:HELLO }}"); + STASIS_ASSERT(strcmp(result, "Hello environment!") == 0, "environment variable content mismatch"); + guard_free(result); unsetenv("HELLO"); guard_free(data); } @@ -87,18 +93,25 @@ void test_tpl_register_func() { char *result = NULL; result = tpl_render("{{ func:add(0,3) }}"); STASIS_ASSERT(result != NULL && strcmp(result, "3") == 0, "Answer was not 3"); + guard_free(result); result = tpl_render("{{ func:add(1,2) }}"); STASIS_ASSERT(result != NULL && strcmp(result, "3") == 0, "Answer was not 3"); + guard_free(result); result = tpl_render("{{ func:sub(6,3) }}"); STASIS_ASSERT(result != NULL && strcmp(result, "3") == 0, "Answer was not 3"); + guard_free(result); result = tpl_render("{{ func:sub(4,1) }}"); STASIS_ASSERT(result != NULL && strcmp(result, "3") == 0, "Answer was not 3"); + guard_free(result); result = tpl_render("{{ func:mul(1, 3) }}"); STASIS_ASSERT(result != NULL && strcmp(result, "3") == 0, "Answer was not 3"); + guard_free(result); result = tpl_render("{{ func:div(6,2) }}"); STASIS_ASSERT(result != NULL && strcmp(result, "3") == 0, "Answer was not 3"); + guard_free(result); result = tpl_render("{{ func:div(3,1) }}"); STASIS_ASSERT(result != NULL && strcmp(result, "3") == 0, "Answer was not 3"); + guard_free(result); } int main(int argc, char *argv[]) { |