diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -542,15 +542,17 @@ Body); Body = Body.ltrim('/'); llvm::SmallString<16> Path(Body); - path::native(Path); fs::make_absolute(TestScheme::TestDir, Path); + path::native(Path); return std::string(Path); } llvm::Expected uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override { llvm::StringRef Body = AbsolutePath; - if (!Body.consume_front(TestScheme::TestDir)) + llvm::SmallString<16> NativeTestDir(TestDir); + llvm::sys::path::native(NativeTestDir); + if (!Body.consume_front(NativeTestDir)) return error("Path {0} doesn't start with root {1}", AbsolutePath, TestDir); diff --git a/clang-tools-extra/clangd/unittests/TestFS.h b/clang-tools-extra/clangd/unittests/TestFS.h --- a/clang-tools-extra/clangd/unittests/TestFS.h +++ b/clang-tools-extra/clangd/unittests/TestFS.h @@ -75,7 +75,8 @@ }; // Returns an absolute (fake) test directory for this OS. -const char *testRoot(); +llvm::SmallString<16> testRootBuf(); +#define testRoot() testRootBuf().c_str() // Returns a suitable absolute path for this OS. std::string testPath(PathRef File, diff --git a/clang-tools-extra/clangd/unittests/TestFS.cpp b/clang-tools-extra/clangd/unittests/TestFS.cpp --- a/clang-tools-extra/clangd/unittests/TestFS.cpp +++ b/clang-tools-extra/clangd/unittests/TestFS.cpp @@ -71,11 +71,14 @@ FileName, std::move(CommandLine), "")}; } -const char *testRoot() { +llvm::SmallString<16> testRootBuf() { #ifdef _WIN32 - return "C:\\clangd-test"; + llvm::SmallString<16> NativeRoot("C:\\clangd-test"); + llvm::sys::path::native(NativeRoot); + return NativeRoot; #else - return "/clangd-test"; + llvm::SmallString<16> Root("/clangd-test"); + return Root; #endif } diff --git a/clang-tools-extra/clangd/unittests/URITests.cpp b/clang-tools-extra/clangd/unittests/URITests.cpp --- a/clang-tools-extra/clangd/unittests/URITests.cpp +++ b/clang-tools-extra/clangd/unittests/URITests.cpp @@ -133,8 +133,10 @@ TEST(URITest, Resolve) { #ifdef _WIN32 - EXPECT_THAT(resolveOrDie(parseOrDie("file:///c%3a/x/y/z")), "c:\\x\\y\\z"); - EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), "c:\\x\\y\\z"); + llvm::SmallString<16> Ref("c:\\x\\y\\z"); + llvm::sys::path::native(Ref); + EXPECT_THAT(resolveOrDie(parseOrDie("file:///c%3a/x/y/z")), Ref); + EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), Ref); #else EXPECT_EQ(resolveOrDie(parseOrDie("file:/a/b/c")), "/a/b/c"); EXPECT_EQ(resolveOrDie(parseOrDie("file://auth/a/b/c")), "//auth/a/b/c"); @@ -148,13 +150,17 @@ TEST(URITest, ResolveUNC) { #ifdef _WIN32 + llvm::SmallString<32> RefExample("\\\\example.com\\x\\y\\z"); + llvm::sys::path::native(RefExample); + llvm::SmallString<16> RefLocalhost("\\\\127.0.0.1\\x\\y\\z"); + llvm::sys::path::native(RefLocalhost); EXPECT_THAT(resolveOrDie(parseOrDie("file://example.com/x/y/z")), - "\\\\example.com\\x\\y\\z"); + RefExample); EXPECT_THAT(resolveOrDie(parseOrDie("file://127.0.0.1/x/y/z")), - "\\\\127.0.0.1\\x\\y\\z"); + RefLocalhost); // Ensure non-traditional file URI still resolves to correct UNC path. EXPECT_THAT(resolveOrDie(parseOrDie("file:////127.0.0.1/x/y/z")), - "\\\\127.0.0.1\\x\\y\\z"); + RefLocalhost); #else EXPECT_THAT(resolveOrDie(parseOrDie("file://example.com/x/y/z")), "//example.com/x/y/z");