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

Unified Diff: tools/gn/config_unittest.cc

Issue 1342183003: Allow GN configs to have sub-configs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
Index: tools/gn/config_unittest.cc
diff --git a/tools/gn/config_unittest.cc b/tools/gn/config_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2c345b97daec25d5f123fb3c163d4d6e48d735d9
--- /dev/null
+++ b/tools/gn/config_unittest.cc
@@ -0,0 +1,85 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "tools/gn/config.h"
+#include "tools/gn/test_with_scope.h"
+
+// Tests that the "resolved" values are the same as "own" values when there
+// are no child configs.
+TEST(Config, ResolvedNoChildren) {
+ TestWithScope setup;
+ Err err;
+
+ Config config(setup.settings(), Label(SourceDir("//foo/"), "bar"));
+ config.own_values().defines().push_back("FOO");
+ ASSERT_TRUE(config.OnResolved(&err));
+
+ // The resolved values should be the same as the value we put in to
+ // own_values().
+ ASSERT_EQ(1u, config.resolved_values().defines().size());
+ EXPECT_EQ("FOO", config.resolved_values().defines()[0]);
+
+ // As an optimization, the string should actually refer to the original. This
+ // isn't required to pass for semantic correctness, though.
+ EXPECT_TRUE(&config.own_values() == &config.resolved_values());
+}
+
+// Tests that child configs are resolved in the correct order.
+TEST(Config, ResolvedChildren) {
+ TestWithScope setup;
+ Err err;
+
+ Config child1(setup.settings(), Label(SourceDir("//foo/"), "1"));
+ child1.own_values().defines().push_back("ONE");
+ ASSERT_TRUE(child1.OnResolved(&err));
+
+ Config child2(setup.settings(), Label(SourceDir("//foo/"), "2"));
+ child2.own_values().defines().push_back("TWO");
+ ASSERT_TRUE(child2.OnResolved(&err));
+
+ Config config(setup.settings(), Label(SourceDir("//foo/"), "bar"));
+ config.own_values().defines().push_back("FOO");
+ config.configs().push_back(LabelConfigPair(&child1));
+ config.configs().push_back(LabelConfigPair(&child2));
+ ASSERT_TRUE(config.OnResolved(&err));
+
+ // The resolved values should be the same as the value we put in to
+ // own_values().
+ ASSERT_EQ(3u, config.resolved_values().defines().size());
+ EXPECT_EQ("FOO", config.resolved_values().defines()[0]);
+ EXPECT_EQ("ONE", config.resolved_values().defines()[1]);
+ EXPECT_EQ("TWO", config.resolved_values().defines()[2]);
+
+ // The "own" values should be unchanged.
+ ASSERT_EQ(1u, config.own_values().defines().size());
+ EXPECT_EQ("FOO", config.own_values().defines()[0]);
+}
+
+// Tests that doubly-nested configs are resolved properly.
+TEST(Config, DoublyNested) {
Dirk Pranke 2015/09/15 21:31:31 same comment.
+ TestWithScope setup;
+ Err err;
+
+ // Set up first -> middle -> last configs.
+ Config last(setup.settings(), Label(SourceDir("//foo/"), "last"));
+ last.own_values().defines().push_back("LAST");
+ ASSERT_TRUE(last.OnResolved(&err));
+
+ Config middle(setup.settings(), Label(SourceDir("//foo/"), "middle"));
+ middle.own_values().defines().push_back("MIDDLE");
+ middle.configs().push_back(LabelConfigPair(&last));
+ ASSERT_TRUE(middle.OnResolved(&err));
+
+ Config first(setup.settings(), Label(SourceDir("//foo/"), "first"));
+ first.own_values().defines().push_back("FIRST");
+ first.configs().push_back(LabelConfigPair(&middle));
+ ASSERT_TRUE(first.OnResolved(&err));
+
+ // Check final resolved defines on "first".
+ ASSERT_EQ(3u, first.resolved_values().defines().size());
+ EXPECT_EQ("FIRST", first.resolved_values().defines()[0]);
+ EXPECT_EQ("MIDDLE", first.resolved_values().defines()[1]);
+ EXPECT_EQ("LAST", first.resolved_values().defines()[2]);
+}

Powered by Google App Engine
This is Rietveld 408576698