summaryrefslogtreecommitdiffstats
path: root/clang/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp12
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.h17
2 files changed, 29 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index 5649ad897e8..cc13c01fec3 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/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/clang/unittests/ASTMatchers/ASTMatchersTest.h b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index e65d8e792df..f5bcd37f112 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/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();
}
OpenPOWER on IntegriCloud