brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 19ea46d Raw
67 lines · cpp
1// REQUIRES: plugins2// RUN: clang-tidy -checks='-*,mytest*' --list-checks -load %llvmshlibdir/CTTestTidyModule%pluginext | FileCheck --check-prefix=CHECK-LIST %s3// CHECK-LIST: Enabled checks:4// CHECK-LIST-NEXT:    mytest15// CHECK-LIST-NEXT:    mytest26// RUN: clang-tidy -checks='-*,mytest*,misc-definitions-in-headers' -load %llvmshlibdir/CTTestTidyModule%pluginext /dev/null -- -xc 2>&1 | FileCheck %s7// CHECK: 3 warnings generated.8// CHECK-NEXT: warning: mytest success [misc-definitions-in-headers,mytest1,mytest2]9 10#include "clang-tidy/ClangTidy.h"11#include "clang-tidy/ClangTidyCheck.h"12#include "clang-tidy/ClangTidyModule.h"13#include "clang-tidy/ClangTidyModuleRegistry.h"14#include "clang/AST/ASTContext.h"15#include "clang/ASTMatchers/ASTMatchFinder.h"16 17using namespace clang;18using namespace clang::tidy;19using namespace clang::ast_matchers;20 21namespace {22class MyTestCheck : public ClangTidyCheck {23 24public:25  MyTestCheck(StringRef Name, ClangTidyContext *Context)26      : ClangTidyCheck(Name, Context) {}27 28  void registerMatchers(ast_matchers::MatchFinder *Finder) override {29    Finder->addMatcher(translationUnitDecl().bind("tu"), this);30  }31 32  void check(const ast_matchers::MatchFinder::MatchResult &Result) override {33    auto S = Result.Nodes.getNodeAs<TranslationUnitDecl>("tu");34    if (S)35      diag("mytest success");36  }37 38private:39};40 41class CTTestModule : public ClangTidyModule {42public:43  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {44    CheckFactories.registerCheck<MyTestCheck>("mytest1");45    CheckFactories.registerCheck<MyTestCheck>("mytest2");46    // intentionally collide with an existing test name, overriding it47    CheckFactories.registerCheck<MyTestCheck>("misc-definitions-in-headers");48  }49};50} // namespace51 52namespace tidy1 {53// Register the CTTestTidyModule using this statically initialized variable.54static ClangTidyModuleRegistry::Add<::CTTestModule>55    X("mytest-module", "Adds my checks.");56} // namespace tidy157 58namespace tidy2 {59// intentionally collide with an existing test group name, merging with it60static ClangTidyModuleRegistry::Add<::CTTestModule>61    X("misc-module", "Adds miscellaneous lint checks.");62} // namespace tidy263 64// This anchor is used to force the linker to link in the generated object file65// and thus register the CTTestModule.66volatile int CTTestModuleAnchorSource = 0;67