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..9072eba9aa125b9fd369ddd930df75a5cae9d056 |
--- /dev/null |
+++ b/tools/gn/function_forward_variables_from_unittest.cc |
@@ -0,0 +1,57 @@ |
+// 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 values out. |
+ TestParseInput input( |
+ "template(\"a\") {\n" |
+ " forward_variables_from(invoker, [\"x\", \"y\"])\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(); |
+} |
+ |
+TEST(FunctionForwardVariablesFrom, Star) { |
+ Scheduler scheduler; |
+ TestWithScope setup; |
+ |
+ // Defines a template and copy the two x and y values out. |
+ TestParseInput input( |
+ "template(\"a\") {\n" |
+ " 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(); |
+} |
Dirk Pranke
2015/08/03 19:07:20
Maybe add a test where one of the values isn't def
|