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
diff --git a/unittests/ASTMatchers/ASTMatchersTest.h b/unittests/ASTMatchers/ASTMatchersTest.h
index 5fed85b..e65d8e7 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/unittests/ASTMatchers/ASTMatchersTest.h
@@ -26,6 +26,7 @@
   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 @@
     }
   }
 
+  void onEndOfTranslationUnit() LLVM_OVERRIDE {
+    if (FindResultReviewer)
+      FindResultReviewer->onEndOfTranslationUnit();
+  }
+
 private:
   bool *const Verified;
   BoundNodesCallback *const FindResultReviewer;
@@ -54,15 +60,23 @@
                                               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 << "\"";