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());
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());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits