diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2013-11-07 22:30:32 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2013-11-07 22:30:32 +0000 |
commit | d2bd58907f77e1c1b68a6fa8fc72e1c5b057a5b1 (patch) | |
tree | c49204d1af6701a991b87ccf161d587dd900b90b /unittests | |
parent | baa9af171fd7ac6ff6a1b5ca09bf77168c1728e7 (diff) | |
download | clang-d2bd58907f77e1c1b68a6fa8fc72e1c5b057a5b1.tar.gz |
Re-introduce MatchFinder::addDynamicMatcher.
Differential Revision: http://llvm-reviews.chandlerc.com/D2114
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194222 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.cpp | 21 | ||||
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.h | 16 |
2 files changed, 35 insertions, 2 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index a848d55f98..5649ad897e 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -40,6 +40,18 @@ TEST(IsDerivedFromDeathTest, DiesOnEmptyBaseName) { } #endif +TEST(Finder, DynamicOnlyAcceptsSomeMatchers) { + MatchFinder Finder; + EXPECT_TRUE(Finder.addDynamicMatcher(decl(), NULL)); + EXPECT_TRUE(Finder.addDynamicMatcher(callExpr(), NULL)); + EXPECT_TRUE(Finder.addDynamicMatcher(constantArrayType(hasSize(42)), NULL)); + + // Do not accept non-toplevel matchers. + EXPECT_FALSE(Finder.addDynamicMatcher(isArrow(), NULL)); + EXPECT_FALSE(Finder.addDynamicMatcher(hasSize(2), NULL)); + EXPECT_FALSE(Finder.addDynamicMatcher(hasName("x"), NULL)); +} + TEST(Decl, MatchesDeclarations) { EXPECT_TRUE(notMatches("", decl(usingDecl()))); EXPECT_TRUE(matches("namespace x { class X {}; } using x::X;", @@ -651,11 +663,18 @@ public: : Id(Id), ExpectedCount(ExpectedCount), Count(0), ExpectedName(ExpectedName) {} - ~VerifyIdIsBoundTo() { + void onEndOfTranslationUnit() LLVM_OVERRIDE { if (ExpectedCount != -1) EXPECT_EQ(ExpectedCount, Count); if (!ExpectedName.empty()) EXPECT_EQ(ExpectedName, Name); + Count = 0; + Name.clear(); + } + + ~VerifyIdIsBoundTo() { + EXPECT_EQ(0, Count); + EXPECT_EQ("", Name); } virtual bool run(const BoundNodes *Nodes) { diff --git a/unittests/ASTMatchers/ASTMatchersTest.h b/unittests/ASTMatchers/ASTMatchersTest.h index 5fed85bb30..e65d8e792d 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.h +++ b/unittests/ASTMatchers/ASTMatchersTest.h @@ -26,6 +26,7 @@ public: virtual ~BoundNodesCallback() {} virtual bool run(const BoundNodes *BoundNodes) = 0; virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0; + virtual void onEndOfTranslationUnit() {} }; // If 'FindResultVerifier' is not NULL, sets *Verified to the result of @@ -44,6 +45,11 @@ public: } } + void onEndOfTranslationUnit() LLVM_OVERRIDE { + if (FindResultReviewer) + FindResultReviewer->onEndOfTranslationUnit(); + } + private: bool *const Verified; BoundNodesCallback *const FindResultReviewer; @@ -54,15 +60,23 @@ testing::AssertionResult matchesConditionally(const std::string &Code, const T &AMatcher, bool ExpectMatch, llvm::StringRef CompileArg) { - bool Found = false; + bool Found = false, DynamicFound = false; MatchFinder Finder; Finder.addMatcher(AMatcher, new VerifyMatch(0, &Found)); + if (!Finder.addDynamicMatcher(AMatcher, new VerifyMatch(0, &DynamicFound))) + return testing::AssertionFailure() << "Could not add dynamic matcher"; OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder)); // Some tests use typeof, which is a gnu extension. std::vector<std::string> Args(1, CompileArg); if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) { return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; } + if (Found != DynamicFound) { + return testing::AssertionFailure() << "Dynamic match result (" + << DynamicFound + << ") does not match static result (" + << Found << ")"; + } if (!Found && ExpectMatch) { return testing::AssertionFailure() << "Could not find match in \"" << Code << "\""; |