OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/config.h" | 8 #include "tools/gn/config.h" |
9 #include "tools/gn/header_checker.h" | 9 #include "tools/gn/header_checker.h" |
10 #include "tools/gn/scheduler.h" | 10 #include "tools/gn/scheduler.h" |
11 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
12 #include "tools/gn/test_with_scope.h" | 12 #include "tools/gn/test_with_scope.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 class HeaderCheckerTest : public testing::Test { | 16 class HeaderCheckerTest : public testing::Test { |
17 public: | 17 public: |
18 HeaderCheckerTest() | 18 HeaderCheckerTest() |
19 : a_(setup_.settings(), Label(SourceDir("//a/"), "a")), | 19 : a_(setup_.settings(), Label(SourceDir("//a/"), "a"), {}), |
20 b_(setup_.settings(), Label(SourceDir("//b/"), "b")), | 20 b_(setup_.settings(), Label(SourceDir("//b/"), "b"), {}), |
21 c_(setup_.settings(), Label(SourceDir("//c/"), "c")), | 21 c_(setup_.settings(), Label(SourceDir("//c/"), "c"), {}), |
22 d_(setup_.settings(), Label(SourceDir("//d/"), "d")) { | 22 d_(setup_.settings(), Label(SourceDir("//d/"), "d"), {}) { |
23 a_.set_output_type(Target::SOURCE_SET); | 23 a_.set_output_type(Target::SOURCE_SET); |
24 b_.set_output_type(Target::SOURCE_SET); | 24 b_.set_output_type(Target::SOURCE_SET); |
25 c_.set_output_type(Target::SOURCE_SET); | 25 c_.set_output_type(Target::SOURCE_SET); |
26 d_.set_output_type(Target::SOURCE_SET); | 26 d_.set_output_type(Target::SOURCE_SET); |
27 | 27 |
28 Err err; | 28 Err err; |
29 a_.SetToolchain(setup_.toolchain(), &err); | 29 a_.SetToolchain(setup_.toolchain(), &err); |
30 b_.SetToolchain(setup_.toolchain(), &err); | 30 b_.SetToolchain(setup_.toolchain(), &err); |
31 c_.SetToolchain(setup_.toolchain(), &err); | 31 c_.SetToolchain(setup_.toolchain(), &err); |
32 d_.SetToolchain(setup_.toolchain(), &err); | 32 d_.SetToolchain(setup_.toolchain(), &err); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 TEST_F(HeaderCheckerTest, IsDependencyOf) { | 71 TEST_F(HeaderCheckerTest, IsDependencyOf) { |
72 scoped_refptr<HeaderChecker> checker( | 72 scoped_refptr<HeaderChecker> checker( |
73 new HeaderChecker(setup_.build_settings(), targets_)); | 73 new HeaderChecker(setup_.build_settings(), targets_)); |
74 | 74 |
75 // Add a target P ("private") that privately depends on C, and hook up the | 75 // Add a target P ("private") that privately depends on C, and hook up the |
76 // chain so that A -> P -> C. A will depend on C via two different paths. | 76 // chain so that A -> P -> C. A will depend on C via two different paths. |
77 Err err; | 77 Err err; |
78 Target p(setup_.settings(), Label(SourceDir("//p/"), "p")); | 78 Target p(setup_.settings(), Label(SourceDir("//p/"), "p"), {}); |
79 p.set_output_type(Target::SOURCE_SET); | 79 p.set_output_type(Target::SOURCE_SET); |
80 p.SetToolchain(setup_.toolchain(), &err); | 80 p.SetToolchain(setup_.toolchain(), &err); |
81 EXPECT_FALSE(err.has_error()); | 81 EXPECT_FALSE(err.has_error()); |
82 p.private_deps().push_back(LabelTargetPair(&c_)); | 82 p.private_deps().push_back(LabelTargetPair(&c_)); |
83 p.visibility().SetPublic(); | 83 p.visibility().SetPublic(); |
84 p.OnResolved(&err); | 84 p.OnResolved(&err); |
85 | 85 |
86 a_.public_deps().push_back(LabelTargetPair(&p)); | 86 a_.public_deps().push_back(LabelTargetPair(&p)); |
87 | 87 |
88 // A does not depend on itself. | 88 // A does not depend on itself. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Add a public and private header on C. | 158 // Add a public and private header on C. |
159 SourceFile c_public("//c_public.h"); | 159 SourceFile c_public("//c_public.h"); |
160 SourceFile c_private("//c_private.h"); | 160 SourceFile c_private("//c_private.h"); |
161 c_.sources().push_back(c_private); | 161 c_.sources().push_back(c_private); |
162 c_.public_headers().push_back(c_public); | 162 c_.public_headers().push_back(c_public); |
163 c_.set_all_headers_public(false); | 163 c_.set_all_headers_public(false); |
164 | 164 |
165 // Create another toolchain. | 165 // Create another toolchain. |
166 Settings other_settings(setup_.build_settings(), "other/"); | 166 Settings other_settings(setup_.build_settings(), "other/"); |
167 Toolchain other_toolchain(&other_settings, | 167 Toolchain other_toolchain(&other_settings, |
168 Label(SourceDir("//toolchain/"), "other")); | 168 Label(SourceDir("//toolchain/"), "other"), {}); |
169 TestWithScope::SetupToolchain(&other_toolchain); | 169 TestWithScope::SetupToolchain(&other_toolchain); |
170 other_settings.set_toolchain_label(other_toolchain.label()); | 170 other_settings.set_toolchain_label(other_toolchain.label()); |
171 other_settings.set_default_toolchain_label(setup_.toolchain()->label()); | 171 other_settings.set_default_toolchain_label(setup_.toolchain()->label()); |
172 | 172 |
173 // Add a target in the other toolchain with a header in it that is not | 173 // Add a target in the other toolchain with a header in it that is not |
174 // connected to any targets in the main toolchain. | 174 // connected to any targets in the main toolchain. |
175 Target otc(&other_settings, Label(SourceDir("//p/"), "otc", | 175 Target otc(&other_settings, |
176 other_toolchain.label().dir(), other_toolchain.label().name())); | 176 Label(SourceDir("//p/"), "otc", other_toolchain.label().dir(), |
| 177 other_toolchain.label().name()), |
| 178 {}); |
177 otc.set_output_type(Target::SOURCE_SET); | 179 otc.set_output_type(Target::SOURCE_SET); |
178 Err err; | 180 Err err; |
179 EXPECT_TRUE(otc.SetToolchain(&other_toolchain, &err)); | 181 EXPECT_TRUE(otc.SetToolchain(&other_toolchain, &err)); |
180 otc.visibility().SetPublic(); | 182 otc.visibility().SetPublic(); |
181 targets_.push_back(&otc); | 183 targets_.push_back(&otc); |
182 | 184 |
183 SourceFile otc_header("//otc_header.h"); | 185 SourceFile otc_header("//otc_header.h"); |
184 otc.sources().push_back(otc_header); | 186 otc.sources().push_back(otc_header); |
185 EXPECT_TRUE(otc.OnResolved(&err)); | 187 EXPECT_TRUE(otc.OnResolved(&err)); |
186 | 188 |
(...skipping 28 matching lines...) Expand all Loading... |
215 err = Err(); | 217 err = Err(); |
216 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, otc_header, range, &err)); | 218 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, otc_header, range, &err)); |
217 EXPECT_FALSE(err.has_error()); | 219 EXPECT_FALSE(err.has_error()); |
218 } | 220 } |
219 | 221 |
220 // A public chain of dependencies should always be identified first, even if | 222 // A public chain of dependencies should always be identified first, even if |
221 // it is longer than a private one. | 223 // it is longer than a private one. |
222 TEST_F(HeaderCheckerTest, PublicFirst) { | 224 TEST_F(HeaderCheckerTest, PublicFirst) { |
223 // Now make a A -> Z -> D private dependency chain (one shorter than the | 225 // Now make a A -> Z -> D private dependency chain (one shorter than the |
224 // public one to get to D). | 226 // public one to get to D). |
225 Target z(setup_.settings(), Label(SourceDir("//a/"), "a")); | 227 Target z(setup_.settings(), Label(SourceDir("//a/"), "a"), {}); |
226 z.set_output_type(Target::SOURCE_SET); | 228 z.set_output_type(Target::SOURCE_SET); |
227 Err err; | 229 Err err; |
228 EXPECT_TRUE(z.SetToolchain(setup_.toolchain(), &err)); | 230 EXPECT_TRUE(z.SetToolchain(setup_.toolchain(), &err)); |
229 z.private_deps().push_back(LabelTargetPair(&d_)); | 231 z.private_deps().push_back(LabelTargetPair(&d_)); |
230 EXPECT_TRUE(z.OnResolved(&err)); | 232 EXPECT_TRUE(z.OnResolved(&err)); |
231 targets_.push_back(&z); | 233 targets_.push_back(&z); |
232 | 234 |
233 a_.private_deps().push_back(LabelTargetPair(&z)); | 235 a_.private_deps().push_back(LabelTargetPair(&z)); |
234 | 236 |
235 // Check that D can be found from A, but since it's private, it will be | 237 // Check that D can be found from A, but since it's private, it will be |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 EXPECT_TRUE(err.has_error()); | 283 EXPECT_TRUE(err.has_error()); |
282 | 284 |
283 // Add an allow_circular_includes_from on A that lists B. | 285 // Add an allow_circular_includes_from on A that lists B. |
284 a_.allow_circular_includes_from().insert(b_.label()); | 286 a_.allow_circular_includes_from().insert(b_.label()); |
285 | 287 |
286 // Now the include from B to A should be allowed. | 288 // Now the include from B to A should be allowed. |
287 err = Err(); | 289 err = Err(); |
288 EXPECT_TRUE(checker->CheckInclude(&b_, input_file, a_public, range, &err)); | 290 EXPECT_TRUE(checker->CheckInclude(&b_, input_file, a_public, range, &err)); |
289 EXPECT_FALSE(err.has_error()); | 291 EXPECT_FALSE(err.has_error()); |
290 } | 292 } |
OLD | NEW |