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

Side by Side Diff: PRESUBMIT_test.py

Issue 11441035: PRESUBMIT #include check enhancements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import os 6 import os
7 import re 7 import re
8 import unittest 8 import unittest
9 9
10 import PRESUBMIT 10 import PRESUBMIT
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 self.assertTrue('15' in warnings[0]) 92 self.assertTrue('15' in warnings[0])
93 self.assertTrue('25' in warnings[1]) 93 self.assertTrue('25' in warnings[1])
94 self.assertTrue('35' in warnings[2]) 94 self.assertTrue('35' in warnings[2])
95 95
96 def testSpecialFirstInclude1(self): 96 def testSpecialFirstInclude1(self):
97 mock_input_api = MockInputApi() 97 mock_input_api = MockInputApi()
98 contents = ['#include "some/path/foo.h"', 98 contents = ['#include "some/path/foo.h"',
99 '#include "a/header.h"'] 99 '#include "a/header.h"']
100 mock_file = MockFile('some/path/foo.cc', contents) 100 mock_file = MockFile('some/path/foo.cc', contents)
101 warnings = PRESUBMIT._CheckIncludeOrderInFile( 101 warnings = PRESUBMIT._CheckIncludeOrderInFile(
102 mock_input_api, mock_file, True, range(1, len(contents) + 1)) 102 mock_input_api, mock_file, range(1, len(contents) + 1))
103 self.assertEqual(0, len(warnings)) 103 self.assertEqual(0, len(warnings))
104 104
105 def testSpecialFirstInclude2(self): 105 def testSpecialFirstInclude2(self):
106 mock_input_api = MockInputApi() 106 mock_input_api = MockInputApi()
107 contents = ['#include "some/other/path/foo.h"', 107 contents = ['#include "some/other/path/foo.h"',
108 '#include "a/header.h"'] 108 '#include "a/header.h"']
109 mock_file = MockFile('some/path/foo.cc', contents) 109 mock_file = MockFile('some/path/foo.cc', contents)
110 warnings = PRESUBMIT._CheckIncludeOrderInFile( 110 warnings = PRESUBMIT._CheckIncludeOrderInFile(
111 mock_input_api, mock_file, True, range(1, len(contents) + 1)) 111 mock_input_api, mock_file, range(1, len(contents) + 1))
112 self.assertEqual(0, len(warnings)) 112 self.assertEqual(0, len(warnings))
113 113
114 def testSpecialFirstInclude3(self): 114 def testSpecialFirstInclude3(self):
115 mock_input_api = MockInputApi() 115 mock_input_api = MockInputApi()
116 contents = ['#include "some/path/foo.h"', 116 contents = ['#include "some/path/foo.h"',
117 '#include "a/header.h"'] 117 '#include "a/header.h"']
118 mock_file = MockFile('some/path/foo_platform.cc', contents) 118 mock_file = MockFile('some/path/foo_platform.cc', contents)
119 warnings = PRESUBMIT._CheckIncludeOrderInFile( 119 warnings = PRESUBMIT._CheckIncludeOrderInFile(
120 mock_input_api, mock_file, True, range(1, len(contents) + 1)) 120 mock_input_api, mock_file, range(1, len(contents) + 1))
121 self.assertEqual(0, len(warnings)) 121 self.assertEqual(0, len(warnings))
122 122
123 def testSpecialFirstInclude4(self): 123 def testSpecialFirstInclude4(self):
124 mock_input_api = MockInputApi() 124 mock_input_api = MockInputApi()
125 contents = ['#include "some/path/bar.h"', 125 contents = ['#include "some/path/bar.h"',
126 '#include "a/header.h"'] 126 '#include "a/header.h"']
127 mock_file = MockFile('some/path/foo_platform.cc', contents) 127 mock_file = MockFile('some/path/foo_platform.cc', contents)
128 warnings = PRESUBMIT._CheckIncludeOrderInFile( 128 warnings = PRESUBMIT._CheckIncludeOrderInFile(
129 mock_input_api, mock_file, True, range(1, len(contents) + 1)) 129 mock_input_api, mock_file, range(1, len(contents) + 1))
130 self.assertEqual(1, len(warnings)) 130 self.assertEqual(1, len(warnings))
131 self.assertTrue('2' in warnings[0]) 131 self.assertTrue('2' in warnings[0])
132 132
133 def testSpecialFirstInclude5(self):
134 mock_input_api = MockInputApi()
135 contents = ['#include "some/other/path/foo.h"',
136 '#include "a/header.h"']
137 mock_file = MockFile('some/path/foo-suffix.h', contents)
138 warnings = PRESUBMIT._CheckIncludeOrderInFile(
139 mock_input_api, mock_file, range(1, len(contents) + 1))
140 self.assertEqual(0, len(warnings))
141
133 def testOrderAlreadyWrong(self): 142 def testOrderAlreadyWrong(self):
134 scope = [(1, '#include "b.h"'), 143 scope = [(1, '#include "b.h"'),
135 (2, '#include "a.h"'), 144 (2, '#include "a.h"'),
136 (3, '#include "c.h"')] 145 (3, '#include "c.h"')]
137 mock_input_api = MockInputApi() 146 mock_input_api = MockInputApi()
138 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, 147 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
139 '', [3]) 148 '', [3])
140 self.assertEqual(0, len(warnings)) 149 self.assertEqual(0, len(warnings))
141 150
142 def testConflictAdded1(self): 151 def testConflictAdded1(self):
(...skipping 12 matching lines...) Expand all
155 (3, '#include "d.h"')] 164 (3, '#include "d.h"')]
156 mock_input_api = MockInputApi() 165 mock_input_api = MockInputApi()
157 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, 166 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
158 '', [2]) 167 '', [2])
159 self.assertEqual(1, len(warnings)) 168 self.assertEqual(1, len(warnings))
160 self.assertTrue('2' in warnings[0]) 169 self.assertTrue('2' in warnings[0])
161 170
162 def testIfElifElseEndif(self): 171 def testIfElifElseEndif(self):
163 mock_input_api = MockInputApi() 172 mock_input_api = MockInputApi()
164 contents = ['#include "e.h"', 173 contents = ['#include "e.h"',
174 '#define foo',
175 '#include "f.h"',
176 '#undef foo',
177 '#include "e.h"',
165 '#if foo', 178 '#if foo',
166 '#include "d.h"', 179 '#include "d.h"',
167 '#elif bar', 180 '#elif bar',
168 '#include "c.h"', 181 '#include "c.h"',
169 '#else', 182 '#else',
170 '#include "b.h"', 183 '#include "b.h"',
171 '#endif', 184 '#endif',
172 '#include "a.h"'] 185 '#include "a.h"']
173 mock_file = MockFile('', contents) 186 mock_file = MockFile('', contents)
174 warnings = PRESUBMIT._CheckIncludeOrderInFile( 187 warnings = PRESUBMIT._CheckIncludeOrderInFile(
175 mock_input_api, mock_file, True, range(1, len(contents) + 1)) 188 mock_input_api, mock_file, range(1, len(contents) + 1))
176 self.assertEqual(0, len(warnings)) 189 self.assertEqual(0, len(warnings))
177 190
178 def testSysIncludes(self): 191 def testSysIncludes(self):
179 # #include <sys/...>'s can appear in any order. 192 # #include <sys/...>'s can appear in any order.
180 mock_input_api = MockInputApi() 193 mock_input_api = MockInputApi()
181 contents = ['#include <sys/b.h>', 194 contents = ['#include <sys/b.h>',
182 '#include <sys/a.h>'] 195 '#include <sys/a.h>']
183 mock_file = MockFile('', contents) 196 mock_file = MockFile('', contents)
184 warnings = PRESUBMIT._CheckIncludeOrderInFile( 197 warnings = PRESUBMIT._CheckIncludeOrderInFile(
185 mock_input_api, mock_file, True, range(1, len(contents) + 1)) 198 mock_input_api, mock_file, range(1, len(contents) + 1))
186 self.assertEqual(0, len(warnings)) 199 self.assertEqual(0, len(warnings))
187 200
188 201
189 class VersionControlerConflictsTest(unittest.TestCase): 202 class VersionControlerConflictsTest(unittest.TestCase):
190 def testTypicalConflict(self): 203 def testTypicalConflict(self):
191 lines = ['<<<<<<< HEAD', 204 lines = ['<<<<<<< HEAD',
192 ' base::ScopedTempDir temp_dir_;', 205 ' base::ScopedTempDir temp_dir_;',
193 '=======', 206 '=======',
194 ' ScopedTempDir temp_dir_;', 207 ' ScopedTempDir temp_dir_;',
195 '>>>>>>> master'] 208 '>>>>>>> master']
196 errors = PRESUBMIT._CheckForVersionControlConflictsInFile( 209 errors = PRESUBMIT._CheckForVersionControlConflictsInFile(
197 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) 210 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
198 self.assertEqual(3, len(errors)) 211 self.assertEqual(3, len(errors))
199 self.assertTrue('1' in errors[0]) 212 self.assertTrue('1' in errors[0])
200 self.assertTrue('3' in errors[1]) 213 self.assertTrue('3' in errors[1])
201 self.assertTrue('5' in errors[2]) 214 self.assertTrue('5' in errors[2])
202 215
203 216
204 if __name__ == '__main__': 217 if __name__ == '__main__':
205 unittest.main() 218 unittest.main()
OLDNEW
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698