From d7c9abad6dd09f92605f88394ea1d2cfd59d2d6d Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Mon, 6 Apr 2026 17:31:15 -0500 Subject: [PATCH 1/3] Dynamically select drive for test --- src/AppInstallerCLITests/Filesystem.cpp | 40 ++++++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/AppInstallerCLITests/Filesystem.cpp b/src/AppInstallerCLITests/Filesystem.cpp index ae032b4ed5..9bb46dc956 100644 --- a/src/AppInstallerCLITests/Filesystem.cpp +++ b/src/AppInstallerCLITests/Filesystem.cpp @@ -67,12 +67,33 @@ TEST_CASE("VerifyIsSameVolume", "[filesystem]") std::filesystem::path path3 = L"localPath\\test\\folder"; std::filesystem::path path4 = L"test\\folder"; std::filesystem::path path5 = L"D:\\test\\folder"; - std::filesystem::path path6 = L"F:\\test\\folder"; + // path 6 dynamically generated below to be a non-existent drive letter std::filesystem::path path7 = L"d:\\randomFolder"; - std::filesystem::path path8 = L"f:\\randomFolder"; + // path 8 dynamically generated below to be a non-existent drive letter with different case than path 6 std::filesystem::path path9 = L"a"; std::filesystem::path path10 = L"b"; + // Dynamically find a drive letter that is not mounted on this machine so that + // GetVolumePathNameW will fail for it, making IsSameVolume return false. + // This avoids environment-dependent failures when drive letters like F:\ are mounted. + wchar_t nonExistentDriveLetter = L'\0'; + const DWORD driveMask = GetLogicalDrives(); + for (wchar_t c = L'Z'; c >= L'A'; c--) + { + if (!(driveMask & (1 << (c - L'A')))) + { + nonExistentDriveLetter = c; + break; + } + } + + std::filesystem::path path6, path8; + if (nonExistentDriveLetter != L'\0') + { + path6 = std::wstring(1, nonExistentDriveLetter) + L":\\test\\folder"; + path8 = std::wstring(1, towlower(nonExistentDriveLetter)) + L":\\randomFolder"; + } + REQUIRE(IsSameVolume(path1, path2)); if (IsSameVolume(path5, path5)) { @@ -82,13 +103,16 @@ TEST_CASE("VerifyIsSameVolume", "[filesystem]") REQUIRE(IsSameVolume(path9, path10)); REQUIRE_FALSE(IsSameVolume(path1, path5)); - REQUIRE_FALSE(IsSameVolume(path1, path6)); REQUIRE_FALSE(IsSameVolume(path2, path5)); - REQUIRE_FALSE(IsSameVolume(path2, path6)); - REQUIRE_FALSE(IsSameVolume(path3, path6)); - REQUIRE_FALSE(IsSameVolume(path5, path6)); - REQUIRE_FALSE(IsSameVolume(path4, path6)); - REQUIRE_FALSE(IsSameVolume(path6, path8)); + if (nonExistentDriveLetter != L'\0') + { + REQUIRE_FALSE(IsSameVolume(path1, path6)); + REQUIRE_FALSE(IsSameVolume(path2, path6)); + REQUIRE_FALSE(IsSameVolume(path3, path6)); + REQUIRE_FALSE(IsSameVolume(path5, path6)); + REQUIRE_FALSE(IsSameVolume(path4, path6)); + REQUIRE_FALSE(IsSameVolume(path6, path8)); + } } TEST_CASE("ReplaceCommonPathPrefix", "[filesystem]") From 07b3ee9244dd24889c701e769a50b17ccb2ef1b7 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Mon, 6 Apr 2026 17:39:11 -0500 Subject: [PATCH 2/3] Spelling --- src/AppInstallerCLITests/Filesystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AppInstallerCLITests/Filesystem.cpp b/src/AppInstallerCLITests/Filesystem.cpp index 9bb46dc956..d5e720994e 100644 --- a/src/AppInstallerCLITests/Filesystem.cpp +++ b/src/AppInstallerCLITests/Filesystem.cpp @@ -67,9 +67,9 @@ TEST_CASE("VerifyIsSameVolume", "[filesystem]") std::filesystem::path path3 = L"localPath\\test\\folder"; std::filesystem::path path4 = L"test\\folder"; std::filesystem::path path5 = L"D:\\test\\folder"; - // path 6 dynamically generated below to be a non-existent drive letter + // path 6 dynamically generated below to be a nonexistent drive letter std::filesystem::path path7 = L"d:\\randomFolder"; - // path 8 dynamically generated below to be a non-existent drive letter with different case than path 6 + // path 8 dynamically generated below to be a nonexistent drive letter with different case than path 6 std::filesystem::path path9 = L"a"; std::filesystem::path path10 = L"b"; From 8ce6c18dc42c812c5e6b0fbd452aebfcd4ce6480 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Mon, 6 Apr 2026 17:41:31 -0500 Subject: [PATCH 3/3] Fix order --- src/AppInstallerCLITests/Filesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppInstallerCLITests/Filesystem.cpp b/src/AppInstallerCLITests/Filesystem.cpp index d5e720994e..75a9bb593a 100644 --- a/src/AppInstallerCLITests/Filesystem.cpp +++ b/src/AppInstallerCLITests/Filesystem.cpp @@ -109,8 +109,8 @@ TEST_CASE("VerifyIsSameVolume", "[filesystem]") REQUIRE_FALSE(IsSameVolume(path1, path6)); REQUIRE_FALSE(IsSameVolume(path2, path6)); REQUIRE_FALSE(IsSameVolume(path3, path6)); - REQUIRE_FALSE(IsSameVolume(path5, path6)); REQUIRE_FALSE(IsSameVolume(path4, path6)); + REQUIRE_FALSE(IsSameVolume(path5, path6)); REQUIRE_FALSE(IsSameVolume(path6, path8)); } }