[clang-tools-extra] 478f6fb - [clangd] Add buildPreamble to TestTU
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Fri May 29 03:24:36 PDT 2020
Author: Kadir Cetinkaya
Date: 2020-05-29T12:20:23+02:00
New Revision: 478f6fb2001698eb102ddce9500ff0885eaaeaab
URL: https://github.com/llvm/llvm-project/commit/478f6fb2001698eb102ddce9500ff0885eaaeaab
DIFF: https://github.com/llvm/llvm-project/commit/478f6fb2001698eb102ddce9500ff0885eaaeaab.diff
LOG: [clangd] Add buildPreamble to TestTU
Summary: Depends on D77644.
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D79930
Added:
Modified:
clang-tools-extra/clangd/unittests/PreambleTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/TestTU.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
index bb471ab30175..75aad728280a 100644
--- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -36,37 +36,19 @@ MATCHER_P2(Distance, File, D, "") {
return arg.first() == File && arg.second == D;
}
-std::shared_ptr<const PreambleData>
-createPreamble(llvm::StringRef Contents = "") {
- auto TU = TestTU::withCode(Contents);
- // ms-compatibility changes meaning of #import, make sure it is turned off.
- TU.ExtraArgs = {"-fno-ms-compatibility"};
- TU.Filename = "preamble.cpp";
- auto PI = TU.inputs();
- IgnoreDiagnostics Diags;
- auto CI = buildCompilerInvocation(PI, Diags);
- if (!CI) {
- ADD_FAILURE() << "failed to build compiler invocation";
- return nullptr;
- }
- if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
- return Preamble;
- ADD_FAILURE() << "failed to build preamble";
- return nullptr;
-}
-
// Builds a preamble for BaselineContents, patches it for ModifiedContents and
// returns the includes in the patch.
IncludeStructure
collectPatchedIncludes(llvm::StringRef ModifiedContents,
llvm::StringRef BaselineContents,
llvm::StringRef MainFileName = "main.cpp") {
- auto BaselinePreamble = createPreamble(BaselineContents);
- // Create the patch.
- auto TU = TestTU::withCode(ModifiedContents);
+ auto TU = TestTU::withCode(BaselineContents);
TU.Filename = MainFileName.str();
// ms-compatibility changes meaning of #import, make sure it is turned off.
TU.ExtraArgs = {"-fno-ms-compatibility"};
+ auto BaselinePreamble = TU.preamble();
+ // Create the patch.
+ TU = TestTU::withCode(ModifiedContents);
auto PI = TU.inputs();
auto PP = PreamblePatch::create(testPath(TU.Filename), PI, *BaselinePreamble);
// Collect patch contents.
diff --git a/clang-tools-extra/clangd/unittests/TestTU.cpp b/clang-tools-extra/clangd/unittests/TestTU.cpp
index 824c4cc8ff14..b4781425943c 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -66,14 +66,24 @@ ParseInputs TestTU::inputs() const {
return Inputs;
}
+std::shared_ptr<const PreambleData> TestTU::preamble() const {
+ auto Inputs = inputs();
+ IgnoreDiagnostics Diags;
+ auto CI = buildCompilerInvocation(Inputs, Diags);
+ assert(CI && "Failed to build compilation invocation.");
+ return clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+ /*StoreInMemory=*/true,
+ /*PreambleCallback=*/nullptr);
+}
+
ParsedAST TestTU::build() const {
auto Inputs = inputs();
StoreDiags Diags;
auto CI = buildCompilerInvocation(Inputs, Diags);
assert(CI && "Failed to build compilation invocation.");
- auto Preamble =
- buildPreamble(testPath(Filename), *CI, Inputs,
- /*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);
+ auto Preamble = clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+ /*StoreInMemory=*/true,
+ /*PreambleCallback=*/nullptr);
auto AST = ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
Diags.take(), Preamble);
if (!AST.hasValue()) {
diff --git a/clang-tools-extra/clangd/unittests/TestTU.h b/clang-tools-extra/clangd/unittests/TestTU.h
index 2be294f78e7e..57017f4a9175 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.h
+++ b/clang-tools-extra/clangd/unittests/TestTU.h
@@ -68,6 +68,7 @@ struct TestTU {
// By default, build() will report Error diagnostics as GTest errors.
// Suppress this behavior by adding an 'error-ok' comment to the code.
ParsedAST build() const;
+ std::shared_ptr<const PreambleData> preamble() const;
ParseInputs inputs() const;
SymbolSlab headerSymbols() const;
RefSlab headerRefs() const;
More information about the cfe-commits
mailing list