OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
7 | 7 |
8 import StringIO | 8 import StringIO |
9 | 9 |
10 # Fixes include path. | 10 # Fixes include path. |
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 results2 = check(input_api2, presubmit.OutputApi) | 1154 results2 = check(input_api2, presubmit.OutputApi) |
1155 self.assertEquals(len(results2), 1) | 1155 self.assertEquals(len(results2), 1) |
1156 self.assertEquals(results2[0].__class__, error_type) | 1156 self.assertEquals(results2[0].__class__, error_type) |
1157 | 1157 |
1158 def ContentTest(self, check, content1, content2, error_type): | 1158 def ContentTest(self, check, content1, content2, error_type): |
1159 change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None, | 1159 change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None, |
1160 0, 0) | 1160 0, 0) |
1161 input_api1 = self.MockInputApi(change1, False) | 1161 input_api1 = self.MockInputApi(change1, False) |
1162 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 1162 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
1163 affected_file.LocalPath().AndReturn('foo.cc') | 1163 affected_file.LocalPath().AndReturn('foo.cc') |
| 1164 # Format is (file, line number, line content) |
1164 output1 = [ | 1165 output1 = [ |
1165 (affected_file, 42, 'yo, ' + content1), | 1166 (affected_file, 42, 'yo, ' + content1), |
1166 (affected_file, 43, 'yer'), | 1167 (affected_file, 43, 'yer'), |
1167 (affected_file, 23, 'ya'), | 1168 (affected_file, 23, 'ya'), |
1168 ] | 1169 ] |
1169 input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) | 1170 input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) |
1170 change2 = presubmit.Change('foo2', 'foo2\n', self.fake_root_dir, None, | 1171 change2 = presubmit.Change('foo2', 'foo2\n', self.fake_root_dir, None, |
1171 0, 0) | 1172 0, 0) |
1172 input_api2 = self.MockInputApi(change2, False) | 1173 input_api2 = self.MockInputApi(change2, False) |
1173 output2 = [ | 1174 output2 = [ |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 self.ReadFileTest( | 1321 self.ReadFileTest( |
1321 presubmit_canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol, | 1322 presubmit_canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol, |
1322 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", | 1323 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", |
1323 presubmit.OutputApi.PresubmitPromptWarning) | 1324 presubmit.OutputApi.PresubmitPromptWarning) |
1324 | 1325 |
1325 def testCannedCheckChangeHasNoTabs(self): | 1326 def testCannedCheckChangeHasNoTabs(self): |
1326 self.ContentTest(presubmit_canned_checks.CheckChangeHasNoTabs, | 1327 self.ContentTest(presubmit_canned_checks.CheckChangeHasNoTabs, |
1327 'blah blah', 'blah\tblah', | 1328 'blah blah', 'blah\tblah', |
1328 presubmit.OutputApi.PresubmitPromptWarning) | 1329 presubmit.OutputApi.PresubmitPromptWarning) |
1329 | 1330 |
| 1331 # Make sure makefiles are ignored. |
| 1332 change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None, |
| 1333 0, 0) |
| 1334 input_api1 = self.MockInputApi(change1, False) |
| 1335 affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 1336 affected_file1.LocalPath().AndReturn('foo.cc') |
| 1337 affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 1338 affected_file2.LocalPath().AndReturn('foo/Makefile') |
| 1339 affected_file3 = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 1340 affected_file3.LocalPath().AndReturn('makefile') |
| 1341 # Only this one will trigger. |
| 1342 affected_file4 = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 1343 affected_file4.LocalPath().AndReturn('makefile.foo') |
| 1344 affected_file4.LocalPath().AndReturn('makefile.foo') |
| 1345 output1 = [ |
| 1346 (affected_file1, 42, 'yo, '), |
| 1347 (affected_file2, 43, 'yer\t'), |
| 1348 (affected_file3, 45, 'yr\t'), |
| 1349 (affected_file4, 46, 'ye\t'), |
| 1350 ] |
| 1351 def test(source_filter): |
| 1352 for i in output1: |
| 1353 if source_filter(i[0]): |
| 1354 yield i |
| 1355 # Override the mock of these functions. |
| 1356 input_api1.FilterSourceFile = lambda x: x |
| 1357 input_api1.RightHandSideLines = test |
| 1358 self.mox.ReplayAll() |
| 1359 |
| 1360 results1 = presubmit_canned_checks.CheckChangeHasNoTabs(input_api1, |
| 1361 presubmit.OutputApi, None) |
| 1362 self.assertEquals(len(results1), 1) |
| 1363 self.assertEquals(results1[0].__class__, |
| 1364 presubmit.OutputApi.PresubmitPromptWarning) |
| 1365 self.assertEquals(results1[0]._long_text, |
| 1366 'makefile.foo, line 46') |
| 1367 |
| 1368 |
1330 def testCannedCheckLongLines(self): | 1369 def testCannedCheckLongLines(self): |
1331 check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) | 1370 check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) |
1332 self.ContentTest(check, '', 'blah blah blah', | 1371 self.ContentTest(check, '', 'blah blah blah', |
1333 presubmit.OutputApi.PresubmitPromptWarning) | 1372 presubmit.OutputApi.PresubmitPromptWarning) |
1334 | 1373 |
1335 def testCheckChangeSvnEolStyleCommit(self): | 1374 def testCheckChangeSvnEolStyleCommit(self): |
1336 # Test CheckSvnProperty at the same time. | 1375 # Test CheckSvnProperty at the same time. |
1337 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, | 1376 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, |
1338 'svn:eol-style', 'LF', '', True, | 1377 'svn:eol-style', 'LF', '', True, |
1339 presubmit.OutputApi.PresubmitError, True) | 1378 presubmit.OutputApi.PresubmitError, True) |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( | 1698 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( |
1660 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) | 1699 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) |
1661 self.assertEquals(len(results), 1) | 1700 self.assertEquals(len(results), 1) |
1662 self.assertEquals(results[0].__class__, | 1701 self.assertEquals(results[0].__class__, |
1663 presubmit.OutputApi.PresubmitNotifyResult) | 1702 presubmit.OutputApi.PresubmitNotifyResult) |
1664 | 1703 |
1665 | 1704 |
1666 if __name__ == '__main__': | 1705 if __name__ == '__main__': |
1667 import unittest | 1706 import unittest |
1668 unittest.main() | 1707 unittest.main() |
OLD | NEW |