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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/scheduler.h"
7 #include "tools/gn/test_with_scope.h"
8
9 TEST(FunctionForwardVariablesFrom, List) {
10 Scheduler scheduler;
11 TestWithScope setup;
12
13 // Defines a template and copy the two x and y, and z values out.
14 TestParseInput input(
15 "template(\"a\") {\n"
16 " forward_variables_from(invoker, [\"x\", \"y\", \"z\"])\n"
17 " assert(!defined(z))\n" // "z" should still be undefined.
18 " print(\"$target_name, $x, $y\")\n"
19 "}\n"
20 "a(\"target\") {\n"
21 " x = 1\n"
22 " y = 2\n"
23 "}\n");
24
25 ASSERT_FALSE(input.has_error());
26
27 Err err;
28 input.parsed()->Execute(setup.scope(), &err);
29 ASSERT_FALSE(err.has_error()) << err.message();
30
31 EXPECT_EQ("target, 1, 2\n", setup.print_output());
32 setup.print_output().clear();
33 }
34
35 TEST(FunctionForwardVariablesFrom, ErrorCases) {
36 Scheduler scheduler;
37 TestWithScope setup;
38
39 // Type check the source scope.
40 TestParseInput invalid_source(
41 "template(\"a\") {\n"
42 " forward_variables_from(42, [\"x\"])\n"
43 " print(\"$target_name\")\n" // Prevent unused var error.
44 "}\n"
45 "a(\"target\") {\n"
46 "}\n");
47 ASSERT_FALSE(invalid_source.has_error());
48 Err err;
49 invalid_source.parsed()->Execute(setup.scope(), &err);
50 EXPECT_TRUE(err.has_error());
51 EXPECT_EQ("Expected an identifier for the scope.", err.message());
52
53 // Type check the list. We need to use a new template name each time since
54 // all of these invocations are executing in sequence in the same scope.
55 TestParseInput invalid_list(
56 "template(\"b\") {\n"
57 " forward_variables_from(invoker, 42)\n"
58 " print(\"$target_name\")\n"
59 "}\n"
60 "b(\"target\") {\n"
61 "}\n");
62 ASSERT_FALSE(invalid_list.has_error());
63 err = Err();
64 invalid_list.parsed()->Execute(setup.scope(), &err);
65 EXPECT_TRUE(err.has_error());
66 EXPECT_EQ("Not a valid list of variables to copy.", err.message());
67
68 // Programmatic values should error.
69 TestParseInput prog(
70 "template(\"c\") {\n"
71 " forward_variables_from(invoker, [\"root_out_dir\"])\n"
72 " print(\"$target_name\")\n"
73 "}\n"
74 "c(\"target\") {\n"
75 "}\n");
76 ASSERT_FALSE(prog.has_error());
77 err = Err();
78 prog.parsed()->Execute(setup.scope(), &err);
79 EXPECT_TRUE(err.has_error());
80 EXPECT_EQ("This value can't be forwarded.", err.message());
81 }
82
83 TEST(FunctionForwardVariablesFrom, Star) {
84 Scheduler scheduler;
85 TestWithScope setup;
86
87 // Defines a template and copy the two x and y values out. The "*" behavior
88 // should clobber existing variables with the same name.
89 TestParseInput input(
90 "template(\"a\") {\n"
91 " x = 1000000\n" // Should be clobbered.
92 " forward_variables_from(invoker, \"*\")\n"
93 " print(\"$target_name, $x, $y\")\n"
94 "}\n"
95 "a(\"target\") {\n"
96 " x = 1\n"
97 " y = 2\n"
98 "}\n");
99
100 ASSERT_FALSE(input.has_error());
101
102 Err err;
103 input.parsed()->Execute(setup.scope(), &err);
104 ASSERT_FALSE(err.has_error()) << err.message();
105
106 EXPECT_EQ("target, 1, 2\n", setup.print_output());
107 setup.print_output().clear();
108 }
OLDNEW
« 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