aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/cmake.yml6
-rw-r--r--lib/cleanpath.c10
-rw-r--r--tests/CMakeLists.txt25
3 files changed, 34 insertions, 7 deletions
diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml
index abb6236..394d587 100644
--- a/.github/workflows/cmake.yml
+++ b/.github/workflows/cmake.yml
@@ -7,8 +7,8 @@ on:
branches: [ master ]
env:
- # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
- BUILD_TYPE: Release
+ TESTVAR_NIX: "/usr/local/bin:/usr/bin:/bin"
+ TESTVAR_WIN: "C:\\usr\\local\\bin;C:\\usr\\bin;C:\\bin"
jobs:
tests:
@@ -54,5 +54,5 @@ jobs:
- name: Test
working-directory: ${{ github.workspace }}/build
- run: ctest -C ${{ matrix.build_type }}
+ run: ctest -V -C ${{ matrix.build_type }}
diff --git a/lib/cleanpath.c b/lib/cleanpath.c
index fdb615d..c3a7e81 100644
--- a/lib/cleanpath.c
+++ b/lib/cleanpath.c
@@ -103,6 +103,7 @@ void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern
*/
char *cleanpath_read(struct CleanPath *path) {
char *result;
+ size_t result_len;
result = calloc(path->data_len, sizeof(char));
if (result == NULL) {
@@ -115,11 +116,12 @@ char *cleanpath_read(struct CleanPath *path) {
continue;
}
strcat(result, path->part[i]);
+ strcat(result, path->sep);
+ }
- // Do not append path separator on final element
- if (path->part[i + 1] != NULL && *path->part[i + 1] != '\0') {
- strcat(result, path->sep);
- }
+ result_len = strlen(result);
+ if (result_len) {
+ result[result_len - 1] = '\0';
}
cleanpath_read__failure:
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4f23ecf..7a56301 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -20,3 +20,28 @@ foreach(file ${files})
PROPERTIES
TIMEOUT 120)
endforeach()
+
+# For these tests to pass TESTVAR_WIN (Windows) and TESTVAR_NIX (Unix-like)
+# must be set in the runtime environment prior to execution. For some
+# reason environment variables defined here are not passed on to child
+# processes.
+set(TEST_SETUP -E TESTVAR)
+
+if(${CMAKE_SYSTEM_NAME} EQUAL WINDOWS)
+ set(TEST_SETUP ${TEST_SETUP}_WIN)
+ set(exec ${CMAKE_BINARY_DIR}/cleanpath.exe)
+
+ add_test(cmd_arg_exact ${exec} --exact ${TEST_SETUP} C:\\usr\\bin)
+ add_test(cmd_arg_loose ${exec} --loose ${TEST_SETUP} C:\\usr\\bin)
+else()
+ set(TEST_SETUP ${TEST_SETUP}_NIX)
+ set(exec ${CMAKE_BINARY_DIR}/cleanpath)
+
+ add_test(cmd_arg_exact ${exec} ${TEST_SETUP} --exact /usr/bin)
+ add_test(cmd_arg_loose ${exec} ${TEST_SETUP} --loose /usr/bin)
+ add_test(cmd_arg_regex ${exec} ${TEST_SETUP} --regex /usr/bin)
+endif()
+
+add_test(cmd_arg_help ${exec} --help)
+add_test(cmd_arg_version ${exec} --version)
+add_test(cmd_arg_list ${exec} --list)