summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2017-08-14 08:37:32 +0000
committerIlya Biryukov <ibiryukov@google.com>2017-08-14 08:37:32 +0000
commit91dbf5b6b4128b70359de70ee41d3fb1a6112ecf (patch)
tree36d0a7cab1cf2a56d787b9bae912017bc1277668 /clang-tools-extra/unittests
parentc5ad35fb23368fef39e4f57d90c35deede9f32e5 (diff)
downloadbcm5719-llvm-91dbf5b6b4128b70359de70ee41d3fb1a6112ecf.tar.gz
bcm5719-llvm-91dbf5b6b4128b70359de70ee41d3fb1a6112ecf.zip
[clangd] Check if CompileCommand has changed on forceReparse.
Reviewers: krasimir, bkramer, klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D36398 llvm-svn: 310819
Diffstat (limited to 'clang-tools-extra/unittests')
-rw-r--r--clang-tools-extra/unittests/clangd/ClangdTests.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/clang-tools-extra/unittests/clangd/ClangdTests.cpp b/clang-tools-extra/unittests/clangd/ClangdTests.cpp
index 7fae4fa7e87..e120ff587ff 100644
--- a/clang-tools-extra/unittests/clangd/ClangdTests.cpp
+++ b/clang-tools-extra/unittests/clangd/ClangdTests.cpp
@@ -501,6 +501,53 @@ std::string x;
}
#endif // LLVM_ON_UNIX
+TEST_F(ClangdVFSTest, ForceReparseCompileCommand) {
+ MockFSProvider FS;
+ ErrorCheckingDiagConsumer DiagConsumer;
+ MockCompilationDatabase CDB(/*AddFreestandingFlag=*/true);
+ ClangdServer Server(CDB, DiagConsumer, FS,
+ /*RunSynchronously=*/true);
+ // No need to sync reparses, because RunSynchronously is set
+ // to true.
+
+ auto FooCpp = getVirtualTestFilePath("foo.cpp");
+ const auto SourceContents1 = R"cpp(
+template <class T>
+struct foo { T x; };
+)cpp";
+ const auto SourceContents2 = R"cpp(
+template <class T>
+struct bar { T x; };
+)cpp";
+
+ FS.Files[FooCpp] = "";
+ FS.ExpectedFile = FooCpp;
+
+ // First parse files in C mode and check they produce errors.
+ CDB.ExtraClangFlags = {"-xc"};
+ Server.addDocument(FooCpp, SourceContents1);
+ EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
+ Server.addDocument(FooCpp, SourceContents2);
+ EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
+
+ // Now switch to C++ mode.
+ CDB.ExtraClangFlags = {"-xc++"};
+ // Currently, addDocument never checks if CompileCommand has changed, so we
+ // expect to see the errors.
+ Server.addDocument(FooCpp, SourceContents1);
+ EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
+ Server.addDocument(FooCpp, SourceContents2);
+ EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
+ // But forceReparse should reparse the file with proper flags.
+ Server.forceReparse(FooCpp);
+ EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
+ // Subsequent addDocument calls should finish without errors too.
+ Server.addDocument(FooCpp, SourceContents1);
+ EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
+ Server.addDocument(FooCpp, SourceContents2);
+ EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
+}
+
class ClangdCompletionTest : public ClangdVFSTest {
protected:
bool ContainsItem(std::vector<CompletionItem> const &Items, StringRef Name) {
OpenPOWER on IntegriCloud