Index: tools/gn/test_with_scope.cc |
diff --git a/tools/gn/test_with_scope.cc b/tools/gn/test_with_scope.cc |
index 32d5dd675850bcf54886b0289b086360306a655b..be2875557eb90b2a4d81b0fbf60fc781be454cc9 100644 |
--- a/tools/gn/test_with_scope.cc |
+++ b/tools/gn/test_with_scope.cc |
@@ -24,6 +24,7 @@ TestWithScope::TestWithScope() |
settings_.set_default_toolchain_label(toolchain_.label()); |
SetupToolchain(&toolchain_); |
+ scope_.set_item_collector(&items_); |
} |
TestWithScope::~TestWithScope() { |
@@ -37,6 +38,35 @@ Label TestWithScope::ParseLabel(const std::string& str) const { |
return result; |
} |
+bool TestWithScope::ExecuteSnippet(const std::string& str, Err* err) { |
+ TestParseInput input(str); |
+ if (input.has_error()) { |
+ if (err != nullptr) { |
brettw
2016/04/19 18:29:39
I've not used optional errors in any places to avo
agrieve
2016/04/20 00:45:02
Done.
|
+ *err = input.parse_err(); |
+ } |
+ return false; |
+ } |
+ |
+ size_t first_item = items_.size(); |
+ Err my_err; |
+ input.parsed()->Execute(&scope_, &my_err); |
+ if (my_err.has_error()) { |
+ if (err != nullptr) { |
+ *err = my_err; |
+ } |
+ return false; |
+ } |
+ |
+ for (size_t i = first_item; i < items_.size(); ++i) { |
+ CHECK(items_[i]->AsTarget() != nullptr) |
+ << "Only targets are supported in ExecuteSnippet()"; |
+ items_[i]->AsTarget()->SetToolchain(&toolchain_); |
+ if (!items_[i]->OnResolved(err)) |
+ return false; |
+ } |
+ return true; |
+} |
+ |
// static |
void TestWithScope::SetupToolchain(Toolchain* toolchain) { |
Err err; |