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

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

Issue 231293003: Revert 262747 "Improve GN public header file checking" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/tools/gn/header_checker.cc ('k') | trunk/src/tools/gn/input_conversion.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/header_checker.h" 8 #include "tools/gn/header_checker.h"
9 #include "tools/gn/scheduler.h" 9 #include "tools/gn/scheduler.h"
10 #include "tools/gn/target.h" 10 #include "tools/gn/target.h"
11 #include "tools/gn/test_with_scope.h" 11 #include "tools/gn/test_with_scope.h"
12 12
13 namespace { 13 namespace {
14 14
15 class HeaderCheckerTest : public testing::Test { 15 class HeaderCheckerTest : public testing::Test {
16 public: 16 public:
17 HeaderCheckerTest() 17 HeaderCheckerTest()
18 : a_(setup_.settings(), Label(SourceDir("//a/"), "a")), 18 : a_(setup_.settings(), Label(SourceDir("//"), "a")),
19 b_(setup_.settings(), Label(SourceDir("//b/"), "a")), 19 b_(setup_.settings(), Label(SourceDir("//"), "a")),
20 c_(setup_.settings(), Label(SourceDir("//c/"), "c")) { 20 c_(setup_.settings(), Label(SourceDir("//"), "c")) {
21 a_.deps().push_back(LabelTargetPair(&b_)); 21 a_.deps().push_back(LabelTargetPair(&b_));
22 b_.deps().push_back(LabelTargetPair(&c_)); 22 b_.deps().push_back(LabelTargetPair(&c_));
23 23
24 // Start with all public visibility.
25 a_.visibility().SetPublic();
26 b_.visibility().SetPublic();
27 c_.visibility().SetPublic();
28
29 targets_.push_back(&a_); 24 targets_.push_back(&a_);
30 targets_.push_back(&b_); 25 targets_.push_back(&b_);
31 targets_.push_back(&c_); 26 targets_.push_back(&c_);
32 } 27 }
33 28
34 protected: 29 protected:
35 Scheduler scheduler_; 30 Scheduler scheduler_;
36 31
37 TestWithScope setup_; 32 TestWithScope setup_;
38 33
(...skipping 12 matching lines...) Expand all
51 scoped_refptr<HeaderChecker> checker( 46 scoped_refptr<HeaderChecker> checker(
52 new HeaderChecker(setup_.build_settings(), targets_)); 47 new HeaderChecker(setup_.build_settings(), targets_));
53 48
54 EXPECT_FALSE(checker->IsDependencyOf(&a_, &a_)); 49 EXPECT_FALSE(checker->IsDependencyOf(&a_, &a_));
55 EXPECT_TRUE(checker->IsDependencyOf(&b_, &a_)); 50 EXPECT_TRUE(checker->IsDependencyOf(&b_, &a_));
56 EXPECT_TRUE(checker->IsDependencyOf(&c_, &a_)); 51 EXPECT_TRUE(checker->IsDependencyOf(&c_, &a_));
57 EXPECT_FALSE(checker->IsDependencyOf(&a_, &c_)); 52 EXPECT_FALSE(checker->IsDependencyOf(&a_, &c_));
58 } 53 }
59 54
60 TEST_F(HeaderCheckerTest, CheckInclude) { 55 TEST_F(HeaderCheckerTest, CheckInclude) {
61 InputFile input_file(SourceFile("//some_file.cc"));
62 input_file.SetContents(std::string());
63 LocationRange range; // Dummy value.
64
65 // Add a disconnected target d with a header to check that you have to have 56 // Add a disconnected target d with a header to check that you have to have
66 // to depend on a target listing a header. 57 // to depend on a target listing a header.
67 Target d(setup_.settings(), Label(SourceDir("//"), "d")); 58 Target d(setup_.settings(), Label(SourceDir("//"), "d"));
68 SourceFile d_header("//d_header.h"); 59 SourceFile d_header("//d_header.h");
69 d.sources().push_back(SourceFile(d_header)); 60 d.sources().push_back(SourceFile(d_header));
70 61
71 // Add a header on B and say everything in B is public. 62 // Add a header on B and say everything in B is public.
72 SourceFile b_public("//b_public.h"); 63 SourceFile b_public("//b_public.h");
73 b_.sources().push_back(b_public); 64 b_.sources().push_back(b_public);
74 c_.set_all_headers_public(true); 65 c_.set_all_headers_public(true);
75 66
76 // Add a public and private header on C. 67 // Add a public and private header on C.
77 SourceFile c_public("//c_public.h"); 68 SourceFile c_public("//c_public.h");
78 SourceFile c_private("//c_private.h"); 69 SourceFile c_private("//c_private.h");
79 c_.sources().push_back(c_private); 70 c_.sources().push_back(c_private);
80 c_.public_headers().push_back(c_public); 71 c_.public_headers().push_back(c_public);
81 c_.set_all_headers_public(false); 72 c_.set_all_headers_public(false);
82 73
83 targets_.push_back(&d); 74 targets_.push_back(&d);
84 scoped_refptr<HeaderChecker> checker( 75 scoped_refptr<HeaderChecker> checker(
85 new HeaderChecker(setup_.build_settings(), targets_)); 76 new HeaderChecker(setup_.build_settings(), targets_));
86 77
87 // A file in target A can't include a header from D because A has no 78 // A file in target A can't include a header from D because A has no
88 // dependency on D. 79 // dependency on D.
89 Err err; 80 Err err;
90 EXPECT_FALSE(checker->CheckInclude(&a_, input_file, d_header, range, &err)); 81 SourceFile source_file("//some_file.cc");
82 EXPECT_FALSE(checker->CheckInclude(&a_, source_file, d_header, &err));
91 EXPECT_TRUE(err.has_error()); 83 EXPECT_TRUE(err.has_error());
92 84
93 // A can include the public header in B. 85 // A can include the public header in B.
94 err = Err(); 86 err = Err();
95 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, b_public, range, &err)); 87 EXPECT_TRUE(checker->CheckInclude(&a_, source_file, b_public, &err));
96 EXPECT_FALSE(err.has_error()); 88 EXPECT_FALSE(err.has_error());
97 89
98 // Check A depending on the public and private headers in C. 90 // Check A depending on the public and private headers in C.
99 err = Err(); 91 err = Err();
100 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, c_public, range, &err)); 92 EXPECT_TRUE(checker->CheckInclude(&a_, source_file, c_public, &err));
101 EXPECT_FALSE(err.has_error()); 93 EXPECT_FALSE(err.has_error());
102 EXPECT_FALSE(checker->CheckInclude(&a_, input_file, c_private, range, &err)); 94 EXPECT_FALSE(checker->CheckInclude(&a_, source_file, c_private, &err));
103 EXPECT_TRUE(err.has_error()); 95 EXPECT_TRUE(err.has_error());
104 96
105 // A can depend on a random file unknown to the build. 97 // A can depend on a random file unknown to the build.
106 err = Err(); 98 err = Err();
107 EXPECT_TRUE(checker->CheckInclude(&a_, input_file, SourceFile("//random.h"), 99 EXPECT_TRUE(checker->CheckInclude(&a_, source_file, SourceFile("//random.h"),
108 range, &err)); 100 &err));
109 EXPECT_FALSE(err.has_error()); 101 EXPECT_FALSE(err.has_error());
110
111 // If C is not visible from A, A can't include public headers even if there
112 // is a dependency path.
113 c_.visibility().SetPrivate(c_.label().dir());
114 err = Err();
115 EXPECT_FALSE(checker->CheckInclude(&a_, input_file, c_public, range, &err));
116 EXPECT_TRUE(err.has_error());
117 } 102 }
OLDNEW
« no previous file with comments | « trunk/src/tools/gn/header_checker.cc ('k') | trunk/src/tools/gn/input_conversion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698