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

Unified Diff: tools/gn/args_unittest.cc

Issue 2092623002: GN: Don't define argument overrides globally (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments 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
« no previous file with comments | « tools/gn/args.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/args_unittest.cc
diff --git a/tools/gn/args_unittest.cc b/tools/gn/args_unittest.cc
index 098f3dec8504975a55a136204f196cc12b74bd4c..cf51036fb66ea4af26f27bacda6078ffbfb965e7 100644
--- a/tools/gn/args_unittest.cc
+++ b/tools/gn/args_unittest.cc
@@ -39,3 +39,43 @@ TEST(ArgsTest, VerifyAllOverridesUsed) {
args.AddArgOverride("c", Value(nullptr, true));
EXPECT_FALSE(args.VerifyAllOverridesUsed(&err));
}
+
+// Ensure that arg overrides get only set after the they were declared.
+TEST(ArgsTest, VerifyOverrideScope) {
+ TestWithScope setup;
+ Args args;
+ Err err;
+
+ args.AddArgOverride("a", Value(nullptr, "avalue"));
+ args.AddArgOverride("current_os", Value(nullptr, "theiros"));
+
+ Scope::KeyValueMap toolchain_overrides;
+ toolchain_overrides["b"] = Value(nullptr, "bvalue");
+ toolchain_overrides["current_os"] = Value(nullptr, "myos");
+ args.SetupRootScope(setup.scope(), toolchain_overrides);
+
+ // Overrides of arguments not yet declared aren't applied yet.
+ EXPECT_EQ(nullptr, setup.scope()->GetValue("a"));
+ EXPECT_EQ(nullptr, setup.scope()->GetValue("b"));
+
+ // |current_os| is a system var. and already declared.
+ // Thus it should have our override value.
+ ASSERT_NE(nullptr, setup.scope()->GetValue("current_os"));
+ EXPECT_EQ(Value(nullptr, "myos"), *setup.scope()->GetValue("current_os"));
+
+ Scope::KeyValueMap key_value_map1;
+ key_value_map1["a"] = Value(nullptr, "avalue2");
+ key_value_map1["b"] = Value(nullptr, "bvalue2");
+ key_value_map1["c"] = Value(nullptr, "cvalue2");
+ EXPECT_TRUE(args.DeclareArgs(key_value_map1, setup.scope(), &err));
+
+ ASSERT_NE(nullptr, setup.scope()->GetValue("a"));
+ EXPECT_EQ(Value(nullptr, "avalue"), *setup.scope()->GetValue("a"));
+
+ ASSERT_NE(nullptr, setup.scope()->GetValue("b"));
+ EXPECT_EQ(Value(nullptr, "bvalue"), *setup.scope()->GetValue("b"));
+
+ // This wasn't overwritten, so it should have the default value.
+ ASSERT_NE(nullptr, setup.scope()->GetValue("c"));
+ EXPECT_EQ(Value(nullptr, "cvalue2"), *setup.scope()->GetValue("c"));
+}
« no previous file with comments | « tools/gn/args.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698