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

Unified Diff: tools/gn/function_forward_variables_from_unittest.cc

Issue 1263053003: Add forward_variables_from() and target() to GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More spelling fixes Created 5 years, 4 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/function_forward_variables_from.cc ('k') | tools/gn/function_template.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/function_forward_variables_from_unittest.cc
diff --git a/tools/gn/function_forward_variables_from_unittest.cc b/tools/gn/function_forward_variables_from_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c3dd715f4f1a8dc11585ddbe8fc08bcfcdeac791
--- /dev/null
+++ b/tools/gn/function_forward_variables_from_unittest.cc
@@ -0,0 +1,108 @@
+// 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/scheduler.h"
+#include "tools/gn/test_with_scope.h"
+
+TEST(FunctionForwardVariablesFrom, List) {
+ Scheduler scheduler;
+ TestWithScope setup;
+
+ // Defines a template and copy the two x and y, and z values out.
+ TestParseInput input(
+ "template(\"a\") {\n"
+ " forward_variables_from(invoker, [\"x\", \"y\", \"z\"])\n"
+ " assert(!defined(z))\n" // "z" should still be undefined.
+ " print(\"$target_name, $x, $y\")\n"
+ "}\n"
+ "a(\"target\") {\n"
+ " x = 1\n"
+ " y = 2\n"
+ "}\n");
+
+ ASSERT_FALSE(input.has_error());
+
+ Err err;
+ input.parsed()->Execute(setup.scope(), &err);
+ ASSERT_FALSE(err.has_error()) << err.message();
+
+ EXPECT_EQ("target, 1, 2\n", setup.print_output());
+ setup.print_output().clear();
+}
+
+TEST(FunctionForwardVariablesFrom, ErrorCases) {
+ Scheduler scheduler;
+ TestWithScope setup;
+
+ // Type check the source scope.
+ TestParseInput invalid_source(
+ "template(\"a\") {\n"
+ " forward_variables_from(42, [\"x\"])\n"
+ " print(\"$target_name\")\n" // Prevent unused var error.
+ "}\n"
+ "a(\"target\") {\n"
+ "}\n");
+ ASSERT_FALSE(invalid_source.has_error());
+ Err err;
+ invalid_source.parsed()->Execute(setup.scope(), &err);
+ EXPECT_TRUE(err.has_error());
+ EXPECT_EQ("Expected an identifier for the scope.", err.message());
+
+ // Type check the list. We need to use a new template name each time since
+ // all of these invocations are executing in sequence in the same scope.
+ TestParseInput invalid_list(
+ "template(\"b\") {\n"
+ " forward_variables_from(invoker, 42)\n"
+ " print(\"$target_name\")\n"
+ "}\n"
+ "b(\"target\") {\n"
+ "}\n");
+ ASSERT_FALSE(invalid_list.has_error());
+ err = Err();
+ invalid_list.parsed()->Execute(setup.scope(), &err);
+ EXPECT_TRUE(err.has_error());
+ EXPECT_EQ("Not a valid list of variables to copy.", err.message());
+
+ // Programmatic values should error.
+ TestParseInput prog(
+ "template(\"c\") {\n"
+ " forward_variables_from(invoker, [\"root_out_dir\"])\n"
+ " print(\"$target_name\")\n"
+ "}\n"
+ "c(\"target\") {\n"
+ "}\n");
+ ASSERT_FALSE(prog.has_error());
+ err = Err();
+ prog.parsed()->Execute(setup.scope(), &err);
+ EXPECT_TRUE(err.has_error());
+ EXPECT_EQ("This value can't be forwarded.", err.message());
+}
+
+TEST(FunctionForwardVariablesFrom, Star) {
+ Scheduler scheduler;
+ TestWithScope setup;
+
+ // Defines a template and copy the two x and y values out. The "*" behavior
+ // should clobber existing variables with the same name.
+ TestParseInput input(
+ "template(\"a\") {\n"
+ " x = 1000000\n" // Should be clobbered.
+ " forward_variables_from(invoker, \"*\")\n"
+ " print(\"$target_name, $x, $y\")\n"
+ "}\n"
+ "a(\"target\") {\n"
+ " x = 1\n"
+ " y = 2\n"
+ "}\n");
+
+ ASSERT_FALSE(input.has_error());
+
+ Err err;
+ input.parsed()->Execute(setup.scope(), &err);
+ ASSERT_FALSE(err.has_error()) << err.message();
+
+ EXPECT_EQ("target, 1, 2\n", setup.print_output());
+ setup.print_output().clear();
+}
« no previous file with comments | « tools/gn/function_forward_variables_from.cc ('k') | tools/gn/function_template.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698