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

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

Issue 1217093007: Add a //nogncheck anntation to GN include checker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « tools/gn/c_include_iterator.cc ('k') | tools/gn/docs/reference.md » ('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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/c_include_iterator.h" 6 #include "tools/gn/c_include_iterator.h"
7 #include "tools/gn/input_file.h" 7 #include "tools/gn/input_file.h"
8 #include "tools/gn/location.h" 8 #include "tools/gn/location.h"
9 9
10 namespace { 10 namespace {
(...skipping 11 matching lines...) Expand all
22 TEST(CIncludeIterator, Basic) { 22 TEST(CIncludeIterator, Basic) {
23 std::string buffer; 23 std::string buffer;
24 buffer.append("// Some comment\n"); 24 buffer.append("// Some comment\n");
25 buffer.append("\n"); 25 buffer.append("\n");
26 buffer.append("#include \"foo/bar.h\"\n"); 26 buffer.append("#include \"foo/bar.h\"\n");
27 buffer.append("\n"); 27 buffer.append("\n");
28 buffer.append("#include <stdio.h>\n"); 28 buffer.append("#include <stdio.h>\n");
29 buffer.append("\n"); 29 buffer.append("\n");
30 buffer.append(" #include \"foo/baz.h\"\n"); // Leading whitespace 30 buffer.append(" #include \"foo/baz.h\"\n"); // Leading whitespace
31 buffer.append("#include \"la/deda.h\"\n"); 31 buffer.append("#include \"la/deda.h\"\n");
32 // Line annotated with "// nogncheck"
33 buffer.append("#include \"should_be_skipped.h\" // nogncheck\n");
32 buffer.append("#import \"weird_mac_import.h\"\n"); 34 buffer.append("#import \"weird_mac_import.h\"\n");
33 buffer.append("\n"); 35 buffer.append("\n");
34 buffer.append("void SomeCode() {\n"); 36 buffer.append("void SomeCode() {\n");
35 37
36 InputFile file(SourceFile("//foo.cc")); 38 InputFile file(SourceFile("//foo.cc"));
37 file.SetContents(buffer); 39 file.SetContents(buffer);
38 40
39 CIncludeIterator iter(&file); 41 CIncludeIterator iter(&file);
40 42
41 base::StringPiece contents; 43 base::StringPiece contents;
42 LocationRange range; 44 LocationRange range;
43 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); 45 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range));
44 EXPECT_EQ("foo/bar.h", contents); 46 EXPECT_EQ("foo/bar.h", contents);
45 EXPECT_TRUE(RangeIs(range, 3, 11, 20)) << range.begin().Describe(true); 47 EXPECT_TRUE(RangeIs(range, 3, 11, 20)) << range.begin().Describe(true);
46 48
47 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); 49 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range));
48 EXPECT_EQ("foo/baz.h", contents); 50 EXPECT_EQ("foo/baz.h", contents);
49 EXPECT_TRUE(RangeIs(range, 7, 12, 21)) << range.begin().Describe(true); 51 EXPECT_TRUE(RangeIs(range, 7, 12, 21)) << range.begin().Describe(true);
50 52
51 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); 53 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range));
52 EXPECT_EQ("la/deda.h", contents); 54 EXPECT_EQ("la/deda.h", contents);
53 EXPECT_TRUE(RangeIs(range, 8, 11, 20)) << range.begin().Describe(true); 55 EXPECT_TRUE(RangeIs(range, 8, 11, 20)) << range.begin().Describe(true);
54 56
57 // The line annotated with "nogncheck" should be skipped.
58
55 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); 59 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range));
56 EXPECT_EQ("weird_mac_import.h", contents); 60 EXPECT_EQ("weird_mac_import.h", contents);
57 EXPECT_TRUE(RangeIs(range, 9, 10, 28)) << range.begin().Describe(true); 61 EXPECT_TRUE(RangeIs(range, 10, 10, 28)) << range.begin().Describe(true);
58 62
59 EXPECT_FALSE(iter.GetNextIncludeString(&contents, &range)); 63 EXPECT_FALSE(iter.GetNextIncludeString(&contents, &range));
60 } 64 }
61 65
62 // Tests that we don't search for includes indefinitely. 66 // Tests that we don't search for includes indefinitely.
63 TEST(CIncludeIterator, GiveUp) { 67 TEST(CIncludeIterator, GiveUp) {
64 std::string buffer; 68 std::string buffer;
65 for (size_t i = 0; i < 1000; i++) 69 for (size_t i = 0; i < 1000; i++)
66 buffer.append("x\n"); 70 buffer.append("x\n");
67 buffer.append("#include \"foo/bar.h\"\n"); 71 buffer.append("#include \"foo/bar.h\"\n");
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 base::StringPiece contents; 125 base::StringPiece contents;
122 LocationRange range; 126 LocationRange range;
123 127
124 CIncludeIterator iter(&file); 128 CIncludeIterator iter(&file);
125 for (size_t group = 0; group < kGroupCount; group++) { 129 for (size_t group = 0; group < kGroupCount; group++) {
126 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range)); 130 EXPECT_TRUE(iter.GetNextIncludeString(&contents, &range));
127 EXPECT_EQ(include, contents.as_string()); 131 EXPECT_EQ(include, contents.as_string());
128 } 132 }
129 EXPECT_FALSE(iter.GetNextIncludeString(&contents, &range)); 133 EXPECT_FALSE(iter.GetNextIncludeString(&contents, &range));
130 } 134 }
OLDNEW
« no previous file with comments | « tools/gn/c_include_iterator.cc ('k') | tools/gn/docs/reference.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698