[clang-tools-extra] 8cec8de - [clangd] testPath's final result agrees with the passed in Style

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 03:45:17 PST 2020


Author: Kadir Cetinkaya
Date: 2020-11-23T12:45:06+01:00
New Revision: 8cec8de2a4e6692da6226bb02cf417eb0e50adde

URL: https://github.com/llvm/llvm-project/commit/8cec8de2a4e6692da6226bb02cf417eb0e50adde
DIFF: https://github.com/llvm/llvm-project/commit/8cec8de2a4e6692da6226bb02cf417eb0e50adde.diff

LOG: [clangd] testPath's final result agrees with the passed in Style

This was confusing, as testRoot on windows results in C:\\clangd-test
and testPath generated with posix explicitly still contained backslashes.

This patch ensures not only the relative part, but the whole final result
respects passed in Style.

Differential Revision: https://reviews.llvm.org/D91947

Added: 
    

Modified: 
    clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
    clang-tools-extra/clangd/unittests/TestFS.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
index a2423094b17a..2b4605eb97e2 100644
--- a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -255,7 +255,6 @@ TEST_F(ConfigCompileTests, ExternalBlockMountPoint) {
   };
 
   auto BarPath = testPath("foo/bar.h", llvm::sys::path::Style::posix);
-  BarPath = llvm::sys::path::convert_to_slash(BarPath);
   Parm.Path = BarPath;
   // Non-absolute MountPoint without a directory raises an error.
   Frag = GetFrag("", "foo");
@@ -269,7 +268,6 @@ TEST_F(ConfigCompileTests, ExternalBlockMountPoint) {
   ASSERT_FALSE(Conf.Index.External);
 
   auto FooPath = testPath("foo/", llvm::sys::path::Style::posix);
-  FooPath = llvm::sys::path::convert_to_slash(FooPath);
   // Ok when relative.
   Frag = GetFrag(testRoot(), "foo/");
   compileAndApply();
@@ -293,7 +291,6 @@ TEST_F(ConfigCompileTests, ExternalBlockMountPoint) {
 
   // File outside MountPoint, no index.
   auto BazPath = testPath("bar/baz.h", llvm::sys::path::Style::posix);
-  BazPath = llvm::sys::path::convert_to_slash(BazPath);
   Parm.Path = BazPath;
   Frag = GetFrag("", FooPath.c_str());
   compileAndApply();
@@ -302,7 +299,6 @@ TEST_F(ConfigCompileTests, ExternalBlockMountPoint) {
 
   // File under MountPoint, index should be set.
   BazPath = testPath("foo/baz.h", llvm::sys::path::Style::posix);
-  BazPath = llvm::sys::path::convert_to_slash(BazPath);
   Parm.Path = BazPath;
   Frag = GetFrag("", FooPath.c_str());
   compileAndApply();

diff  --git a/clang-tools-extra/clangd/unittests/TestFS.cpp b/clang-tools-extra/clangd/unittests/TestFS.cpp
index ba4010cb4581..f343a85331d0 100644
--- a/clang-tools-extra/clangd/unittests/TestFS.cpp
+++ b/clang-tools-extra/clangd/unittests/TestFS.cpp
@@ -80,12 +80,10 @@ const char *testRoot() {
 }
 
 std::string testPath(PathRef File, llvm::sys::path::Style Style) {
-  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
-
-  llvm::SmallString<32> NativeFile = File;
-  llvm::sys::path::native(NativeFile, Style);
+  assert(llvm::sys::path::is_relative(File, Style));
   llvm::SmallString<32> Path;
-  llvm::sys::path::append(Path, Style, testRoot(), NativeFile);
+  llvm::sys::path::append(Path, testRoot(), File);
+  llvm::sys::path::native(Path, Style);
   return std::string(Path.str());
 }
 


        


More information about the cfe-commits mailing list