diff options
Diffstat (limited to 'unittests/AST/MatchVerifier.h')
-rw-r--r-- | unittests/AST/MatchVerifier.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/unittests/AST/MatchVerifier.h b/unittests/AST/MatchVerifier.h index 31932479ef8de..74b9bdfbe7e68 100644 --- a/unittests/AST/MatchVerifier.h +++ b/unittests/AST/MatchVerifier.h @@ -62,6 +62,9 @@ public: std::vector<std::string>& Args, Language L); + template <typename MatcherType> + testing::AssertionResult match(const Decl *D, const MatcherType &AMatcher); + protected: void run(const MatchFinder::MatchResult &Result) override; virtual void verify(const MatchFinder::MatchResult &Result, @@ -127,6 +130,22 @@ testing::AssertionResult MatchVerifier<NodeType>::match( return testing::AssertionSuccess(); } +/// \brief Runs a matcher over some AST, and returns the result of the +/// verifier for the matched node. +template <typename NodeType> template <typename MatcherType> +testing::AssertionResult MatchVerifier<NodeType>::match( + const Decl *D, const MatcherType &AMatcher) { + MatchFinder Finder; + Finder.addMatcher(AMatcher.bind(""), this); + + setFailure("Could not find match"); + Finder.match(*D, D->getASTContext()); + + if (!Verified) + return testing::AssertionFailure() << VerifyResult; + return testing::AssertionSuccess(); +} + template <typename NodeType> void MatchVerifier<NodeType>::run(const MatchFinder::MatchResult &Result) { const NodeType *Node = Result.Nodes.getNodeAs<NodeType>(""); |