From 23cdd12bf40c8128b1c8df9127e5110af89ff460 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 10 Dec 2024 15:46:55 -0500 Subject: Keep test paths within created temporary directory Creates a subdirectory for testing ".." to stay within the created test directory for compatibility with sandboxing. --- test/test_filesystem.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'test/test_filesystem.c') diff --git a/test/test_filesystem.c b/test/test_filesystem.c index d57dc3f..40fc9a2 100644 --- a/test/test_filesystem.c +++ b/test/test_filesystem.c @@ -1,4 +1,4 @@ -// Copyright 2020-2023 David Robillard +// Copyright 2020-2024 David Robillard // SPDX-License-Identifier: ISC #undef NDEBUG @@ -64,6 +64,10 @@ test_canonical_path(void) char* const temp_dir = create_temp_dir("zixXXXXXX"); assert(temp_dir); + char* const sub_dir = zix_path_join(NULL, temp_dir, "sub"); + assert(!zix_create_directory(sub_dir)); + assert(zix_file_type(temp_dir) == ZIX_FILE_TYPE_DIRECTORY); + char* const file_path = zix_path_join(NULL, temp_dir, "zix_test_file"); assert(file_path); @@ -96,10 +100,10 @@ test_canonical_path(void) // Test dot segment resolution - char* const parent_dir_1 = zix_path_join(NULL, temp_dir, ".."); + char* const parent_dir_1 = zix_path_join(NULL, sub_dir, ".."); assert(parent_dir_1); - const ZixStringView parent_view = zix_path_parent_path(temp_dir); + const ZixStringView parent_view = zix_path_parent_path(sub_dir); char* const parent_dir_2 = zix_string_view_copy(NULL, parent_view); assert(parent_dir_2); assert(parent_dir_2[0]); @@ -120,6 +124,7 @@ test_canonical_path(void) // Clean everything up assert(!zix_remove(file_path)); + assert(!zix_remove(sub_dir)); assert(!zix_remove(temp_dir)); free(real_parent_dir_2); @@ -127,6 +132,7 @@ test_canonical_path(void) free(parent_dir_2); free(parent_dir_1); free(file_path); + free(sub_dir); free(temp_dir); } -- cgit v1.2.1