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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « tools/gn/operators.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/operators.h" 5 #include "tools/gn/operators.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Assigning an empty list should succeed. 323 // Assigning an empty list should succeed.
324 node.SetRightToValue( 324 node.SetRightToValue(
325 Value(nullptr, std::unique_ptr<Scope>(new Scope(setup.settings())))); 325 Value(nullptr, std::unique_ptr<Scope>(new Scope(setup.settings()))));
326 node.Execute(setup.scope(), &err); 326 node.Execute(setup.scope(), &err);
327 ASSERT_FALSE(err.has_error()); 327 ASSERT_FALSE(err.has_error());
328 new_value = setup.scope()->GetValue(foo); 328 new_value = setup.scope()->GetValue(foo);
329 ASSERT_TRUE(new_value); 329 ASSERT_TRUE(new_value);
330 ASSERT_EQ(Value::SCOPE, new_value->type()); 330 ASSERT_EQ(Value::SCOPE, new_value->type());
331 ASSERT_FALSE(new_value->scope_value()->HasValues(Scope::SEARCH_CURRENT)); 331 ASSERT_FALSE(new_value->scope_value()->HasValues(Scope::SEARCH_CURRENT));
332 } 332 }
333
334 // Tests this case:
335 // foo = 1
336 // target(...) {
337 // foo += 1
338 //
339 // This should mark the outer "foo" as used, and the inner "foo" as unused.
340 TEST(Operators, PlusEqualsUsed) {
341 Err err;
342 TestWithScope setup;
343
344 // Outer "foo" definition, it should be unused.
345 const char foo[] = "foo";
346 Value old_value(nullptr, static_cast<int64_t>(1));
347 setup.scope()->SetValue(foo, old_value, nullptr);
348 EXPECT_TRUE(setup.scope()->IsSetButUnused(foo));
349
350 // Nested scope.
351 Scope nested(setup.scope());
352
353 // Run "foo += 1".
354 TestBinaryOpNode node(Token::PLUS_EQUALS, "+=");
355 node.SetLeftToIdentifier(foo);
356 node.SetRightToValue(Value(nullptr, static_cast<int64_t>(1)));
357 node.Execute(&nested, &err);
358 ASSERT_FALSE(err.has_error());
359
360 // Outer foo should be used, inner foo should not be.
361 EXPECT_FALSE(setup.scope()->IsSetButUnused(foo));
362 EXPECT_TRUE(nested.IsSetButUnused(foo));
363 }
OLDNEW
« 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