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 e5137a48b266cc8c5bd161caca2ab51b2f9cb5d3..2e6f5a2800ccf377019ffa6ca47daff9e65dbb16 100644 |
--- a/tools/gn/function_forward_variables_from_unittest.cc |
+++ b/tools/gn/function_forward_variables_from_unittest.cc |
@@ -8,28 +8,46 @@ |
TEST(FunctionForwardVariablesFrom, List) { |
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\"])\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" |
- "}\n"); |
- |
- ASSERT_FALSE(input.has_error()); |
- |
Err err; |
- input.parsed()->Execute(setup.scope(), &err); |
- ASSERT_FALSE(err.has_error()) << err.message(); |
- |
- EXPECT_EQ("target, 1, 2\n", setup.print_output()); |
- setup.print_output().clear(); |
+ std::string program = |
+ "template(\"a\") {\n" |
+ " forward_variables_from(invoker, [\"x\", \"y\", \"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" |
+ "}\n"; |
+ |
+ { |
+ TestWithScope setup; |
+ |
+ // Defines a template and copy the two x and y, and z values out. |
+ TestParseInput input(program); |
+ ASSERT_FALSE(input.has_error()); |
+ |
+ input.parsed()->Execute(setup.scope(), &err); |
+ ASSERT_FALSE(err.has_error()) << err.message(); |
+ |
+ EXPECT_EQ("target, 1, 2\n", setup.print_output()); |
+ setup.print_output().clear(); |
+ } |
+ |
+ { |
+ TestWithScope setup; |
+ |
+ // Test that the same input but forwarding a variable with the name of |
+ // something in the given scope throws an error rather than clobbering it. |
+ // This uses the same known-good program as before, but adds another |
+ // variable in the scope before it. |
+ TestParseInput clobber("x = 1\n" + program); |
+ ASSERT_FALSE(clobber.has_error()); |
+ |
+ clobber.parsed()->Execute(setup.scope(), &err); |
+ ASSERT_TRUE(err.has_error()); // Should thow a clobber error. |
+ EXPECT_EQ("Clobbering existing value.", err.message()); |
+ } |
} |
TEST(FunctionForwardVariablesFrom, ListWithExclusion) { |