diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_artifactory.c | 4 | ||||
-rw-r--r-- | tests/test_copy.c | 2 | ||||
-rw-r--r-- | tests/test_environment.c | 13 | ||||
-rw-r--r-- | tests/test_recipe.c | 1 | ||||
-rw-r--r-- | tests/test_system.c | 3 | ||||
-rw-r--r-- | tests/test_utils.c | 6 |
6 files changed, 24 insertions, 5 deletions
diff --git a/tests/test_artifactory.c b/tests/test_artifactory.c index 2c732fa..4f41543 100644 --- a/tests/test_artifactory.c +++ b/tests/test_artifactory.c @@ -73,7 +73,7 @@ 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)) { @@ -107,6 +107,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 +119,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_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..134d061 100644 --- a/tests/test_environment.c +++ b/tests/test_environment.c @@ -31,7 +31,7 @@ void test_runtime() { 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_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"); } |