From 347677c3330ece8496b9cd242fd7e4292c2260ae Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 24 Apr 2026 15:55:21 -0400 Subject: NUL terminate after copy --- tests/test_relocation.c | 1 + tests/test_str.c | 3 +++ tests/test_utils.c | 1 + 3 files changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/test_relocation.c b/tests/test_relocation.c index 69142dc..3454a69 100644 --- a/tests/test_relocation.c +++ b/tests/test_relocation.c @@ -15,6 +15,7 @@ void test_replace_text() { const char *expected = targets[i + 1]; char input[BUFSIZ] = {0}; strncpy(input, test_string, sizeof(input) - 1); + input[sizeof(input) - 1] = '\0'; printf("input: %s\n", input); printf("target: %s\n", target); diff --git a/tests/test_str.c b/tests/test_str.c index aac5d71..09d8809 100644 --- a/tests/test_str.c +++ b/tests/test_str.c @@ -38,6 +38,7 @@ void test_tolower_s() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char input[100] = {0}; strncpy(input, tc[i].data, sizeof(input) - 1); + input[sizeof(input) - 1] = '\0'; tolower_s(input); STASIS_ASSERT(strcmp(input, tc[i].expected) == 0, "unexpected result"); } @@ -318,6 +319,7 @@ void test_lstrip() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *buf = calloc(255, sizeof(*buf)); strncpy(buf, tc[i].data, 254); + buf[254] = '\0'; char *result = lstrip(buf); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-left"); guard_free(buf); @@ -342,6 +344,7 @@ void test_strip() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *buf = calloc(255, sizeof(*buf)); strncpy(buf, tc[i].data, 254); + buf[254] = '\0'; char *result = strip(buf); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-right"); guard_free(buf); diff --git a/tests/test_utils.c b/tests/test_utils.c index a5faf5c..4f89509 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -312,6 +312,7 @@ void test_path_dirname() { const char *expected = data[i + 1]; char tmp[PATH_MAX] = {0}; strncpy(tmp, input, sizeof(tmp) - 1); + tmp[sizeof(tmp) - 1] = '\0'; char *result = path_dirname(tmp); STASIS_ASSERT(strcmp(expected, result) == 0, NULL); -- cgit From c4116b2bf33fa3cb6cf976a38e897af8a9dffbd8 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 24 Apr 2026 23:38:06 -0400 Subject: Fix assertion. count should be greater than zero. --- tests/test_wheel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_wheel.c b/tests/test_wheel.c index 531e4b7..a1623e8 100644 --- a/tests/test_wheel.c +++ b/tests/test_wheel.c @@ -41,13 +41,13 @@ static void test_wheel_package() { const struct WheelValue dist_version = wheel_get_value_by_name(wheel, WHEEL_FROM_DIST, "Wheel-Version"); STASIS_ASSERT(dist_version.type == WHEELVAL_STR, "Wheel dist version value must be a string"); STASIS_ASSERT_FATAL(dist_version.data != NULL, "Wheel dist version value must not be NULL"); - STASIS_ASSERT(dist_version.count, "Wheel value must be populated"); + STASIS_ASSERT(dist_version.count != 0, "Wheel value must be populated"); // Get data from METADATA const struct WheelValue meta_name = wheel_get_value_by_name(wheel, WHEEL_FROM_METADATA, "Metadata-Version"); STASIS_ASSERT(meta_name.type == WHEELVAL_STR, "Wheel metadata version value must be a string"); STASIS_ASSERT_FATAL(meta_name.data != NULL, "Wheel metadata version value must not be NULL"); - STASIS_ASSERT(meta_name.count, "Wheel metadata version value must be populated"); + STASIS_ASSERT(meta_name.count != 0, "Wheel metadata version value must be populated"); wheel_package_free(&wheel); STASIS_ASSERT(wheel == NULL, "wheel struct should be NULL after free"); -- cgit From 499bbc2e33172dd19f130dc33ced217e51bc48ed Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 25 Apr 2026 18:46:51 -0400 Subject: Restrict tests from finding STASIS's .git directory --- tests/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dd68231..26c4250 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,7 +17,10 @@ if (BASH_PROGRAM AND TESTS_RT) file(REAL_PATH ${rt_file} rt_name) string(REGEX REPLACE ${ext_pattern} "" rt_name ${rt_file}) add_test (${rt_name} ${BASH_PROGRAM} ${rt_file}) - endforeach() + set_property(TEST ${rt_name} + PROPERTY ENVIRONMENT "GIT_CEILING_DIRECTORIES=${CMAKE_BINARY_DIR}" + ) +endforeach() endif() foreach(source_file ${source_files}) @@ -49,5 +52,7 @@ foreach(source_file ${source_files}) PROPERTIES SKIP_RETURN_CODE 127) set_property(TEST ${test_executable} - PROPERTY ENVIRONMENT "STASIS_SYSCONFDIR=${CMAKE_SOURCE_DIR}") + PROPERTY ENVIRONMENT "STASIS_SYSCONFDIR=${CMAKE_SOURCE_DIR}" + PROPERTY ENVIRONMENT "GIT_CEILING_DIRECTORIES=${CMAKE_BINARY_DIR}" + ) endforeach() -- cgit From 2596f879f9cc8a6eab4fd2991d9639ef22753b62 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sun, 26 Apr 2026 01:15:38 -0400 Subject: test_fix_tox_conf: Check lines and result --- tests/test_utils.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/test_utils.c b/tests/test_utils.c index 4f89509..fd398e2 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -71,6 +71,8 @@ void test_fix_tox_conf() { } char **lines = file_readlines(result, 0, 0, NULL); + STASIS_ASSERT_FATAL(lines != NULL, "lines array should not be NULL"); + STASIS_ASSERT_FATAL(result != NULL, "result should not be NULL"); STASIS_ASSERT(strstr_array(lines, expected) != NULL, "{posargs} not found in result"); guard_array_free(lines); -- cgit From 421903a1379353f07a10deb335ed3c0361233064 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sun, 26 Apr 2026 01:49:02 -0400 Subject: Fix file handle leaks --- tests/test_relocation.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/test_relocation.c b/tests/test_relocation.c index 3454a69..4a02e01 100644 --- a/tests/test_relocation.c +++ b/tests/test_relocation.c @@ -40,6 +40,7 @@ void test_file_replace_text() { STASIS_ASSERT(file_replace_text(filename, target, "^^^", 0) == 0, "string replacement failed"); } else { STASIS_ASSERT(false, "failed to open file for writing"); + fclose(fp); return; } @@ -48,8 +49,10 @@ void test_file_replace_text() { if (fp) { fread(input, sizeof(*input), sizeof(input), fp); STASIS_ASSERT(strcmp(input, expected) == 0, "unexpected replacement"); + fclose(fp); } else { STASIS_ASSERT(false, "failed to open file for reading"); + fclose(fp); return; } } -- cgit From 4d3edd67c28116bdd337f5b3b2f456329a269bdb Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 27 Apr 2026 01:55:14 -0400 Subject: pkg_index_provides: Add logdir argument * mkdirs() the logdir --- tests/test_conda.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_conda.c b/tests/test_conda.c index 9f0e718..242d398 100644 --- a/tests/test_conda.c +++ b/tests/test_conda.c @@ -143,7 +143,7 @@ void test_pip_index_provides() { }; for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { struct testcase *test = &tc[i]; - int result = pkg_index_provides(PKG_USE_PIP, test->pindex, test->name); + int result = pkg_index_provides(PKG_USE_PIP, test->pindex, test->name, "."); STASIS_ASSERT(result == test->expected, "Unexpected result"); if (PKG_INDEX_PROVIDES_FAILED(result)) { fprintf(stderr, "error: %s\n", pkg_index_provides_strerror(result)); @@ -175,7 +175,7 @@ void test_conda_provides() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { struct testcase *test = &tc[i]; - int result = pkg_index_provides(PKG_USE_CONDA, NULL, test->name); + int result = pkg_index_provides(PKG_USE_CONDA, NULL, test->name, "."); printf("%s returned %d, expecting %d\n", test->name, result, test->expected); STASIS_ASSERT(result == test->expected, "Unexpected result"); } -- cgit From 11bc498b5bca18662a582a163d3e9aaed1a17b79 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 27 Apr 2026 09:20:06 -0400 Subject: Add download_dir member to MicroMambaInfo struct. * TMPDIR and hardcoded path is too unpredictable. --- tests/test_conda.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test_conda.c b/tests/test_conda.c index 242d398..e32c9f2 100644 --- a/tests/test_conda.c +++ b/tests/test_conda.c @@ -18,10 +18,10 @@ void test_micromamba() { int result; }; struct testcase tc[] = { - {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "info", .result = 0}, - {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "env list", .result = 0}, - {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "run python3 -V", .result = 0}, - {.mminfo = {.micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "no_such_option", .result = 109}, + {.mminfo = {.download_dir = cwd_workspace, .micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "info", .result = 0}, + {.mminfo = {.download_dir = cwd_workspace, .micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "env list", .result = 0}, + {.mminfo = {.download_dir = cwd_workspace, .micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "run python3 -V", .result = 0}, + {.mminfo = {.download_dir = cwd_workspace, .micromamba_prefix = mm_prefix, .conda_prefix = c_prefix}, .cmd = "no_such_option", .result = 109}, }; for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { @@ -31,7 +31,7 @@ void test_micromamba() { result = result >> 8; } STASIS_ASSERT(result == item->result, "unexpected exit value"); - SYSERROR("micromamba command: '%s' (returned: %d)", item->cmd, result); + SYSDEBUG("micromamba command: '%s' (returned: %d)", item->cmd, result); } } -- cgit