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

Side by Side Diff: tools/gn/header_checker_unittest.cc

Issue 516683002: Add GN variables for controlling header checking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@desc
Patch Set: Created 6 years, 3 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
OLDNEW
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"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 b_.set_output_type(Target::GROUP); 219 b_.set_output_type(Target::GROUP);
220 err = Err(); 220 err = Err();
221 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, c_public, range, &err)); 221 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, c_public, range, &err));
222 EXPECT_FALSE(err.has_error()); 222 EXPECT_FALSE(err.has_error());
223 223
224 b_.set_output_type(Target::UNKNOWN); 224 b_.set_output_type(Target::UNKNOWN);
225 c_.direct_dependent_configs().clear(); 225 c_.direct_dependent_configs().clear();
226 } 226 }
227 } 227 }
228 228
229 // Checks that the allow_circular_includes_from list works.
230 TEST_F(HeaderCheckerTest, CheckIncludeAllowCircular) {
231 InputFile input_file(SourceFile("//some_file.cc"));
232 input_file.SetContents(std::string());
233 LocationRange range; // Dummy value.
234
235 // Add an include file to A.
236 SourceFile a_public("//a_public.h");
237 a_.sources().push_back(a_public);
238
239 scoped_refptr<HeaderChecker> checker(
240 new HeaderChecker(setup_.build_settings(), targets_));
241
242 // A depends on B. So B normally can't include headers from A.
243 Err err;
244 EXPECT_FALSE(checker->CheckInclude(&b_, input_file, a_public, range, &err));
245 EXPECT_TRUE(err.has_error());
246
247 // Add an allow_circular_includes_from on A that lists B.
248 a_.allow_circular_includes_from().insert(b_.label());
249
250 // Now the include from B to A should be allowed.
251 err = Err();
252 EXPECT_TRUE(checker->CheckInclude(&b_, input_file, a_public, range, &err));
253 EXPECT_FALSE(err.has_error());
254 }
255
229 TEST_F(HeaderCheckerTest, GetDependentConfigChainProblemIndex) { 256 TEST_F(HeaderCheckerTest, GetDependentConfigChainProblemIndex) {
230 // Assume we have a chain A -> B -> C -> D. 257 // Assume we have a chain A -> B -> C -> D.
231 Target target_a(setup_.settings(), Label(SourceDir("//a/"), "a")); 258 Target target_a(setup_.settings(), Label(SourceDir("//a/"), "a"));
232 Target target_b(setup_.settings(), Label(SourceDir("//b/"), "b")); 259 Target target_b(setup_.settings(), Label(SourceDir("//b/"), "b"));
233 Target target_c(setup_.settings(), Label(SourceDir("//c/"), "c")); 260 Target target_c(setup_.settings(), Label(SourceDir("//c/"), "c"));
234 Target target_d(setup_.settings(), Label(SourceDir("//d/"), "d")); 261 Target target_d(setup_.settings(), Label(SourceDir("//d/"), "d"));
235 262
236 // C is a group, and B forwards deps from C, so A should get configs from D. 263 // C is a group, and B forwards deps from C, so A should get configs from D.
237 target_a.set_output_type(Target::SOURCE_SET); 264 target_a.set_output_type(Target::SOURCE_SET);
238 target_b.set_output_type(Target::SOURCE_SET); 265 target_b.set_output_type(Target::SOURCE_SET);
(...skipping 11 matching lines...) Expand all
250 277
251 // If C is not a group, it shouldn't work anymore. 278 // If C is not a group, it shouldn't work anymore.
252 target_c.set_output_type(Target::SOURCE_SET); 279 target_c.set_output_type(Target::SOURCE_SET);
253 EXPECT_EQ(1u, HeaderChecker::GetDependentConfigChainProblemIndex(chain)); 280 EXPECT_EQ(1u, HeaderChecker::GetDependentConfigChainProblemIndex(chain));
254 281
255 // Or if B stops forwarding from C, it shouldn't work anymore. 282 // Or if B stops forwarding from C, it shouldn't work anymore.
256 target_c.set_output_type(Target::GROUP); 283 target_c.set_output_type(Target::GROUP);
257 target_b.forward_dependent_configs().clear(); 284 target_b.forward_dependent_configs().clear();
258 EXPECT_EQ(2u, HeaderChecker::GetDependentConfigChainProblemIndex(chain)); 285 EXPECT_EQ(2u, HeaderChecker::GetDependentConfigChainProblemIndex(chain));
259 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698