aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2026-04-28 11:45:10 -0400
committerGitHub <noreply@github.com>2026-04-28 11:45:10 -0400
commit10f13b36560c5112554c54d8958081b7aa518050 (patch)
treebd27866c4352de38ebc5b13f8208768d576ae904 /tests
parent017bc273aedf3f20512beeb78a2f513913e56305 (diff)
parentd761cc976a8d645e61d23f6e43dcfec1a7fdb061 (diff)
downloadstasis-10f13b36560c5112554c54d8958081b7aa518050.tar.gz
Merge pull request #137 from jhunkeler/bughunt-1001
Bug Hunt 0x1001
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt9
-rw-r--r--tests/test_conda.c14
-rw-r--r--tests/test_relocation.c4
-rw-r--r--tests/test_str.c3
-rw-r--r--tests/test_utils.c3
-rw-r--r--tests/test_wheel.c4
6 files changed, 26 insertions, 11 deletions
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()
diff --git a/tests/test_conda.c b/tests/test_conda.c
index 9f0e718..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);
}
}
@@ -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");
}
diff --git a/tests/test_relocation.c b/tests/test_relocation.c
index 69142dc..4a02e01 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);
@@ -39,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;
}
@@ -47,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;
}
}
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..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);
@@ -312,6 +314,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);
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");