Skip to content

Commit c5fd672

Browse files
benhillisBen Hillis
andauthored
test: add more path translation variations (#13927)
* test: add more path translation variations * Update test/windows/SimpleTests.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
1 parent d060939 commit c5fd672

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

test/linux/unit_tests/wslpath.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ Return Value:
163163
LxtCheckResult(LxtCheckWslPathTranslation("C:/Foo/bar", "/mnt/c/Foo/bar", true));
164164
LxtCheckResult(LxtCheckWslPathTranslation("foo", "foo", true));
165165
LxtCheckResult(LxtCheckWslPathTranslation("foo\\", "foo/", true));
166+
LxtCheckResult(LxtCheckWslPathTranslation("C:\\Program Files\\Git", "/mnt/c/Program Files/Git", true));
167+
LxtCheckResult(LxtCheckWslPathTranslation("C:\\Program Files\\PowerShell\\7", "/mnt/c/Program Files/PowerShell/7", true));
168+
LxtCheckResult(LxtCheckWslPathTranslation("C:\\Program Files (x86)\\Common Files", "/mnt/c/Program Files (x86)/Common Files", true));
169+
LxtCheckResult(LxtCheckWslPathTranslation(
170+
"C:\\Users\\Test User\\AppData\\Local\\Programs\\Microsoft VS Code\\bin",
171+
"/mnt/c/Users/Test User/AppData/Local/Programs/Microsoft VS Code/bin",
172+
true));
166173

167174
ErrorExit:
168175
return Result;
@@ -241,6 +248,13 @@ Return Value:
241248
LxtCheckResult(LxtCheckWslPathTranslation("/mnt/c/Users", "C:\\Users", false));
242249
LxtCheckResult(LxtCheckWslPathTranslation("/mnt/c/Users/", "C:\\Users\\", false));
243250
LxtCheckResult(LxtCheckWslPathTranslation("/mnt/c/DOESNOTEXIST/", "C:\\DOESNOTEXIST\\", false));
251+
LxtCheckResult(LxtCheckWslPathTranslation("/mnt/c/Program Files/Git", "C:\\Program Files\\Git", false));
252+
LxtCheckResult(LxtCheckWslPathTranslation("/mnt/c/Program Files/PowerShell/7", "C:\\Program Files\\PowerShell\\7", false));
253+
LxtCheckResult(LxtCheckWslPathTranslation("/mnt/c/Program Files (x86)/Common Files", "C:\\Program Files (x86)\\Common Files", false));
254+
LxtCheckResult(LxtCheckWslPathTranslation(
255+
"/mnt/c/Users/Test User/AppData/Local/Programs/Microsoft VS Code/bin",
256+
"C:\\Users\\Test User\\AppData\\Local\\Programs\\Microsoft VS Code\\bin",
257+
false));
244258

245259
ErrorExit:
246260
return Result;

test/windows/SimpleTests.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,39 @@ class SimpleTests
262262
std::transform(upperCaseGuidStringWide.begin(), upperCaseGuidStringWide.end(), upperCaseGuidStringWide.begin(), toupper);
263263
VERIFY_ARE_EQUAL(upperCaseGuidStringWide, wsl::shared::string::GuidToString<wchar_t>(guid, wsl::shared::string::GuidToStringFlags::Uppercase));
264264
}
265+
266+
TEST_METHOD(WindowsPathWithSpaces)
267+
{
268+
wil::unique_environstrings_ptr originalPath;
269+
const DWORD pathLength = GetEnvironmentVariableW(L"PATH", nullptr, 0);
270+
if (pathLength > 0)
271+
{
272+
originalPath.reset(static_cast<PWSTR>(HeapAlloc(GetProcessHeap(), 0, pathLength * sizeof(wchar_t))));
273+
THROW_LAST_ERROR_IF_NULL(originalPath.get());
274+
THROW_LAST_ERROR_IF(GetEnvironmentVariableW(L"PATH", originalPath.get(), pathLength) == 0);
275+
}
276+
277+
auto cleanup = wil::scope_exit([&]() {
278+
if (originalPath)
279+
{
280+
THROW_LAST_ERROR_IF(!SetEnvironmentVariableW(L"PATH", originalPath.get()));
281+
}
282+
});
283+
284+
const wchar_t* testPath =
285+
L"C:\\Program Files\\Git\\cmd;"
286+
L"C:\\Program Files\\PowerShell\\7;"
287+
L"C:\\Program Files (x86)\\Common Files;"
288+
L"C:\\Users\\Test User\\AppData\\Local\\Programs\\Microsoft VS Code\\bin";
289+
290+
THROW_LAST_ERROR_IF(!SetEnvironmentVariableW(L"PATH", testPath));
291+
292+
auto [output, _] = LxsstuLaunchWslAndCaptureOutput(L"echo $PATH");
293+
294+
VERIFY_IS_TRUE(output.find(L"/mnt/c/Program Files/Git/cmd") != std::wstring::npos);
295+
VERIFY_IS_TRUE(output.find(L"/mnt/c/Program Files/PowerShell/7") != std::wstring::npos);
296+
VERIFY_IS_TRUE(output.find(L"/mnt/c/Program Files (x86)/Common Files") != std::wstring::npos);
297+
VERIFY_IS_TRUE(output.find(L"/mnt/c/Users/Test User/AppData/Local/Programs/Microsoft VS Code/bin") != std::wstring::npos);
298+
}
265299
};
266300
} // namespace SimpleTests

0 commit comments

Comments
 (0)