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

Unified Diff: tools/gn/operators_unittest.cc

Issue 2393853003: GN: Mark variables in nested scopes used for += and -=. (Closed)
Patch Set: Fix Created 4 years, 2 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/operators.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/operators_unittest.cc
diff --git a/tools/gn/operators_unittest.cc b/tools/gn/operators_unittest.cc
index 4fa3d114017e88883fdbd7910a6e0d855403bc38..fa163a1775823498d5677cbafab6a60c7e530928 100644
--- a/tools/gn/operators_unittest.cc
+++ b/tools/gn/operators_unittest.cc
@@ -330,3 +330,34 @@ TEST(Operators, NonemptyOverwriting) {
ASSERT_EQ(Value::SCOPE, new_value->type());
ASSERT_FALSE(new_value->scope_value()->HasValues(Scope::SEARCH_CURRENT));
}
+
+// Tests this case:
+// foo = 1
+// target(...) {
+// foo += 1
+//
+// This should mark the outer "foo" as used, and the inner "foo" as unused.
+TEST(Operators, PlusEqualsUsed) {
+ Err err;
+ TestWithScope setup;
+
+ // Outer "foo" definition, it should be unused.
+ const char foo[] = "foo";
+ Value old_value(nullptr, static_cast<int64_t>(1));
+ setup.scope()->SetValue(foo, old_value, nullptr);
+ EXPECT_TRUE(setup.scope()->IsSetButUnused(foo));
+
+ // Nested scope.
+ Scope nested(setup.scope());
+
+ // Run "foo += 1".
+ TestBinaryOpNode node(Token::PLUS_EQUALS, "+=");
+ node.SetLeftToIdentifier(foo);
+ node.SetRightToValue(Value(nullptr, static_cast<int64_t>(1)));
+ node.Execute(&nested, &err);
+ ASSERT_FALSE(err.has_error());
+
+ // Outer foo should be used, inner foo should not be.
+ EXPECT_FALSE(setup.scope()->IsSetButUnused(foo));
+ EXPECT_TRUE(nested.IsSetButUnused(foo));
+}
« no previous file with comments | « tools/gn/operators.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698