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>

Ben Hillis committed Dec 16, 2025 at 18:53 UTC c5fd6728473dc08e2bd0d99c5d64192f8e19fbfd
2 files changed +48
test/linux/unit_tests/wslpath.c
+14
@@ -163,6 +163,13 @@ Return Value:
163 LxtCheckResult(LxtCheckWslPathTranslation("C:/Foo/bar", "/mnt/c/Foo/bar", true));
164 LxtCheckResult(LxtCheckWslPathTranslation("foo", "foo", true));
165 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));
173
174 ErrorExit:
175 return Result;
@@ -241,6 +248,13 @@ Return Value:
248 LxtCheckResult(LxtCheckWslPathTranslation("/mnt/c/Users", "C:\\Users", false));
249 LxtCheckResult(LxtCheckWslPathTranslation("/mnt/c/Users/", "C:\\Users\\", false));
250 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));
258
259 ErrorExit:
260 return Result;
test/windows/SimpleTests.cpp
+34
@@ -262,5 +262,39 @@ class SimpleTests
262 std::transform(upperCaseGuidStringWide.begin(), upperCaseGuidStringWide.end(), upperCaseGuidStringWide.begin(), toupper);
263 VERIFY_ARE_EQUAL(upperCaseGuidStringWide, wsl::shared::string::GuidToString<wchar_t>(guid, wsl::shared::string::GuidToStringFlags::Uppercase));
264 }
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 + }
299 };
300 } // namespace SimpleTests
\ No newline at end of file