15#include "clang/Lex/PreprocessorOptions.h"
16#include "llvm/Support/Error.h"
17#include "gmock/gmock.h"
18#include "gtest/gtest.h"
25TEST(FeatureModulesTest, ContributesTweak) {
26 static constexpr const char *TweakID =
"ModuleTweak";
27 struct TweakContributingModule final :
public FeatureModule {
28 struct ModuleTweak final :
public Tweak {
29 const char *id()
const override {
return TweakID; }
30 bool prepare(
const Selection &Sel)
override {
return true; }
31 Expected<Effect> apply(
const Selection &Sel)
override {
32 return error(
"not implemented");
34 std::string title()
const override {
return id(); }
35 llvm::StringLiteral kind()
const override {
36 return llvm::StringLiteral(
"");
40 void contributeTweaks(std::vector<std::unique_ptr<Tweak>> &
Out)
override {
41 Out.emplace_back(
new ModuleTweak);
46 Set.add(std::make_unique<TweakContributingModule>());
52 TweakID, Tweak::Selection(
nullptr,
AST, 0, 0, std::move(Tree),
nullptr),
54 ASSERT_TRUE(
bool(Actual));
55 EXPECT_EQ(Actual->get()->id(), TweakID);
58TEST(FeatureModulesTest, SuppressDiags) {
59 struct DiagModifierModule final :
public FeatureModule {
60 struct Listener :
public FeatureModule::ASTListener {
61 void sawDiagnostic(
const clang::Diagnostic &
Info,
62 clangd::Diag &Diag)
override {
63 Diag.Severity = DiagnosticsEngine::Ignored;
66 std::unique_ptr<ASTListener> astListeners()
override {
67 return std::make_unique<Listener>();
71 FMS.add(std::make_unique<DiagModifierModule>());
73 Annotations
Code(
"[[test]]; /* error-ok */");
75 TU.Code =
Code.code().str();
78 auto AST = TU.build();
79 EXPECT_THAT(
AST.getDiagnostics(), testing::Not(testing::IsEmpty()));
82 TU.FeatureModules = &FMS;
84 auto AST = TU.build();
85 EXPECT_THAT(
AST.getDiagnostics(), testing::IsEmpty());
89TEST(FeatureModulesTest, BeforeExecute) {
90 struct BeforeExecuteModule final :
public FeatureModule {
91 struct Listener :
public FeatureModule::ASTListener {
92 void beforeExecute(CompilerInstance &
CI)
override {
93 CI.getPreprocessor().SetSuppressIncludeNotFoundError(
true);
96 std::unique_ptr<ASTListener> astListeners()
override {
97 return std::make_unique<Listener>();
100 FeatureModuleSet FMS;
101 FMS.add(std::make_unique<BeforeExecuteModule>());
105 #include "not_found.h"
108 #include "not_found_not_preamble.h"
113 auto AST = TU.build();
114 EXPECT_THAT(
AST.getDiagnostics(), testing::Not(testing::IsEmpty()));
117 TU.FeatureModules = &FMS;
119 auto AST = TU.build();
120 EXPECT_THAT(
AST.getDiagnostics(), testing::IsEmpty());
CompiledFragmentImpl & Out
std::unique_ptr< CompilerInvocation > CI
static SelectionTree createRight(ASTContext &AST, const syntax::TokenBuffer &Tokens, unsigned Begin, unsigned End)
llvm::Error error(std::error_code, std::string &&)
llvm::Expected< std::unique_ptr< Tweak > > prepareTweak(StringRef ID, const Tweak::Selection &S, const FeatureModuleSet *Modules)
TEST(BackgroundQueueTest, Priority)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static TestTU withCode(llvm::StringRef Code)