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

Unified Diff: tools/gn/scope_unittest.cc

Issue 547063004: Allow GN template collisions if they're the same. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/scope.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/scope_unittest.cc
diff --git a/tools/gn/scope_unittest.cc b/tools/gn/scope_unittest.cc
index 53d4689af0b9723c9a34ec7f1929e8cce2d34e73..97ca60afa3b1debe5875c48305071390b9217f83 100644
--- a/tools/gn/scope_unittest.cc
+++ b/tools/gn/scope_unittest.cc
@@ -6,6 +6,7 @@
#include "tools/gn/input_file.h"
#include "tools/gn/parse_tree.h"
#include "tools/gn/scope.h"
+#include "tools/gn/template.h"
#include "tools/gn/test_with_scope.h"
namespace {
@@ -34,11 +35,20 @@ TEST(Scope, NonRecursiveMergeTo) {
LiteralNode assignment;
assignment.set_value(assignment_token);
+ // Add some values to the scope.
Value old_value(&assignment, "hello");
setup.scope()->SetValue("v", old_value, &assignment);
base::StringPiece private_var_name("_private");
setup.scope()->SetValue(private_var_name, old_value, &assignment);
+ // Add some templates to the scope.
+ FunctionCallNode templ_definition;
+ scoped_refptr<Template> templ(new Template(setup.scope(), &templ_definition));
+ setup.scope()->AddTemplate("templ", templ.get());
+ scoped_refptr<Template> private_templ(
+ new Template(setup.scope(), &templ_definition));
+ setup.scope()->AddTemplate("_templ", private_templ.get());
+
// Detect collisions of values' values.
{
Scope new_scope(setup.settings());
@@ -52,6 +62,20 @@ TEST(Scope, NonRecursiveMergeTo) {
EXPECT_TRUE(err.has_error());
}
+ // Template name collisions.
+ {
+ Scope new_scope(setup.settings());
+
+ scoped_refptr<Template> new_templ(
+ new Template(&new_scope, &templ_definition));
+ new_scope.AddTemplate("templ", new_templ.get());
+
+ Err err;
+ EXPECT_FALSE(setup.scope()->NonRecursiveMergeTo(
+ &new_scope, Scope::MergeOptions(), &assignment, "error", &err));
+ EXPECT_TRUE(err.has_error());
+ }
+
// The clobber flag should just overwrite colliding values.
{
Scope new_scope(setup.settings());
@@ -70,6 +94,26 @@ TEST(Scope, NonRecursiveMergeTo) {
EXPECT_TRUE(old_value == *found_value);
}
+ // Clobber flag for templates.
+ {
+ Scope new_scope(setup.settings());
+
+ scoped_refptr<Template> new_templ(
+ new Template(&new_scope, &templ_definition));
+ new_scope.AddTemplate("templ", new_templ.get());
+ Scope::MergeOptions options;
+ options.clobber_existing = true;
+
+ Err err;
+ EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo(
+ &new_scope, options, &assignment, "error", &err));
+ EXPECT_FALSE(err.has_error());
+
+ const Template* found_value = new_scope.GetTemplate("templ");
+ ASSERT_TRUE(found_value);
+ EXPECT_TRUE(templ.get() == found_value);
+ }
+
// Don't flag values that technically collide but have the same value.
{
Scope new_scope(setup.settings());
@@ -77,14 +121,26 @@ TEST(Scope, NonRecursiveMergeTo) {
new_scope.SetValue("v", new_value, &assignment);
Err err;
- Scope::MergeOptions options;
- options.clobber_existing = true;
EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo(
- &new_scope, options, &assignment, "error", &err));
+ &new_scope, Scope::MergeOptions(), &assignment, "error", &err));
+ EXPECT_FALSE(err.has_error());
+ }
+
+ // Templates that technically collide but are the same.
+ {
+ Scope new_scope(setup.settings());
+
+ scoped_refptr<Template> new_templ(
+ new Template(&new_scope, &templ_definition));
+ new_scope.AddTemplate("templ", templ.get());
+
+ Err err;
+ EXPECT_TRUE(setup.scope()->NonRecursiveMergeTo(
+ &new_scope, Scope::MergeOptions(), &assignment, "error", &err));
EXPECT_FALSE(err.has_error());
}
- // Copy private values.
+ // Copy private values and templates.
{
Scope new_scope(setup.settings());
@@ -93,9 +149,10 @@ TEST(Scope, NonRecursiveMergeTo) {
&new_scope, Scope::MergeOptions(), &assignment, "error", &err));
EXPECT_FALSE(err.has_error());
EXPECT_TRUE(new_scope.GetValue(private_var_name));
+ EXPECT_TRUE(new_scope.GetTemplate("_templ"));
}
- // Skip private values.
+ // Skip private values and templates.
{
Scope new_scope(setup.settings());
@@ -106,6 +163,7 @@ TEST(Scope, NonRecursiveMergeTo) {
&new_scope, options, &assignment, "error", &err));
EXPECT_FALSE(err.has_error());
EXPECT_FALSE(new_scope.GetValue(private_var_name));
+ EXPECT_FALSE(new_scope.GetTemplate("_templ"));
}
// Don't mark used.
« no previous file with comments | « tools/gn/scope.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698