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

Unified Diff: tools/gn/function_forward_variables_from_unittest.cc

Issue 1943583002: GN: forward_variables_from shouldn't clobber vars. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/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) {
« build/toolchain/gcc_toolchain.gni ('K') | « tools/gn/function_forward_variables_from.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698