[PATCH] D48947: [clangd] Added a test for preambles and -isystem

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 4 10:19:30 PDT 2018


ilya-biryukov created this revision.
ilya-biryukov added reviewers: sammccall, ioeric.
Herald added subscribers: jkorous, MaskRay.

Checks that preambles are properly invalidated when headers from
-isystem paths change.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48947

Files:
  unittests/clangd/ClangdTests.cpp


Index: unittests/clangd/ClangdTests.cpp
===================================================================
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -34,13 +34,16 @@
 namespace clangd {
 
 using ::testing::ElementsAre;
+using ::testing::Contains;
 using ::testing::Eq;
 using ::testing::Gt;
 using ::testing::IsEmpty;
 using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
 
 namespace {
+// FIXME: This is copied from CodeCompleteTests.cpp. Share the code instead.
+MATCHER_P(Named, Name, "") { return arg.Name == Name; }
 
 bool diagsContainErrors(const std::vector<Diag> &Diagnostics) {
   for (auto D : Diagnostics) {
@@ -927,6 +930,40 @@
   EXPECT_EQ(Expected, *Changed);
 }
 
+TEST_F(ClangdVFSTest, ChangedHeaderFromISystem) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  MockCompilationDatabase CDB;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+
+  auto SourcePath = testPath("source/foo.cpp");
+  auto HeaderPath = testPath("headers/foo.h");
+  FS.Files[HeaderPath] = "struct X { int bar; };";
+  Annotations Code(R"cpp(
+    #include "foo.h"
+
+    int main() {
+      X().ba^
+    })cpp");
+  CDB.ExtraClangFlags.push_back("-xc++");
+  CDB.ExtraClangFlags.push_back("-isystem" + testPath("headers"));
+
+  runAddDocument(Server, SourcePath, Code.code());
+  auto Completions = cantFail(runCodeComplete(Server, SourcePath, Code.point(),
+                                        clangd::CodeCompleteOptions()))
+                   .Completions;
+  EXPECT_THAT(Completions, ElementsAre(Named("bar")));
+  // Update the header and rerun addDocument to make sure we get the updated
+  // files.
+  FS.Files[HeaderPath] = "struct X { int bar; int baz; };";
+  runAddDocument(Server, SourcePath, Code.code());
+  Completions = cantFail(runCodeComplete(Server, SourcePath, Code.point(),
+                                        clangd::CodeCompleteOptions()))
+                   .Completions;
+  // We want to make sure we see the updated version.
+  EXPECT_THAT(Completions, ElementsAre(Named("bar"), Named("baz")));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48947.154135.patch
Type: text/x-patch
Size: 2187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180704/37acb500/attachment-0001.bin>


More information about the cfe-commits mailing list