summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/ASTMatchersTest.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersTest.h')
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.h36
1 files changed, 23 insertions, 13 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index 1ed1b5958a8b..e98129953157 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -293,7 +293,8 @@ testing::AssertionResult notMatchesWithOpenMP51(const Twine &Code,
template <typename T>
testing::AssertionResult matchAndVerifyResultConditionally(
const Twine &Code, const T &AMatcher,
- std::unique_ptr<BoundNodesCallback> FindResultVerifier, bool ExpectResult) {
+ std::unique_ptr<BoundNodesCallback> FindResultVerifier, bool ExpectResult,
+ ArrayRef<std::string> Args = {}, StringRef Filename = "input.cc") {
bool VerifiedResult = false;
MatchFinder Finder;
VerifyMatch VerifyVerifiedResult(std::move(FindResultVerifier),
@@ -304,9 +305,13 @@ testing::AssertionResult matchAndVerifyResultConditionally(
// Some tests use typeof, which is a gnu extension. Using an explicit
// unknown-unknown triple is good for a large speedup, because it lets us
// avoid constructing a full system triple.
- std::vector<std::string> Args = {"-std=gnu++11", "-target",
- "i386-unknown-unknown"};
- if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) {
+ std::vector<std::string> CompileArgs = {"-std=gnu++11", "-target",
+ "i386-unknown-unknown"};
+ // Append additional arguments at the end to allow overriding the default
+ // choices that we made above.
+ llvm::copy(Args, std::back_inserter(CompileArgs));
+
+ if (!runToolOnCodeWithArgs(Factory->create(), Code, CompileArgs, Filename)) {
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
}
if (!VerifiedResult && ExpectResult) {
@@ -319,8 +324,8 @@ testing::AssertionResult matchAndVerifyResultConditionally(
VerifiedResult = false;
SmallString<256> Buffer;
- std::unique_ptr<ASTUnit> AST(
- buildASTFromCodeWithArgs(Code.toStringRef(Buffer), Args));
+ std::unique_ptr<ASTUnit> AST(buildASTFromCodeWithArgs(
+ Code.toStringRef(Buffer), CompileArgs, Filename));
if (!AST.get())
return testing::AssertionFailure()
<< "Parsing error in \"" << Code << "\" while building AST";
@@ -339,19 +344,24 @@ testing::AssertionResult matchAndVerifyResultConditionally(
// FIXME: Find better names for these functions (or document what they
// do more precisely).
template <typename T>
-testing::AssertionResult matchAndVerifyResultTrue(
- const Twine &Code, const T &AMatcher,
- std::unique_ptr<BoundNodesCallback> FindResultVerifier) {
- return matchAndVerifyResultConditionally(Code, AMatcher,
- std::move(FindResultVerifier), true);
+testing::AssertionResult
+matchAndVerifyResultTrue(const Twine &Code, const T &AMatcher,
+ std::unique_ptr<BoundNodesCallback> FindResultVerifier,
+ ArrayRef<std::string> Args = {},
+ StringRef Filename = "input.cc") {
+ return matchAndVerifyResultConditionally(
+ Code, AMatcher, std::move(FindResultVerifier),
+ /*ExpectResult=*/true, Args, Filename);
}
template <typename T>
testing::AssertionResult matchAndVerifyResultFalse(
const Twine &Code, const T &AMatcher,
- std::unique_ptr<BoundNodesCallback> FindResultVerifier) {
+ std::unique_ptr<BoundNodesCallback> FindResultVerifier,
+ ArrayRef<std::string> Args = {}, StringRef Filename = "input.cc") {
return matchAndVerifyResultConditionally(
- Code, AMatcher, std::move(FindResultVerifier), false);
+ Code, AMatcher, std::move(FindResultVerifier),
+ /*ExpectResult=*/false, Args, Filename);
}
// Implements a run method that returns whether BoundNodes contains a