diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2013-11-07 22:30:36 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2013-11-07 22:30:36 +0000 |
commit | 51fcdf84a794a01601c7c78889efa21fbfc1db08 (patch) | |
tree | d70306b20773a4e138b97fc6b1731f8c3c651bd1 /unittests | |
parent | d2bd58907f77e1c1b68a6fa8fc72e1c5b057a5b1 (diff) | |
download | clang-51fcdf84a794a01601c7c78889efa21fbfc1db08.tar.gz |
Introduce MatchFinder::matchAST.
Differential Revision: http://llvm-reviews.chandlerc.com/D2115
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194223 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 12 | ||||
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.h | 17 |
2 files changed, 29 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 5649ad897e..cc13c01fec 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4114,6 +4114,12 @@ TEST(MatchFinder, InterceptsStartOfTranslationUnit) { OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder)); ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), "int x;")); EXPECT_TRUE(VerifyCallback.Called); + + VerifyCallback.Called = false; + OwningPtr<ASTUnit> AST(tooling::buildASTFromCode("int x;")); + ASSERT_TRUE(AST.get()); + Finder.matchAST(AST->getASTContext()); + EXPECT_TRUE(VerifyCallback.Called); } class VerifyEndOfTranslationUnit : public MatchFinder::MatchCallback { @@ -4135,6 +4141,12 @@ TEST(MatchFinder, InterceptsEndOfTranslationUnit) { OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder)); ASSERT_TRUE(tooling::runToolOnCode(Factory->create(), "int x;")); EXPECT_TRUE(VerifyCallback.Called); + + VerifyCallback.Called = false; + OwningPtr<ASTUnit> AST(tooling::buildASTFromCode("int x;")); + ASSERT_TRUE(AST.get()); + Finder.matchAST(AST->getASTContext()); + EXPECT_TRUE(VerifyCallback.Called); } TEST(EqualsBoundNodeMatcher, QualType) { diff --git a/unittests/ASTMatchers/ASTMatchersTest.h b/unittests/ASTMatchers/ASTMatchersTest.h index e65d8e792d..f5bcd37f11 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.h +++ b/unittests/ASTMatchers/ASTMatchersTest.h @@ -11,12 +11,14 @@ #define LLVM_CLANG_UNITTESTS_AST_MATCHERS_AST_MATCHERS_TEST_H #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Frontend/ASTUnit.h" #include "clang/Tooling/Tooling.h" #include "gtest/gtest.h" namespace clang { namespace ast_matchers { +using clang::tooling::buildASTFromCodeWithArgs; using clang::tooling::newFrontendActionFactory; using clang::tooling::runToolOnCodeWithArgs; using clang::tooling::FrontendActionFactory; @@ -121,6 +123,21 @@ matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher, return testing::AssertionFailure() << "Verified unexpected result in \"" << Code << "\""; } + + VerifiedResult = false; + OwningPtr<ASTUnit> AST(buildASTFromCodeWithArgs(Code, Args)); + if (!AST.get()) + return testing::AssertionFailure() << "Parsing error in \"" << Code + << "\" while building AST"; + Finder.matchAST(AST->getASTContext()); + if (!VerifiedResult && ExpectResult) { + return testing::AssertionFailure() + << "Could not verify result in \"" << Code << "\" with AST"; + } else if (VerifiedResult && !ExpectResult) { + return testing::AssertionFailure() + << "Verified unexpected result in \"" << Code << "\" with AST"; + } + return testing::AssertionSuccess(); } |