[clang-tools-extra] r340035 - [clangd] Add a testcase for empty preamble.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 17 07:55:58 PDT 2018
Author: hokein
Date: Fri Aug 17 07:55:57 2018
New Revision: 340035
URL: http://llvm.org/viewvc/llvm-project?rev=340035&view=rev
Log:
[clangd] Add a testcase for empty preamble.
Summary: This is a patch of add a testcase for https://reviews.llvm.org/D50628.
Reviewers: ilya-biryukov
Subscribers: javed.absar, ioeric, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D50627
Modified:
clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
Modified: clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp?rev=340035&r1=340034&r2=340035&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TUSchedulerTests.cpp Fri Aug 17 07:55:57 2018
@@ -308,6 +308,51 @@ TEST_F(TUSchedulerTests, EvictedAST) {
UnorderedElementsAre(Foo, AnyOf(Bar, Baz)));
}
+TEST_F(TUSchedulerTests, EmptyPreamble) {
+ TUScheduler S(
+ /*AsyncThreadsCount=*/4, /*StorePreambleInMemory=*/true,
+ PreambleParsedCallback(),
+ /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+ ASTRetentionPolicy());
+
+ auto Foo = testPath("foo.cpp");
+ auto Header = testPath("foo.h");
+
+ Files[Header] = "void foo()";
+ Timestamps[Header] = time_t(0);
+ auto WithPreamble = R"cpp(
+ #include "foo.h"
+ int main() {}
+ )cpp";
+ auto WithEmptyPreamble = R"cpp(int main() {})cpp";
+ S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto,
+ [](std::vector<Diag>) {});
+ S.runWithPreamble("getNonEmptyPreamble", Foo,
+ [&](llvm::Expected<InputsAndPreamble> Preamble) {
+ // We expect to get a non-empty preamble.
+ EXPECT_GT(cantFail(std::move(Preamble))
+ .Preamble->Preamble.getBounds()
+ .Size,
+ 0u);
+ });
+ // Wait for the preamble is being built.
+ ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+
+ // Update the file which results in an empty preamble.
+ S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto,
+ [](std::vector<Diag>) {});
+ // Wait for the preamble is being built.
+ ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(1)));
+ S.runWithPreamble("getEmptyPreamble", Foo,
+ [&](llvm::Expected<InputsAndPreamble> Preamble) {
+ // We expect to get an empty preamble.
+ EXPECT_EQ(cantFail(std::move(Preamble))
+ .Preamble->Preamble.getBounds()
+ .Size,
+ 0u);
+ });
+}
+
TEST_F(TUSchedulerTests, RunWaitsForPreamble) {
// Testing strategy: we update the file and schedule a few preamble reads at
// the same time. All reads should get the same non-null preamble.
More information about the cfe-commits
mailing list