diff --git a/src/types/ut_types/UtilsTests.cpp b/src/types/ut_types/UtilsTests.cpp index a7af2ce3750..88b8926f66b 100644 --- a/src/types/ut_types/UtilsTests.cpp +++ b/src/types/ut_types/UtilsTests.cpp @@ -27,8 +27,6 @@ class UtilsTests TEST_METHOD(TestStringToUint); TEST_METHOD(TestColorFromXTermColor); - TEST_METHOD(TestMangleWSLPaths); - void _VerifyXTermColorResult(const std::wstring_view wstr, DWORD colorValue); void _VerifyXTermColorInvalid(const std::wstring_view wstr); }; @@ -364,145 +362,3 @@ void UtilsTests::_VerifyXTermColorInvalid(const std::wstring_view wstr) std::optional color = ColorFromXTermColor(wstr); VERIFY_IS_FALSE(color.has_value()); } - -void UtilsTests::TestMangleWSLPaths() -{ - // Continue on failures - const WEX::TestExecution::DisableVerifyExceptions disableExceptionsScope; - - const auto startingDirectory{ L"SENTINEL" }; - // MUST MANGLE - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "SENTINEL" )", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl -d X)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "SENTINEL" -d X)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl -d X ~/bin/sh)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "SENTINEL" -d X ~/bin/sh)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl.exe)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl.exe" --cd "SENTINEL" )", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl.exe -d X)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl.exe" --cd "SENTINEL" -d X)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl.exe -d X ~/bin/sh)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl.exe" --cd "SENTINEL" -d X ~/bin/sh)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"("wsl")", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "SENTINEL" )", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"("wsl.exe")", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl.exe" --cd "SENTINEL" )", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"("wsl" -d X)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "SENTINEL" -d X)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"("wsl.exe" -d X)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl.exe" --cd "SENTINEL" -d X)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"("C:\Windows\system32\wsl.exe" -d X)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("C:\Windows\system32\wsl.exe" --cd "SENTINEL" -d X)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"("C:\windows\system32\wsl" -d X)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("C:\windows\system32\wsl" --cd "SENTINEL" -d X)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl ~/bin)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "SENTINEL" ~/bin)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - // MUST NOT MANGLE - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"("C:\wsl.exe" -d X)", startingDirectory); - VERIFY_ARE_EQUAL(LR"("C:\wsl.exe" -d X)", commandline); - VERIFY_ARE_EQUAL(startingDirectory, path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(C:\wsl.exe)", startingDirectory); - VERIFY_ARE_EQUAL(LR"(C:\wsl.exe)", commandline); - VERIFY_ARE_EQUAL(startingDirectory, path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl --cd C:\)", startingDirectory); - VERIFY_ARE_EQUAL(LR"(wsl --cd C:\)", commandline); - VERIFY_ARE_EQUAL(startingDirectory, path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl ~)", startingDirectory); - VERIFY_ARE_EQUAL(LR"(wsl ~)", commandline); - VERIFY_ARE_EQUAL(startingDirectory, path); - } - - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl ~ -d Ubuntu)", startingDirectory); - VERIFY_ARE_EQUAL(LR"(wsl ~ -d Ubuntu)", commandline); - VERIFY_ARE_EQUAL(startingDirectory, path); - } - - { - // Test for GH#11994 - make sure `//wsl$/` paths get mangled back to - // `\\wsl$\`, to workaround a potential bug in `wsl --cd` - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl -d Ubuntu)", LR"(//wsl$/Ubuntu/home/user)"); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "\\wsl$\Ubuntu\home\user" -d Ubuntu)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl -d Ubuntu)", LR"(\\wsl$\Ubuntu\home\user)"); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "\\wsl$\Ubuntu\home\user" -d Ubuntu)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - - { - // Same, but with `wsl.localhost` - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl -d Ubuntu)", LR"(//wsl.localhost/Ubuntu/home/user)"); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "\\wsl.localhost\Ubuntu\home\user" -d Ubuntu)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } - { - auto [commandline, path] = MangleStartingDirectoryForWSL(LR"(wsl -d Ubuntu)", LR"(\\wsl.localhost\Ubuntu\home\user)"); - VERIFY_ARE_EQUAL(LR"("wsl" --cd "\\wsl.localhost\Ubuntu\home\user" -d Ubuntu)", commandline); - VERIFY_ARE_EQUAL(L"", path); - } -}