Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Unified Diff: tools/gn/functions_target_unittest.cc

Issue 2148093002: GN: Use the correct defaults for templates invoked via target(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/gn/functions_target_unittest.cc
diff --git a/tools/gn/functions_target_unittest.cc b/tools/gn/functions_target_unittest.cc
index a7a0de9ac2c63352ec19d0f411b6f10e2ff4e3fb..f4eeb38075c40d23eca76af828a442c69f2156fc 100644
--- a/tools/gn/functions_target_unittest.cc
+++ b/tools/gn/functions_target_unittest.cc
@@ -36,3 +36,37 @@ TEST(FunctionsTarget, CheckUnused) {
source_set_input.parsed()->Execute(setup.scope(), &err);
ASSERT_TRUE(err.has_error());
}
+
+// Checks that the defaults applied to a template invoked by target() use
+// the name of the template, rather than the string "target" (which is the
+// name of the actual function being called).
+TEST(FunctionsTarget, TemplateDefaults) {
+ Scheduler scheduler;
+ TestWithScope setup;
+
+ // The target generator needs a place to put the targets or it will fail.
+ Scope::ItemVector item_collector;
+ setup.scope()->set_item_collector(&item_collector);
+
+ // Test a good one first.
+ TestParseInput good_input(
+ // Make a template with defaults set.
+ "template(\"my_templ\") {\n"
+ " source_set(target_name) {\n"
+ " forward_variables_from(invoker, \"*\")\n"
+ " }\n"
+ "}\n"
+ "set_defaults(\"my_templ\") {\n"
+ " default_value = 1\n"
+ "}\n"
+
+ // Invoke the template with target(). This will fail to execute if the
+ // defaults were not set properly, because "default_value" won't exist.
+ "target(\"my_templ\", \"foo\") {\n"
+ " print(default_value)\n"
+ "}\n");
+ ASSERT_FALSE(good_input.has_error());
+ Err err;
+ good_input.parsed()->Execute(setup.scope(), &err);
+ ASSERT_FALSE(err.has_error()) << err.message();
+}
« tools/gn/functions.cc ('K') | « tools/gn/functions_target.cc ('k') | tools/gn/template.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698