OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "tools/gn/build_settings.h" | 6 #include "tools/gn/build_settings.h" |
7 #include "tools/gn/config.h" | 7 #include "tools/gn/config.h" |
8 #include "tools/gn/settings.h" | 8 #include "tools/gn/settings.h" |
9 #include "tools/gn/target.h" | 9 #include "tools/gn/target.h" |
| 10 #include "tools/gn/test_with_scope.h" |
10 #include "tools/gn/toolchain.h" | 11 #include "tools/gn/toolchain.h" |
11 | 12 |
12 namespace { | |
13 | |
14 class TargetTest : public testing::Test { | |
15 public: | |
16 TargetTest() | |
17 : build_settings_(), | |
18 settings_(&build_settings_, std::string()), | |
19 toolchain_(&settings_, Label(SourceDir("//tc/"), "tc")) { | |
20 settings_.set_toolchain_label(toolchain_.label()); | |
21 } | |
22 virtual ~TargetTest() { | |
23 } | |
24 | |
25 protected: | |
26 BuildSettings build_settings_; | |
27 Settings settings_; | |
28 Toolchain toolchain_; | |
29 }; | |
30 | |
31 } // namespace | |
32 | |
33 // Tests that depending on a group is like depending directly on the group's | 13 // Tests that depending on a group is like depending directly on the group's |
34 // deps. | 14 // deps. |
35 TEST_F(TargetTest, GroupDeps) { | 15 TEST(Target, GroupDeps) { |
| 16 TestWithScope setup; |
| 17 |
36 // Two low-level targets. | 18 // Two low-level targets. |
37 Target x(&settings_, Label(SourceDir("//component/"), "x")); | 19 Target x(setup.settings(), Label(SourceDir("//component/"), "x")); |
38 Target y(&settings_, Label(SourceDir("//component/"), "y")); | 20 x.set_output_type(Target::STATIC_LIBRARY); |
| 21 x.SetToolchain(setup.toolchain()); |
| 22 x.OnResolved(); |
| 23 Target y(setup.settings(), Label(SourceDir("//component/"), "y")); |
| 24 y.set_output_type(Target::STATIC_LIBRARY); |
| 25 y.SetToolchain(setup.toolchain()); |
| 26 y.OnResolved(); |
39 | 27 |
40 // Make a group for both x and y. | 28 // Make a group for both x and y. |
41 Target g(&settings_, Label(SourceDir("//group/"), "g")); | 29 Target g(setup.settings(), Label(SourceDir("//group/"), "g")); |
42 g.set_output_type(Target::GROUP); | 30 g.set_output_type(Target::GROUP); |
43 g.deps().push_back(LabelTargetPair(&x)); | 31 g.deps().push_back(LabelTargetPair(&x)); |
44 g.deps().push_back(LabelTargetPair(&y)); | 32 g.deps().push_back(LabelTargetPair(&y)); |
45 | 33 |
46 // Random placeholder target so we can see the group's deps get inserted at | 34 // Random placeholder target so we can see the group's deps get inserted at |
47 // the right place. | 35 // the right place. |
48 Target b(&settings_, Label(SourceDir("//app/"), "b")); | 36 Target b(setup.settings(), Label(SourceDir("//app/"), "b")); |
| 37 b.set_output_type(Target::STATIC_LIBRARY); |
| 38 b.SetToolchain(setup.toolchain()); |
| 39 b.OnResolved(); |
49 | 40 |
50 // Make a target depending on the group and "b". OnResolved will expand. | 41 // Make a target depending on the group and "b". OnResolved will expand. |
51 Target a(&settings_, Label(SourceDir("//app/"), "a")); | 42 Target a(setup.settings(), Label(SourceDir("//app/"), "a")); |
52 a.set_output_type(Target::EXECUTABLE); | 43 a.set_output_type(Target::EXECUTABLE); |
53 a.deps().push_back(LabelTargetPair(&g)); | 44 a.deps().push_back(LabelTargetPair(&g)); |
54 a.deps().push_back(LabelTargetPair(&b)); | 45 a.deps().push_back(LabelTargetPair(&b)); |
| 46 a.SetToolchain(setup.toolchain()); |
55 a.OnResolved(); | 47 a.OnResolved(); |
56 | 48 |
57 // The group's deps should be inserted after the group itself in the deps | 49 // The group's deps should be inserted after the group itself in the deps |
58 // list, so we should get "g, x, y, b" | 50 // list, so we should get "g, x, y, b" |
59 ASSERT_EQ(4u, a.deps().size()); | 51 ASSERT_EQ(4u, a.deps().size()); |
60 EXPECT_EQ(&g, a.deps()[0].ptr); | 52 EXPECT_EQ(&g, a.deps()[0].ptr); |
61 EXPECT_EQ(&x, a.deps()[1].ptr); | 53 EXPECT_EQ(&x, a.deps()[1].ptr); |
62 EXPECT_EQ(&y, a.deps()[2].ptr); | 54 EXPECT_EQ(&y, a.deps()[2].ptr); |
63 EXPECT_EQ(&b, a.deps()[3].ptr); | 55 EXPECT_EQ(&b, a.deps()[3].ptr); |
64 } | 56 } |
65 | 57 |
66 // Tests that lib[_dir]s are inherited across deps boundaries for static | 58 // Tests that lib[_dir]s are inherited across deps boundaries for static |
67 // libraries but not executables. | 59 // libraries but not executables. |
68 TEST_F(TargetTest, LibInheritance) { | 60 TEST(Target, LibInheritance) { |
| 61 TestWithScope setup; |
| 62 |
69 const std::string lib("foo"); | 63 const std::string lib("foo"); |
70 const SourceDir libdir("/foo_dir/"); | 64 const SourceDir libdir("/foo_dir/"); |
71 | 65 |
72 // Leaf target with ldflags set. | 66 // Leaf target with ldflags set. |
73 Target z(&settings_, Label(SourceDir("//foo/"), "z")); | 67 Target z(setup.settings(), Label(SourceDir("//foo/"), "z")); |
74 z.set_output_type(Target::STATIC_LIBRARY); | 68 z.set_output_type(Target::STATIC_LIBRARY); |
75 z.config_values().libs().push_back(lib); | 69 z.config_values().libs().push_back(lib); |
76 z.config_values().lib_dirs().push_back(libdir); | 70 z.config_values().lib_dirs().push_back(libdir); |
| 71 z.SetToolchain(setup.toolchain()); |
77 z.OnResolved(); | 72 z.OnResolved(); |
78 | 73 |
79 // All lib[_dir]s should be set when target is resolved. | 74 // All lib[_dir]s should be set when target is resolved. |
80 ASSERT_EQ(1u, z.all_libs().size()); | 75 ASSERT_EQ(1u, z.all_libs().size()); |
81 EXPECT_EQ(lib, z.all_libs()[0]); | 76 EXPECT_EQ(lib, z.all_libs()[0]); |
82 ASSERT_EQ(1u, z.all_lib_dirs().size()); | 77 ASSERT_EQ(1u, z.all_lib_dirs().size()); |
83 EXPECT_EQ(libdir, z.all_lib_dirs()[0]); | 78 EXPECT_EQ(libdir, z.all_lib_dirs()[0]); |
84 | 79 |
85 // Shared library target should inherit the libs from the static library | 80 // Shared library target should inherit the libs from the static library |
86 // and its own. Its own flag should be before the inherited one. | 81 // and its own. Its own flag should be before the inherited one. |
87 const std::string second_lib("bar"); | 82 const std::string second_lib("bar"); |
88 const SourceDir second_libdir("/bar_dir/"); | 83 const SourceDir second_libdir("/bar_dir/"); |
89 Target shared(&settings_, Label(SourceDir("//foo/"), "shared")); | 84 Target shared(setup.settings(), Label(SourceDir("//foo/"), "shared")); |
90 shared.set_output_type(Target::SHARED_LIBRARY); | 85 shared.set_output_type(Target::SHARED_LIBRARY); |
91 shared.config_values().libs().push_back(second_lib); | 86 shared.config_values().libs().push_back(second_lib); |
92 shared.config_values().lib_dirs().push_back(second_libdir); | 87 shared.config_values().lib_dirs().push_back(second_libdir); |
93 shared.deps().push_back(LabelTargetPair(&z)); | 88 shared.deps().push_back(LabelTargetPair(&z)); |
| 89 shared.SetToolchain(setup.toolchain()); |
94 shared.OnResolved(); | 90 shared.OnResolved(); |
95 | 91 |
96 ASSERT_EQ(2u, shared.all_libs().size()); | 92 ASSERT_EQ(2u, shared.all_libs().size()); |
97 EXPECT_EQ(second_lib, shared.all_libs()[0]); | 93 EXPECT_EQ(second_lib, shared.all_libs()[0]); |
98 EXPECT_EQ(lib, shared.all_libs()[1]); | 94 EXPECT_EQ(lib, shared.all_libs()[1]); |
99 ASSERT_EQ(2u, shared.all_lib_dirs().size()); | 95 ASSERT_EQ(2u, shared.all_lib_dirs().size()); |
100 EXPECT_EQ(second_libdir, shared.all_lib_dirs()[0]); | 96 EXPECT_EQ(second_libdir, shared.all_lib_dirs()[0]); |
101 EXPECT_EQ(libdir, shared.all_lib_dirs()[1]); | 97 EXPECT_EQ(libdir, shared.all_lib_dirs()[1]); |
102 | 98 |
103 // Executable target shouldn't get either by depending on shared. | 99 // Executable target shouldn't get either by depending on shared. |
104 Target exec(&settings_, Label(SourceDir("//foo/"), "exec")); | 100 Target exec(setup.settings(), Label(SourceDir("//foo/"), "exec")); |
105 exec.set_output_type(Target::EXECUTABLE); | 101 exec.set_output_type(Target::EXECUTABLE); |
106 exec.deps().push_back(LabelTargetPair(&shared)); | 102 exec.deps().push_back(LabelTargetPair(&shared)); |
| 103 exec.SetToolchain(setup.toolchain()); |
107 exec.OnResolved(); | 104 exec.OnResolved(); |
108 EXPECT_EQ(0u, exec.all_libs().size()); | 105 EXPECT_EQ(0u, exec.all_libs().size()); |
109 EXPECT_EQ(0u, exec.all_lib_dirs().size()); | 106 EXPECT_EQ(0u, exec.all_lib_dirs().size()); |
110 } | 107 } |
111 | 108 |
112 // Test all/direct_dependent_configs inheritance, and | 109 // Test all/direct_dependent_configs inheritance, and |
113 // forward_dependent_configs_from | 110 // forward_dependent_configs_from |
114 TEST_F(TargetTest, DependentConfigs) { | 111 TEST(Target, DependentConfigs) { |
| 112 TestWithScope setup; |
| 113 |
115 // Set up a dependency chain of a -> b -> c | 114 // Set up a dependency chain of a -> b -> c |
116 Target a(&settings_, Label(SourceDir("//foo/"), "a")); | 115 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); |
117 a.set_output_type(Target::EXECUTABLE); | 116 a.set_output_type(Target::EXECUTABLE); |
118 Target b(&settings_, Label(SourceDir("//foo/"), "b")); | 117 a.SetToolchain(setup.toolchain()); |
| 118 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); |
119 b.set_output_type(Target::STATIC_LIBRARY); | 119 b.set_output_type(Target::STATIC_LIBRARY); |
120 Target c(&settings_, Label(SourceDir("//foo/"), "c")); | 120 b.SetToolchain(setup.toolchain()); |
| 121 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); |
121 c.set_output_type(Target::STATIC_LIBRARY); | 122 c.set_output_type(Target::STATIC_LIBRARY); |
| 123 c.SetToolchain(setup.toolchain()); |
122 a.deps().push_back(LabelTargetPair(&b)); | 124 a.deps().push_back(LabelTargetPair(&b)); |
123 b.deps().push_back(LabelTargetPair(&c)); | 125 b.deps().push_back(LabelTargetPair(&c)); |
124 | 126 |
125 // Normal non-inherited config. | 127 // Normal non-inherited config. |
126 Config config(&settings_, Label(SourceDir("//foo/"), "config")); | 128 Config config(setup.settings(), Label(SourceDir("//foo/"), "config")); |
127 c.configs().push_back(LabelConfigPair(&config)); | 129 c.configs().push_back(LabelConfigPair(&config)); |
128 | 130 |
129 // All dependent config. | 131 // All dependent config. |
130 Config all(&settings_, Label(SourceDir("//foo/"), "all")); | 132 Config all(setup.settings(), Label(SourceDir("//foo/"), "all")); |
131 c.all_dependent_configs().push_back(LabelConfigPair(&all)); | 133 c.all_dependent_configs().push_back(LabelConfigPair(&all)); |
132 | 134 |
133 // Direct dependent config. | 135 // Direct dependent config. |
134 Config direct(&settings_, Label(SourceDir("//foo/"), "direct")); | 136 Config direct(setup.settings(), Label(SourceDir("//foo/"), "direct")); |
135 c.direct_dependent_configs().push_back(LabelConfigPair(&direct)); | 137 c.direct_dependent_configs().push_back(LabelConfigPair(&direct)); |
136 | 138 |
137 c.OnResolved(); | 139 c.OnResolved(); |
138 b.OnResolved(); | 140 b.OnResolved(); |
139 a.OnResolved(); | 141 a.OnResolved(); |
140 | 142 |
141 // B should have gotten both dependent configs from C. | 143 // B should have gotten both dependent configs from C. |
142 ASSERT_EQ(2u, b.configs().size()); | 144 ASSERT_EQ(2u, b.configs().size()); |
143 EXPECT_EQ(&all, b.configs()[0].ptr); | 145 EXPECT_EQ(&all, b.configs()[0].ptr); |
144 EXPECT_EQ(&direct, b.configs()[1].ptr); | 146 EXPECT_EQ(&direct, b.configs()[1].ptr); |
145 ASSERT_EQ(1u, b.all_dependent_configs().size()); | 147 ASSERT_EQ(1u, b.all_dependent_configs().size()); |
146 EXPECT_EQ(&all, b.all_dependent_configs()[0].ptr); | 148 EXPECT_EQ(&all, b.all_dependent_configs()[0].ptr); |
147 | 149 |
148 // A should have just gotten the "all" dependent config from C. | 150 // A should have just gotten the "all" dependent config from C. |
149 ASSERT_EQ(1u, a.configs().size()); | 151 ASSERT_EQ(1u, a.configs().size()); |
150 EXPECT_EQ(&all, a.configs()[0].ptr); | 152 EXPECT_EQ(&all, a.configs()[0].ptr); |
151 EXPECT_EQ(&all, a.all_dependent_configs()[0].ptr); | 153 EXPECT_EQ(&all, a.all_dependent_configs()[0].ptr); |
152 | 154 |
153 // Making an an alternate A and B with B forwarding the direct dependents. | 155 // Making an an alternate A and B with B forwarding the direct dependents. |
154 Target a_fwd(&settings_, Label(SourceDir("//foo/"), "a_fwd")); | 156 Target a_fwd(setup.settings(), Label(SourceDir("//foo/"), "a_fwd")); |
155 a_fwd.set_output_type(Target::EXECUTABLE); | 157 a_fwd.set_output_type(Target::EXECUTABLE); |
156 Target b_fwd(&settings_, Label(SourceDir("//foo/"), "b_fwd")); | 158 a_fwd.SetToolchain(setup.toolchain()); |
| 159 Target b_fwd(setup.settings(), Label(SourceDir("//foo/"), "b_fwd")); |
157 b_fwd.set_output_type(Target::STATIC_LIBRARY); | 160 b_fwd.set_output_type(Target::STATIC_LIBRARY); |
| 161 b_fwd.SetToolchain(setup.toolchain()); |
158 a_fwd.deps().push_back(LabelTargetPair(&b_fwd)); | 162 a_fwd.deps().push_back(LabelTargetPair(&b_fwd)); |
159 b_fwd.deps().push_back(LabelTargetPair(&c)); | 163 b_fwd.deps().push_back(LabelTargetPair(&c)); |
160 b_fwd.forward_dependent_configs().push_back(LabelTargetPair(&c)); | 164 b_fwd.forward_dependent_configs().push_back(LabelTargetPair(&c)); |
161 | 165 |
162 b_fwd.OnResolved(); | 166 b_fwd.OnResolved(); |
163 a_fwd.OnResolved(); | 167 a_fwd.OnResolved(); |
164 | 168 |
165 // A_fwd should now have both configs. | 169 // A_fwd should now have both configs. |
166 ASSERT_EQ(2u, a_fwd.configs().size()); | 170 ASSERT_EQ(2u, a_fwd.configs().size()); |
167 EXPECT_EQ(&all, a_fwd.configs()[0].ptr); | 171 EXPECT_EQ(&all, a_fwd.configs()[0].ptr); |
168 EXPECT_EQ(&direct, a_fwd.configs()[1].ptr); | 172 EXPECT_EQ(&direct, a_fwd.configs()[1].ptr); |
169 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); | 173 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); |
170 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); | 174 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); |
171 } | 175 } |
172 | 176 |
173 // Tests that forward_dependent_configs_from works for groups, forwarding the | 177 // Tests that forward_dependent_configs_from works for groups, forwarding the |
174 // group's deps' dependent configs. | 178 // group's deps' dependent configs. |
175 TEST_F(TargetTest, ForwardDependentConfigsFromGroups) { | 179 TEST(Target, ForwardDependentConfigsFromGroups) { |
176 Target a(&settings_, Label(SourceDir("//foo/"), "a")); | 180 TestWithScope setup; |
| 181 |
| 182 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); |
177 a.set_output_type(Target::EXECUTABLE); | 183 a.set_output_type(Target::EXECUTABLE); |
178 Target b(&settings_, Label(SourceDir("//foo/"), "b")); | 184 a.SetToolchain(setup.toolchain()); |
| 185 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); |
179 b.set_output_type(Target::GROUP); | 186 b.set_output_type(Target::GROUP); |
180 Target c(&settings_, Label(SourceDir("//foo/"), "c")); | 187 b.SetToolchain(setup.toolchain()); |
| 188 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); |
181 c.set_output_type(Target::STATIC_LIBRARY); | 189 c.set_output_type(Target::STATIC_LIBRARY); |
| 190 c.SetToolchain(setup.toolchain()); |
182 a.deps().push_back(LabelTargetPair(&b)); | 191 a.deps().push_back(LabelTargetPair(&b)); |
183 b.deps().push_back(LabelTargetPair(&c)); | 192 b.deps().push_back(LabelTargetPair(&c)); |
184 | 193 |
185 // Direct dependent config on C. | 194 // Direct dependent config on C. |
186 Config direct(&settings_, Label(SourceDir("//foo/"), "direct")); | 195 Config direct(setup.settings(), Label(SourceDir("//foo/"), "direct")); |
187 c.direct_dependent_configs().push_back(LabelConfigPair(&direct)); | 196 c.direct_dependent_configs().push_back(LabelConfigPair(&direct)); |
188 | 197 |
189 // A forwards the dependent configs from B. | 198 // A forwards the dependent configs from B. |
190 a.forward_dependent_configs().push_back(LabelTargetPair(&b)); | 199 a.forward_dependent_configs().push_back(LabelTargetPair(&b)); |
191 | 200 |
192 c.OnResolved(); | 201 c.OnResolved(); |
193 b.OnResolved(); | 202 b.OnResolved(); |
194 a.OnResolved(); | 203 a.OnResolved(); |
195 | 204 |
196 // The config should now be on A, and in A's direct dependent configs. | 205 // The config should now be on A, and in A's direct dependent configs. |
197 ASSERT_EQ(1u, a.configs().size()); | 206 ASSERT_EQ(1u, a.configs().size()); |
198 ASSERT_EQ(&direct, a.configs()[0].ptr); | 207 ASSERT_EQ(&direct, a.configs()[0].ptr); |
199 ASSERT_EQ(1u, a.direct_dependent_configs().size()); | 208 ASSERT_EQ(1u, a.direct_dependent_configs().size()); |
200 ASSERT_EQ(&direct, a.direct_dependent_configs()[0].ptr); | 209 ASSERT_EQ(&direct, a.direct_dependent_configs()[0].ptr); |
201 } | 210 } |
202 | 211 |
203 TEST_F(TargetTest, InheritLibs) { | 212 TEST(Target, InheritLibs) { |
| 213 TestWithScope setup; |
| 214 |
204 // Create a dependency chain: | 215 // Create a dependency chain: |
205 // A (executable) -> B (shared lib) -> C (static lib) -> D (source set) | 216 // A (executable) -> B (shared lib) -> C (static lib) -> D (source set) |
206 Target a(&settings_, Label(SourceDir("//foo/"), "a")); | 217 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); |
207 a.set_output_type(Target::EXECUTABLE); | 218 a.set_output_type(Target::EXECUTABLE); |
208 Target b(&settings_, Label(SourceDir("//foo/"), "b")); | 219 a.SetToolchain(setup.toolchain()); |
| 220 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); |
209 b.set_output_type(Target::SHARED_LIBRARY); | 221 b.set_output_type(Target::SHARED_LIBRARY); |
210 Target c(&settings_, Label(SourceDir("//foo/"), "c")); | 222 b.SetToolchain(setup.toolchain()); |
| 223 Target c(setup.settings(), Label(SourceDir("//foo/"), "c")); |
211 c.set_output_type(Target::STATIC_LIBRARY); | 224 c.set_output_type(Target::STATIC_LIBRARY); |
212 Target d(&settings_, Label(SourceDir("//foo/"), "d")); | 225 c.SetToolchain(setup.toolchain()); |
| 226 Target d(setup.settings(), Label(SourceDir("//foo/"), "d")); |
213 d.set_output_type(Target::SOURCE_SET); | 227 d.set_output_type(Target::SOURCE_SET); |
| 228 d.SetToolchain(setup.toolchain()); |
214 a.deps().push_back(LabelTargetPair(&b)); | 229 a.deps().push_back(LabelTargetPair(&b)); |
215 b.deps().push_back(LabelTargetPair(&c)); | 230 b.deps().push_back(LabelTargetPair(&c)); |
216 c.deps().push_back(LabelTargetPair(&d)); | 231 c.deps().push_back(LabelTargetPair(&d)); |
217 | 232 |
218 d.OnResolved(); | 233 d.OnResolved(); |
219 c.OnResolved(); | 234 c.OnResolved(); |
220 b.OnResolved(); | 235 b.OnResolved(); |
221 a.OnResolved(); | 236 a.OnResolved(); |
222 | 237 |
223 // C should have D in its inherited libs. | 238 // C should have D in its inherited libs. |
224 const UniqueVector<const Target*>& c_inherited = c.inherited_libraries(); | 239 const UniqueVector<const Target*>& c_inherited = c.inherited_libraries(); |
225 EXPECT_EQ(1u, c_inherited.size()); | 240 EXPECT_EQ(1u, c_inherited.size()); |
226 EXPECT_TRUE(c_inherited.IndexOf(&d) != static_cast<size_t>(-1)); | 241 EXPECT_TRUE(c_inherited.IndexOf(&d) != static_cast<size_t>(-1)); |
227 | 242 |
228 // B should have C and D in its inherited libs. | 243 // B should have C and D in its inherited libs. |
229 const UniqueVector<const Target*>& b_inherited = b.inherited_libraries(); | 244 const UniqueVector<const Target*>& b_inherited = b.inherited_libraries(); |
230 EXPECT_EQ(2u, b_inherited.size()); | 245 EXPECT_EQ(2u, b_inherited.size()); |
231 EXPECT_TRUE(b_inherited.IndexOf(&c) != static_cast<size_t>(-1)); | 246 EXPECT_TRUE(b_inherited.IndexOf(&c) != static_cast<size_t>(-1)); |
232 EXPECT_TRUE(b_inherited.IndexOf(&d) != static_cast<size_t>(-1)); | 247 EXPECT_TRUE(b_inherited.IndexOf(&d) != static_cast<size_t>(-1)); |
233 | 248 |
234 // A should have B in its inherited libs, but not any others (the shared | 249 // A should have B in its inherited libs, but not any others (the shared |
235 // library will include the static library and source set). | 250 // library will include the static library and source set). |
236 const UniqueVector<const Target*>& a_inherited = a.inherited_libraries(); | 251 const UniqueVector<const Target*>& a_inherited = a.inherited_libraries(); |
237 EXPECT_EQ(1u, a_inherited.size()); | 252 EXPECT_EQ(1u, a_inherited.size()); |
238 EXPECT_TRUE(a_inherited.IndexOf(&b) != static_cast<size_t>(-1)); | 253 EXPECT_TRUE(a_inherited.IndexOf(&b) != static_cast<size_t>(-1)); |
239 } | 254 } |
| 255 |
| 256 TEST(Target, GetComputedOutputName) { |
| 257 TestWithScope setup; |
| 258 |
| 259 // Basic target with no prefix (executable type tool in the TestWithScope has |
| 260 // no prefix) or output name. |
| 261 Target basic(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 262 basic.set_output_type(Target::EXECUTABLE); |
| 263 basic.SetToolchain(setup.toolchain()); |
| 264 basic.OnResolved(); |
| 265 EXPECT_EQ("bar", basic.GetComputedOutputName(false)); |
| 266 EXPECT_EQ("bar", basic.GetComputedOutputName(true)); |
| 267 |
| 268 // Target with no prefix but an output name. |
| 269 Target with_name(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 270 with_name.set_output_type(Target::EXECUTABLE); |
| 271 with_name.set_output_name("myoutput"); |
| 272 with_name.SetToolchain(setup.toolchain()); |
| 273 with_name.OnResolved(); |
| 274 EXPECT_EQ("myoutput", with_name.GetComputedOutputName(false)); |
| 275 EXPECT_EQ("myoutput", with_name.GetComputedOutputName(true)); |
| 276 |
| 277 // Target with a "lib" prefix (the static library tool in the TestWithScope |
| 278 // should specify a "lib" output prefix). |
| 279 Target with_prefix(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 280 with_prefix.set_output_type(Target::STATIC_LIBRARY); |
| 281 with_prefix.SetToolchain(setup.toolchain()); |
| 282 with_prefix.OnResolved(); |
| 283 EXPECT_EQ("bar", with_prefix.GetComputedOutputName(false)); |
| 284 EXPECT_EQ("libbar", with_prefix.GetComputedOutputName(true)); |
| 285 |
| 286 // Target with a "lib" prefix that already has it applied. The prefix should |
| 287 // not duplicate something already in the target name. |
| 288 Target dup_prefix(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 289 dup_prefix.set_output_type(Target::STATIC_LIBRARY); |
| 290 dup_prefix.set_output_name("libbar"); |
| 291 dup_prefix.SetToolchain(setup.toolchain()); |
| 292 dup_prefix.OnResolved(); |
| 293 EXPECT_EQ("libbar", dup_prefix.GetComputedOutputName(false)); |
| 294 EXPECT_EQ("libbar", dup_prefix.GetComputedOutputName(true)); |
| 295 } |
OLD | NEW |