diff options
Diffstat (limited to 'unittests/ASTMatchers/ASTMatchersTest.h')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTest.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTest.h b/unittests/ASTMatchers/ASTMatchersTest.h index 64816f5d60468..3b23ada8da778 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.h +++ b/unittests/ASTMatchers/ASTMatchersTest.h @@ -18,13 +18,14 @@ namespace clang { namespace ast_matchers { using clang::tooling::newFrontendActionFactory; -using clang::tooling::runToolOnCode; +using clang::tooling::runToolOnCodeWithArgs; using clang::tooling::FrontendActionFactory; class BoundNodesCallback { public: virtual ~BoundNodesCallback() {} virtual bool run(const BoundNodes *BoundNodes) = 0; + virtual bool run(const BoundNodes *BoundNodes, ASTContext *Context) = 0; }; // If 'FindResultVerifier' is not NULL, sets *Verified to the result of @@ -37,7 +38,7 @@ public: virtual void run(const MatchFinder::MatchResult &Result) { if (FindResultReviewer != NULL) { - *Verified = FindResultReviewer->run(&Result.Nodes); + *Verified |= FindResultReviewer->run(&Result.Nodes, Result.Context); } else { *Verified = true; } @@ -51,12 +52,15 @@ private: template <typename T> testing::AssertionResult matchesConditionally(const std::string &Code, const T &AMatcher, - bool ExpectMatch) { + bool ExpectMatch, + llvm::StringRef CompileArg) { bool Found = false; MatchFinder Finder; Finder.addMatcher(AMatcher, new VerifyMatch(0, &Found)); OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder)); - if (!runToolOnCode(Factory->create(), Code)) { + // 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 && ExpectMatch) { @@ -71,13 +75,13 @@ testing::AssertionResult matchesConditionally(const std::string &Code, template <typename T> testing::AssertionResult matches(const std::string &Code, const T &AMatcher) { - return matchesConditionally(Code, AMatcher, true); + return matchesConditionally(Code, AMatcher, true, "-std=c++11"); } template <typename T> testing::AssertionResult notMatches(const std::string &Code, const T &AMatcher) { - return matchesConditionally(Code, AMatcher, false); + return matchesConditionally(Code, AMatcher, false, "-std=c++11"); } template <typename T> @@ -91,7 +95,9 @@ matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher, Finder.addMatcher( AMatcher, new VerifyMatch(FindResultVerifier, &VerifiedResult)); OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder)); - if (!runToolOnCode(Factory->create(), Code)) { + // Some tests use typeof, which is a gnu extension. + std::vector<std::string> Args(1, "-std=gnu++98"); + if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) { return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; } if (!VerifiedResult && ExpectResult) { |