Index: tools/gn/function_forward_variables_from_unittest.cc |
diff --git a/tools/gn/function_forward_variables_from_unittest.cc b/tools/gn/function_forward_variables_from_unittest.cc |
index c3dd715f4f1a8dc11585ddbe8fc08bcfcdeac791..e5137a48b266cc8c5bd161caca2ab51b2f9cb5d3 100644 |
--- a/tools/gn/function_forward_variables_from_unittest.cc |
+++ b/tools/gn/function_forward_variables_from_unittest.cc |
@@ -32,6 +32,34 @@ TEST(FunctionForwardVariablesFrom, List) { |
setup.print_output().clear(); |
} |
+TEST(FunctionForwardVariablesFrom, ListWithExclusion) { |
+ Scheduler scheduler; |
+ TestWithScope setup; |
+ |
+ // Defines a template and copy the two x and y, and z values out. |
+ TestParseInput input( |
+ "template(\"a\") {\n" |
+ " forward_variables_from(invoker, [\"x\", \"y\", \"z\"], [\"z\"])\n" |
+ " assert(!defined(z))\n" // "z" should still be undefined. |
+ " print(\"$target_name, $x, $y\")\n" |
+ "}\n" |
+ "a(\"target\") {\n" |
+ " x = 1\n" |
+ " y = 2\n" |
+ " z = 3\n" |
+ " print(\"$z\")\n" |
+ "}\n"); |
+ |
+ ASSERT_FALSE(input.has_error()); |
+ |
+ Err err; |
+ input.parsed()->Execute(setup.scope(), &err); |
+ ASSERT_FALSE(err.has_error()) << err.message(); |
+ |
+ EXPECT_EQ("3\ntarget, 1, 2\n", setup.print_output()); |
+ setup.print_output().clear(); |
+} |
+ |
TEST(FunctionForwardVariablesFrom, ErrorCases) { |
Scheduler scheduler; |
TestWithScope setup; |
@@ -65,19 +93,61 @@ TEST(FunctionForwardVariablesFrom, ErrorCases) { |
EXPECT_TRUE(err.has_error()); |
EXPECT_EQ("Not a valid list of variables to copy.", err.message()); |
+ // Type check the exclusion list. |
+ TestParseInput invalid_exclusion_list( |
+ "template(\"c\") {\n" |
+ " forward_variables_from(invoker, \"*\", 42)\n" |
+ " print(\"$target_name\")\n" |
+ "}\n" |
+ "c(\"target\") {\n" |
+ "}\n"); |
+ ASSERT_FALSE(invalid_exclusion_list.has_error()); |
+ err = Err(); |
+ invalid_exclusion_list.parsed()->Execute(setup.scope(), &err); |
+ EXPECT_TRUE(err.has_error()); |
+ EXPECT_EQ("Not a valid list of variables to exclude.", err.message()); |
+ |
// Programmatic values should error. |
TestParseInput prog( |
- "template(\"c\") {\n" |
+ "template(\"d\") {\n" |
" forward_variables_from(invoker, [\"root_out_dir\"])\n" |
" print(\"$target_name\")\n" |
"}\n" |
- "c(\"target\") {\n" |
+ "d(\"target\") {\n" |
"}\n"); |
ASSERT_FALSE(prog.has_error()); |
err = Err(); |
prog.parsed()->Execute(setup.scope(), &err); |
EXPECT_TRUE(err.has_error()); |
EXPECT_EQ("This value can't be forwarded.", err.message()); |
+ |
+ // Not enough arguments. |
+ TestParseInput not_enough_arguments( |
+ "template(\"e\") {\n" |
+ " forward_variables_from(invoker)\n" |
+ " print(\"$target_name\")\n" |
+ "}\n" |
+ "e(\"target\") {\n" |
+ "}\n"); |
+ ASSERT_FALSE(not_enough_arguments.has_error()); |
+ err = Err(); |
+ not_enough_arguments.parsed()->Execute(setup.scope(), &err); |
+ EXPECT_TRUE(err.has_error()); |
+ EXPECT_EQ("Wrong number of arguments.", err.message()); |
+ |
+ // Too many arguments. |
+ TestParseInput too_many_arguments( |
+ "template(\"f\") {\n" |
+ " forward_variables_from(invoker, \"*\", [], [])\n" |
+ " print(\"$target_name\")\n" |
+ "}\n" |
+ "f(\"target\") {\n" |
+ "}\n"); |
+ ASSERT_FALSE(too_many_arguments.has_error()); |
+ err = Err(); |
+ too_many_arguments.parsed()->Execute(setup.scope(), &err); |
+ EXPECT_TRUE(err.has_error()); |
+ EXPECT_EQ("Wrong number of arguments.", err.message()); |
} |
TEST(FunctionForwardVariablesFrom, Star) { |
@@ -106,3 +176,33 @@ TEST(FunctionForwardVariablesFrom, Star) { |
EXPECT_EQ("target, 1, 2\n", setup.print_output()); |
setup.print_output().clear(); |
} |
+ |
+ |
+TEST(FunctionForwardVariablesFrom, StarWithExclusion) { |
+ Scheduler scheduler; |
+ TestWithScope setup; |
+ |
+ // Defines a template and copy all values except z value. The "*" behavior |
+ // should clobber existing variables with the same name. |
+ TestParseInput input( |
+ "template(\"a\") {\n" |
+ " x = 1000000\n" // Should be clobbered. |
+ " forward_variables_from(invoker, \"*\", [\"z\"])\n" |
+ " print(\"$target_name, $x, $y\")\n" |
+ "}\n" |
+ "a(\"target\") {\n" |
+ " x = 1\n" |
+ " y = 2\n" |
+ " z = 3\n" |
+ " print(\"$z\")\n" |
+ "}\n"); |
+ |
+ ASSERT_FALSE(input.has_error()); |
+ |
+ Err err; |
+ input.parsed()->Execute(setup.scope(), &err); |
+ ASSERT_FALSE(err.has_error()) << err.message(); |
+ |
+ EXPECT_EQ("3\ntarget, 1, 2\n", setup.print_output()); |
+ setup.print_output().clear(); |
+} |