[PATCH] D121286: [clangd] Test against path insensitivity

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 10 01:20:35 PST 2022


kadircet updated this revision to Diff 414301.
kadircet added a comment.

Add tests specifically and postpone change in testRoot


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121286/new/

https://reviews.llvm.org/D121286

Files:
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp


Index: clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
+++ clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
@@ -12,7 +12,9 @@
 #include "TestFS.h"
 #include "TestTU.h"
 #include "index/MemIndex.h"
+#include "support/Path.h"
 #include "llvm/ADT/None.h"
+#include "llvm/ADT/StringExtras.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -271,6 +273,29 @@
             *llvm::cantFail(runSwitchHeaderSource(Server, CppPath)));
 }
 
+#ifdef _WIN32
+// Outside of windows systems, we usually have case sensitive file systems.
+TEST(HeaderSourceSwitchTest, CaseSensitivity) {
+  TestTU TU = TestTU::withCode("void foo() {}");
+  TU.HeaderCode = R"cpp(
+  inline void bar1() {}
+  inline void bar2() {})cpp";
+  // Give main file and header different base names to make sure file system
+  // heuristics don't work.
+  TU.Filename = "Source.cpp";
+  TU.HeaderFilename = "Header.h";
+
+  auto Index = TU.index();
+  auto AST = TU.build();
+
+  auto HeaderAbsPath = testPath(TU.Filename);
+  HeaderAbsPath[0] = llvm::toLower(HeaderAbsPath[0]);
+  EXPECT_EQ(testPath(TU.Filename),
+            getCorrespondingHeaderOrSource(testPath(TU.HeaderFilename), AST,
+                                           Index.get()));
+}
+#endif
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/HeaderSourceSwitch.cpp
===================================================================
--- clang-tools-extra/clangd/HeaderSourceSwitch.cpp
+++ clang-tools-extra/clangd/HeaderSourceSwitch.cpp
@@ -11,6 +11,7 @@
 #include "SourceCode.h"
 #include "index/SymbolCollector.h"
 #include "support/Logger.h"
+#include "support/Path.h"
 #include "clang/AST/Decl.h"
 
 namespace clang {
@@ -82,7 +83,7 @@
   llvm::StringMap<int> Candidates; // Target path => score.
   auto AwardTarget = [&](const char *TargetURI) {
     if (auto TargetPath = URI::resolve(TargetURI, OriginalFile)) {
-      if (*TargetPath != OriginalFile) // exclude the original file.
+      if (!pathEqual(*TargetPath, OriginalFile)) // exclude the original file.
         ++Candidates[*TargetPath];
     } else {
       elog("Failed to resolve URI {0}: {1}", TargetURI, TargetPath.takeError());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121286.414301.patch
Type: text/x-patch
Size: 2348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220310/706d9b11/attachment.bin>


More information about the cfe-commits mailing list