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

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

Issue 584683002: Improve GN header checker, make //ui pass. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the adnoid 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
89 bool is_public = false; 89 bool is_permitted = false;
90 std::vector<const Target*> chain; 90 HeaderChecker::Chain chain;
91 EXPECT_FALSE(checker->IsDependencyOf(&a_, &a_, &chain, &is_public)); 91 EXPECT_FALSE(checker->IsDependencyOf(&a_, &a_, &chain, &is_permitted));
92 92
93 // A depends on B. 93 // A depends publicly on B.
94 chain.clear(); 94 chain.clear();
95 is_public = false; 95 is_permitted = false;
96 EXPECT_TRUE(checker->IsDependencyOf(&b_, &a_, &chain, &is_public)); 96 EXPECT_TRUE(checker->IsDependencyOf(&b_, &a_, &chain, &is_permitted));
97 ASSERT_EQ(2u, chain.size()); 97 ASSERT_EQ(2u, chain.size());
98 EXPECT_EQ(&b_, chain[0]); 98 EXPECT_EQ(HeaderChecker::ChainLink(&b_, true), chain[0]);
99 EXPECT_EQ(&a_, chain[1]); 99 EXPECT_EQ(HeaderChecker::ChainLink(&a_, true), chain[1]);
100 EXPECT_TRUE(is_public); 100 EXPECT_TRUE(is_permitted);
101 101
102 // A indirectly depends on C. The "public" dependency path through B should 102 // A indirectly depends on C. The "public" dependency path through B should
103 // be identified. 103 // be identified.
104 chain.clear(); 104 chain.clear();
105 is_public = false; 105 is_permitted = false;
106 EXPECT_TRUE(checker->IsDependencyOf(&c_, &a_, &chain, &is_public)); 106 EXPECT_TRUE(checker->IsDependencyOf(&c_, &a_, &chain, &is_permitted));
107 ASSERT_EQ(3u, chain.size()); 107 ASSERT_EQ(3u, chain.size());
108 EXPECT_EQ(&c_, chain[0]); 108 EXPECT_EQ(HeaderChecker::ChainLink(&c_, true), chain[0]);
109 EXPECT_EQ(&b_, chain[1]); 109 EXPECT_EQ(HeaderChecker::ChainLink(&b_, true), chain[1]);
110 EXPECT_EQ(&a_, chain[2]); 110 EXPECT_EQ(HeaderChecker::ChainLink(&a_, true), chain[2]);
111 EXPECT_TRUE(is_public); 111 EXPECT_TRUE(is_permitted);
112 112
113 // C does not depend on A. 113 // C does not depend on A.
114 chain.clear(); 114 chain.clear();
115 is_public = false; 115 is_permitted = false;
116 EXPECT_FALSE(checker->IsDependencyOf(&a_, &c_, &chain, &is_public)); 116 EXPECT_FALSE(checker->IsDependencyOf(&a_, &c_, &chain, &is_permitted));
117 EXPECT_TRUE(chain.empty()); 117 EXPECT_TRUE(chain.empty());
118 EXPECT_FALSE(is_public); 118 EXPECT_FALSE(is_permitted);
119 119
120 // Add a private A -> C dependency. This should not be detected since it's 120 // Remove the B -> C public dependency, leaving P's private dep on C the only
121 // private, even though it's shorter than the A -> B -> C one. 121 // path from A to C. This should now be found.
122 chain.clear(); 122 chain.clear();
123 is_public = false; 123 EXPECT_EQ(&c_, b_.public_deps()[0].ptr); // Validate it's the right one.
124 a_.private_deps().push_back(LabelTargetPair(&c_)); 124 b_.public_deps().erase(b_.public_deps().begin());
125 EXPECT_TRUE(checker->IsDependencyOf(&c_, &a_, &chain, &is_public)); 125 EXPECT_TRUE(checker->IsDependencyOf(&c_, &a_, &chain, &is_permitted));
126 EXPECT_EQ(&c_, chain[0]); 126 EXPECT_EQ(3u, chain.size());
127 EXPECT_EQ(&b_, chain[1]); 127 EXPECT_EQ(HeaderChecker::ChainLink(&c_, false), chain[0]);
128 EXPECT_EQ(&a_, chain[2]); 128 EXPECT_EQ(HeaderChecker::ChainLink(&p, true), chain[1]);
scottmg 2014/09/18 22:33:52 hm, no i guess is_public for ChainLink makes sense
129 EXPECT_TRUE(is_public); 129 EXPECT_EQ(HeaderChecker::ChainLink(&a_, true), chain[2]);
130 EXPECT_FALSE(is_permitted);
130 131
scottmg 2014/09/18 22:33:52 since the iteration depends on discarding disallow
131 // Remove the B -> C public dependency, leaving A's private dep on C the only 132 // P privately depends on C. That dependency should be OK since it's only
132 // path. This should now be found. 133 // one hop.
133 chain.clear(); 134 chain.clear();
134 EXPECT_EQ(&c_, b_.public_deps()[0].ptr); // Validate it's the right one. 135 is_permitted = false;
135 b_.public_deps().erase(b_.public_deps().begin()); 136 EXPECT_TRUE(checker->IsDependencyOf(&c_, &p, &chain, &is_permitted));
136 EXPECT_TRUE(checker->IsDependencyOf(&c_, &a_, &chain, &is_public)); 137 ASSERT_EQ(2u, chain.size());
137 EXPECT_EQ(&c_, chain[0]); 138 EXPECT_EQ(HeaderChecker::ChainLink(&c_, false), chain[0]);
138 EXPECT_EQ(&a_, chain[1]); 139 EXPECT_EQ(HeaderChecker::ChainLink(&p, true), chain[1]);
139 EXPECT_FALSE(is_public); 140 EXPECT_TRUE(is_permitted);
scottmg 2014/09/18 22:33:52 Maybe a test that A -> B -> C -> D is right too,
140 } 141 }
141 142
142 TEST_F(HeaderCheckerTest, CheckInclude) { 143 TEST_F(HeaderCheckerTest, CheckInclude) {
143 InputFile input_file(SourceFile("//some_file.cc")); 144 InputFile input_file(SourceFile("//some_file.cc"));
144 input_file.SetContents(std::string()); 145 input_file.SetContents(std::string());
145 LocationRange range; // Dummy value. 146 LocationRange range; // Dummy value.
146 147
147 // Add a disconnected target d with a header to check that you have to have 148 // Add a disconnected target d with a header to check that you have to have
148 // to depend on a target listing a header. 149 // to depend on a target listing a header.
149 SourceFile d_header("//d_header.h"); 150 SourceFile d_header("//d_header.h");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 EXPECT_TRUE(err.has_error()); 210 EXPECT_TRUE(err.has_error());
210 211
211 // Add an allow_circular_includes_from on A that lists B. 212 // Add an allow_circular_includes_from on A that lists B.
212 a_.allow_circular_includes_from().insert(b_.label()); 213 a_.allow_circular_includes_from().insert(b_.label());
213 214
214 // Now the include from B to A should be allowed. 215 // Now the include from B to A should be allowed.
215 err = Err(); 216 err = Err();
216 EXPECT_TRUE(checker->CheckInclude(&b_, input_file, a_public, range, &err)); 217 EXPECT_TRUE(checker->CheckInclude(&b_, input_file, a_public, range, &err));
217 EXPECT_FALSE(err.has_error()); 218 EXPECT_FALSE(err.has_error());
218 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698