OLD | NEW |
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 glob | 6 import glob |
7 import json | 7 import json |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 %sDISALLOW_%s(Thing); | 426 %sDISALLOW_%s(Thing); |
427 }; | 427 }; |
428 """ % (macro, line_prefix, header)).splitlines() | 428 """ % (macro, line_prefix, header)).splitlines() |
429 | 429 |
430 def testBaseMacrosInHeadersBad(self): | 430 def testBaseMacrosInHeadersBad(self): |
431 mock_input_api = MockInputApi() | 431 mock_input_api = MockInputApi() |
432 mock_input_api.files = [ | 432 mock_input_api.files = [ |
433 MockAffectedFile('foo.h', self._make_h('not_macros', 'ASSIGN')), | 433 MockAffectedFile('foo.h', self._make_h('not_macros', 'ASSIGN')), |
434 MockAffectedFile('bar.h', self._make_h('not_macros', 'COPY')), | 434 MockAffectedFile('bar.h', self._make_h('not_macros', 'COPY')), |
435 MockAffectedFile('baz.h', self._make_h('not_macros', 'COPY_AND_ASSIGN')), | 435 MockAffectedFile('baz.h', self._make_h('not_macros', 'COPY_AND_ASSIGN')), |
436 MockAffectedFile('qux.h', self._make_h('not_macros', 'EVIL')), | 436 MockAffectedFile('qux.h', self._make_h('not_macros', |
| 437 'EVIL_CONSTRUCTORS')), |
| 438 MockAffectedFile('quux.h', self._make_h('not_macros', |
| 439 'IMPLICIT_CONSTRUCTORS')), |
437 ] | 440 ] |
438 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, | 441 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, |
439 MockOutputApi()) | 442 MockOutputApi()) |
440 self.assertEqual(1, len(warnings)) | 443 self.assertEqual(1, len(warnings)) |
441 self.assertEqual(4, len(warnings[0].items)) | 444 self.assertEqual(len(mock_input_api.files), len(warnings[0].items)) |
442 | 445 |
443 def testBaseMacrosInHeadersGood(self): | 446 def testBaseMacrosInHeadersGood(self): |
444 mock_input_api = MockInputApi() | 447 mock_input_api = MockInputApi() |
445 mock_input_api.files = [ | 448 mock_input_api.files = [ |
446 MockAffectedFile('foo.h', self._make_h('macros', 'ASSIGN')), | 449 MockAffectedFile('foo.h', self._make_h('macros', 'ASSIGN')), |
447 MockAffectedFile('bar.h', self._make_h('macros', 'COPY')), | 450 MockAffectedFile('bar.h', self._make_h('macros', 'COPY')), |
448 MockAffectedFile('baz.h', self._make_h('macros', 'COPY_AND_ASSIGN')), | 451 MockAffectedFile('baz.h', self._make_h('macros', 'COPY_AND_ASSIGN')), |
449 MockAffectedFile('qux.h', self._make_h('macros', 'EVIL')), | 452 MockAffectedFile('qux.h', self._make_h('macros', 'EVIL_CONSTRUCTORS')), |
450 MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', '//')), | 453 MockAffectedFile('quux.h', self._make_h('macros', |
451 MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', ' //')), | 454 'IMPLICIT_CONSTRUCTORS')), |
| 455 MockAffectedFile('corge.h', self._make_h('not_macros', 'ASSIGN', '//')), |
| 456 MockAffectedFile('grault.h', self._make_h('not_macros', 'ASSIGN', ' //')), |
452 ] | 457 ] |
453 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, | 458 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, |
454 MockOutputApi()) | 459 MockOutputApi()) |
455 self.assertEqual(0, len(warnings)) | 460 self.assertEqual(0, len(warnings)) |
456 | 461 |
457 | 462 |
458 class InvalidOSMacroNamesTest(unittest.TestCase): | 463 class InvalidOSMacroNamesTest(unittest.TestCase): |
459 def testInvalidOSMacroNames(self): | 464 def testInvalidOSMacroNames(self): |
460 lines = ['#if defined(OS_WINDOWS)', | 465 lines = ['#if defined(OS_WINDOWS)', |
461 ' #elif defined(OS_WINDOW)', | 466 ' #elif defined(OS_WINDOW)', |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 ['char* host = "https://www.aol.com"; // google.com']) | 1016 ['char* host = "https://www.aol.com"; // google.com']) |
1012 ] | 1017 ] |
1013 | 1018 |
1014 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( | 1019 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( |
1015 input_api, MockOutputApi()) | 1020 input_api, MockOutputApi()) |
1016 self.assertEqual(0, len(warnings)) | 1021 self.assertEqual(0, len(warnings)) |
1017 | 1022 |
1018 | 1023 |
1019 if __name__ == '__main__': | 1024 if __name__ == '__main__': |
1020 unittest.main() | 1025 unittest.main() |
OLD | NEW |