Changeset View
Changeset View
Standalone View
Standalone View
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | testing::AssertionResult matchesConditionally( | ||||
MatchFinder Finder; | MatchFinder Finder; | ||||
VerifyMatch VerifyFound(nullptr, &Found); | VerifyMatch VerifyFound(nullptr, &Found); | ||||
Finder.addMatcher(AMatcher, &VerifyFound); | Finder.addMatcher(AMatcher, &VerifyFound); | ||||
VerifyMatch VerifyDynamicFound(nullptr, &DynamicFound); | VerifyMatch VerifyDynamicFound(nullptr, &DynamicFound); | ||||
if (!Finder.addDynamicMatcher(AMatcher, &VerifyDynamicFound)) | if (!Finder.addDynamicMatcher(AMatcher, &VerifyDynamicFound)) | ||||
return testing::AssertionFailure() << "Could not add dynamic matcher"; | return testing::AssertionFailure() << "Could not add dynamic matcher"; | ||||
std::unique_ptr<FrontendActionFactory> Factory( | std::unique_ptr<FrontendActionFactory> Factory( | ||||
newFrontendActionFactory(&Finder)); | newFrontendActionFactory(&Finder)); | ||||
// Some tests use typeof, which is a gnu extension. | // Some tests need rtti/exceptions on. Use an unknown-unknown triple so we | ||||
std::vector<std::string> Args; | // don't instantiate the full system toolchain. On Linux, instantiating the | ||||
Args.push_back(CompileArg); | // toolchain involves stat'ing large portions of /usr/lib, and this slows down | ||||
// Some tests need rtti/exceptions on | // not only this test, but all other tests, via contention in the kernel. | ||||
Args.push_back("-frtti"); | // | ||||
Args.push_back("-fexceptions"); | // FIXME: This is a hack to work around the fact that there's no way to do the | ||||
// equivalent of runToolOnCodeWithArgs without instantiating a full Driver. | |||||
// We should consider having a function, at least for tests, that invokes cc1. | |||||
std::vector<std::string> Args = {CompileArg, "-frtti", "-fexceptions", | |||||
"-target", "i386-unknown-unknown"}; | |||||
if (!runToolOnCodeWithArgs( | if (!runToolOnCodeWithArgs( | ||||
Factory->create(), Code, Args, Filename, "clang-tool", | Factory->create(), Code, Args, Filename, "clang-tool", | ||||
std::make_shared<PCHContainerOperations>(), VirtualMappedFiles)) { | std::make_shared<PCHContainerOperations>(), VirtualMappedFiles)) { | ||||
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; | return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; | ||||
} | } | ||||
if (Found != DynamicFound) { | if (Found != DynamicFound) { | ||||
return testing::AssertionFailure() << "Dynamic match result (" | return testing::AssertionFailure() << "Dynamic match result (" | ||||
<< DynamicFound | << DynamicFound | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | testing::AssertionResult matchesConditionallyWithCuda( | ||||
MatchFinder Finder; | MatchFinder Finder; | ||||
VerifyMatch VerifyFound(nullptr, &Found); | VerifyMatch VerifyFound(nullptr, &Found); | ||||
Finder.addMatcher(AMatcher, &VerifyFound); | Finder.addMatcher(AMatcher, &VerifyFound); | ||||
VerifyMatch VerifyDynamicFound(nullptr, &DynamicFound); | VerifyMatch VerifyDynamicFound(nullptr, &DynamicFound); | ||||
if (!Finder.addDynamicMatcher(AMatcher, &VerifyDynamicFound)) | if (!Finder.addDynamicMatcher(AMatcher, &VerifyDynamicFound)) | ||||
return testing::AssertionFailure() << "Could not add dynamic matcher"; | return testing::AssertionFailure() << "Could not add dynamic matcher"; | ||||
std::unique_ptr<FrontendActionFactory> Factory( | std::unique_ptr<FrontendActionFactory> Factory( | ||||
newFrontendActionFactory(&Finder)); | newFrontendActionFactory(&Finder)); | ||||
// Some tests use typeof, which is a gnu extension. | // Some tests use typeof, which is a gnu extension. Using an explicit | ||||
std::vector<std::string> Args; | // unknown-unknown triple is good for a large speedup, because it lets us | ||||
Args.push_back("-xcuda"); | // avoid constructing a full system triple. | ||||
Args.push_back("-fno-ms-extensions"); | std::vector<std::string> Args = { | ||||
Args.push_back("--cuda-host-only"); | "-xcuda", "-fno-ms-extensions", "--cuda-host-only", "-nocudainc", | ||||
Args.push_back("-nocudainc"); | "-target", "nvptx64-unknown-unknown", CompileArg}; | ||||
Args.push_back(CompileArg); | |||||
if (!runToolOnCodeWithArgs(Factory->create(), | if (!runToolOnCodeWithArgs(Factory->create(), | ||||
CudaHeader + Code, Args)) { | CudaHeader + Code, Args)) { | ||||
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; | return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; | ||||
} | } | ||||
if (Found != DynamicFound) { | if (Found != DynamicFound) { | ||||
return testing::AssertionFailure() << "Dynamic match result (" | return testing::AssertionFailure() << "Dynamic match result (" | ||||
<< DynamicFound | << DynamicFound | ||||
<< ") does not match static result (" | << ") does not match static result (" | ||||
Show All 27 Lines | matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher, | ||||
std::unique_ptr<BoundNodesCallback> FindResultVerifier, | std::unique_ptr<BoundNodesCallback> FindResultVerifier, | ||||
bool ExpectResult) { | bool ExpectResult) { | ||||
bool VerifiedResult = false; | bool VerifiedResult = false; | ||||
MatchFinder Finder; | MatchFinder Finder; | ||||
VerifyMatch VerifyVerifiedResult(std::move(FindResultVerifier), &VerifiedResult); | VerifyMatch VerifyVerifiedResult(std::move(FindResultVerifier), &VerifiedResult); | ||||
Finder.addMatcher(AMatcher, &VerifyVerifiedResult); | Finder.addMatcher(AMatcher, &VerifyVerifiedResult); | ||||
std::unique_ptr<FrontendActionFactory> Factory( | std::unique_ptr<FrontendActionFactory> Factory( | ||||
newFrontendActionFactory(&Finder)); | newFrontendActionFactory(&Finder)); | ||||
// Some tests use typeof, which is a gnu extension. | // Some tests use typeof, which is a gnu extension. Using an explicit | ||||
std::vector<std::string> Args(1, "-std=gnu++98"); | // 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++98", "-target", | |||||
"i386-unknown-unknown"}; | |||||
if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) { | if (!runToolOnCodeWithArgs(Factory->create(), Code, Args)) { | ||||
return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; | return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; | ||||
} | } | ||||
if (!VerifiedResult && ExpectResult) { | if (!VerifiedResult && ExpectResult) { | ||||
return testing::AssertionFailure() | return testing::AssertionFailure() | ||||
<< "Could not verify result in \"" << Code << "\""; | << "Could not verify result in \"" << Code << "\""; | ||||
} else if (VerifiedResult && !ExpectResult) { | } else if (VerifiedResult && !ExpectResult) { | ||||
return testing::AssertionFailure() | return testing::AssertionFailure() | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |