diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 8 | ||||
-rw-r--r-- | tests/data/gbo.ini | 1 | ||||
-rw-r--r-- | tests/data/gbo.yml | 1 | ||||
-rw-r--r-- | tests/include/testing.h | 15 | ||||
-rw-r--r-- | tests/test_artifactory.c | 9 | ||||
-rw-r--r-- | tests/test_conda.c | 6 | ||||
-rw-r--r-- | tests/test_copy.c | 2 | ||||
-rw-r--r-- | tests/test_environment.c | 17 | ||||
-rw-r--r-- | tests/test_recipe.c | 1 | ||||
-rw-r--r-- | tests/test_system.c | 3 | ||||
-rw-r--r-- | tests/test_template.c | 17 | ||||
-rw-r--r-- | tests/test_utils.c | 6 |
12 files changed, 62 insertions, 24 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/data/gbo.ini b/tests/data/gbo.ini index 609b8f3..3ee6481 100644 --- a/tests/data/gbo.ini +++ b/tests/data/gbo.ini @@ -17,6 +17,7 @@ installer_baseurl = https://github.com/conda-forge/miniforge/releases/download/{ ;conda_packages = pip_packages = firewatch==0.0.4 + gwcs==0.22.1 tweakwcs==0.8.8 diff --git a/tests/data/gbo.yml b/tests/data/gbo.yml index 3ab97a7..929f351 100644 --- a/tests/data/gbo.yml +++ b/tests/data/gbo.yml @@ -6,4 +6,5 @@ dependencies: - setuptools - pip: - firewatch==0.0.3 + - gwcs==0.22.1 - tweakwcs==0.8.7
\ No newline at end of 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 2c732fa..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; @@ -73,11 +71,12 @@ int main(int argc, char *argv[]) { memset(&gnoauth, 0, sizeof(gnoauth)); memset(&ctx, 0, sizeof(ctx)); - const char *basedir = realpath(".", NULL); + char *basedir = realpath(".", NULL); const char *ws = "workspace"; mkdir(ws, 0755); if (pushd(ws)) { SYSERROR("failed to change directory to %s", ws); + guard_free(basedir); STASIS_ASSERT_FATAL(true, "workspace creation failed"); } @@ -107,6 +106,7 @@ int main(int argc, char *argv[]) { ctx._stasis_ini_fp.cfg = ini_open(cfg_path); if (!ctx._stasis_ini_fp.cfg) { SYSERROR("%s: configuration is invalid", cfg_path); + guard_free(basedir); return STASIS_TEST_SUITE_SKIP; } delivery_init_platform(&ctx); @@ -118,6 +118,7 @@ int main(int argc, char *argv[]) { SYSERROR("%s", "Not configured to test Artifactory. Skipping."); return STASIS_TEST_SUITE_SKIP; } + guard_free(basedir); STASIS_TEST_FUNC *tests[] = { test_jfrog_cli_rt_ping, 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_copy.c b/tests/test_copy.c index 14310e4..b37b1d3 100644 --- a/tests/test_copy.c +++ b/tests/test_copy.c @@ -18,7 +18,7 @@ void test_copy() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { struct stat st_a, st_b; struct testcase *test = &tc[i]; - char *mock_data = malloc(test->expect_size * sizeof(*mock_data)); + char *mock_data = malloc(test->expect_size + 1 * sizeof(*mock_data)); memset(mock_data, 'A', test->expect_size); mock_data[test->expect_size] = '\0'; stasis_testing_write_ascii(test->in_file, mock_data); diff --git a/tests/test_environment.c b/tests/test_environment.c index 3418800..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,11 +27,11 @@ 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"); - const char *custom_value = runtime_get(env, "CUSTOM_KEY"); + char *custom_value = runtime_get(env, "CUSTOM_KEY"); STASIS_ASSERT_FATAL(custom_value != NULL, "CUSTOM_KEY should not be NULL"); STASIS_ASSERT(strcmp(custom_value, "Very custom") == 0, "CUSTOM_KEY has incorrect data"); STASIS_ASSERT(strstr_array(environ, "CUSTOM_KEY") == NULL, "CUSTOM_KEY should not exist in the global environment"); @@ -44,6 +44,7 @@ void test_runtime() { STASIS_ASSERT(setenv("CUSTOM_KEY", "modified", 1) == 0, "modifying global CUSTOM_KEY failed"); global_custom_value = getenv("CUSTOM_KEY"); STASIS_ASSERT(strcmp(global_custom_value, custom_value) != 0, "local and global CUSTOM_KEY variable are supposed to be different"); + guard_free(custom_value); runtime_replace(&env, environ); runtime_apply(env); @@ -53,13 +54,19 @@ void test_runtime() { STASIS_ASSERT_FATAL(custom_value != NULL, "CUSTOM_KEY must exist in local environment after calling runtime_replace()"); STASIS_ASSERT_FATAL(global_custom_value != NULL, "CUSTOM_KEY must exist in global environment after calling runtime_replace()"); STASIS_ASSERT(strcmp(global_custom_value, custom_value) == 0, "local and global CUSTOM_KEY variable are supposed to be identical"); + guard_free(custom_value); char output_truth[BUFSIZ] = {0}; - sprintf(output_truth, "Your PATH is '%s'.", runtime_get(env, "PATH")); - const char *output_expanded = runtime_expand_var(env, "Your PATH is '${PATH}'."); + char *your_path = runtime_get(env, "PATH"); + sprintf(output_truth, "Your PATH is '%s'.", your_path); + guard_free(your_path); + + char *output_expanded = runtime_expand_var(env, "Your PATH is '${PATH}'."); STASIS_ASSERT(output_expanded != NULL, "expansion of PATH should not fail"); STASIS_ASSERT(strcmp(output_expanded, output_truth) == 0, "the expansion, and the expected result should be identical"); + guard_free(output_expanded); + guard_runtime_free(env); // TODO: runtime_export() // requires dumping stdout to a file and comparing it with the current environment array } diff --git a/tests/test_recipe.c b/tests/test_recipe.c index 531b3b4..fc7cc78 100644 --- a/tests/test_recipe.c +++ b/tests/test_recipe.c @@ -85,6 +85,7 @@ void test_recipe_clone() { // Verify the result path does not exist STASIS_ASSERT(result_path && access(result_path, F_OK) != 0, "result path should not exist"); } + guard_free(result_path); } } diff --git a/tests/test_system.c b/tests/test_system.c index 0f6bfb7..2271e13 100644 --- a/tests/test_system.c +++ b/tests/test_system.c @@ -18,6 +18,7 @@ void test_shell_output_null_args() { result = shell_output(NULL, &status); STASIS_ASSERT(strcmp(result, "") == 0, "no output expected"); STASIS_ASSERT(status != 0, "expected a non-zero exit code due to null argument string"); + guard_free(result); } void test_shell_output_non_zero_exit() { @@ -26,6 +27,7 @@ void test_shell_output_non_zero_exit() { result = shell_output("HELLO1234 WORLD", &status); STASIS_ASSERT(strcmp(result, "") == 0, "no output expected"); STASIS_ASSERT(status != 0, "expected a non-zero exit code due to intentional error"); + guard_free(result); } void test_shell_output() { @@ -34,6 +36,7 @@ void test_shell_output() { result = shell_output("echo HELLO WORLD", &status); STASIS_ASSERT(strcmp(result, "HELLO WORLD\n") == 0, "output message was incorrect"); STASIS_ASSERT(status == 0, "expected zero exit code"); + guard_free(result); } void test_shell_safe() { 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[]) { diff --git a/tests/test_utils.c b/tests/test_utils.c index 9090b05..8f0a667 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -46,6 +46,7 @@ void test_redact_sensitive() { char output[100] = {0}; redact_sensitive(to_redact, sizeof(to_redact) / sizeof(*to_redact), input, output, sizeof(output) - 1); STASIS_ASSERT(strcmp(output, expected[i]) == 0, "incorrect redaction"); + guard_free(input); } } @@ -118,6 +119,7 @@ void test_path_store() { STASIS_ASSERT(dest != NULL, "dest should not be NULL"); STASIS_ASSERT(dest && (access(dest, F_OK) == 0), "destination path was not created"); rmtree(dest); + guard_free(dest); } void test_isempty_dir() { @@ -226,6 +228,7 @@ void test_git_clone_and_describe() { char *taginfo_bad = git_describe("abc1234_not_here_or_there"); STASIS_ASSERT(taginfo_bad == NULL, "a repository that shouldn't exist... exists and has a tag."); chdir(cwd); + guard_free(cwd); } void test_touch() { @@ -414,9 +417,11 @@ void test_pushd_popd() { // we should be inside the test directory, not the starting directory STASIS_ASSERT(strcmp(cwd_workspace, cwd) != 0, ""); STASIS_ASSERT(popd() == 0, "return from directory failed"); + guard_free(cwd); char *cwd_after_popd = getcwd(NULL, PATH_MAX); STASIS_ASSERT(strcmp(cwd_workspace, cwd_after_popd) == 0, "should be the path where we started"); + guard_free(cwd_after_popd); } void test_pushd_popd_suggested_workflow() { @@ -436,6 +441,7 @@ void test_pushd_popd_suggested_workflow() { // cwd should be our starting directory char *cwd = getcwd(NULL, PATH_MAX); STASIS_ASSERT(strcmp(cwd_workspace, cwd) == 0, NULL); + guard_free(cwd); } else { STASIS_ASSERT(false, "mkdir function failed"); } |