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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 409 |
410 def testSingletonInCC(self): | 410 def testSingletonInCC(self): |
411 diff_cc = ['Foo* foo = base::Singleton<Foo>::get();'] | 411 diff_cc = ['Foo* foo = base::Singleton<Foo>::get();'] |
412 mock_input_api = MockInputApi() | 412 mock_input_api = MockInputApi() |
413 mock_input_api.files = [MockAffectedFile('some/path/foo.cc', diff_cc)] | 413 mock_input_api.files = [MockAffectedFile('some/path/foo.cc', diff_cc)] |
414 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api, | 414 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api, |
415 MockOutputApi()) | 415 MockOutputApi()) |
416 self.assertEqual(0, len(warnings)) | 416 self.assertEqual(0, len(warnings)) |
417 | 417 |
418 | 418 |
419 class CheckBaseMacrosInHeadersTest(unittest.TestCase): | |
420 def _make_h(self, macro, header, line_prefix=''): | |
421 return (""" | |
422 #include "base/%s.h" | |
423 | |
424 class Thing { | |
425 private: | |
426 %sDISALLOW_%s(Thing); | |
427 }; | |
428 """ % (macro, line_prefix, header)).splitlines() | |
429 | |
430 def testBaseMacrosInHeadersBad(self): | |
431 mock_input_api = MockInputApi() | |
432 mock_input_api.files = [ | |
433 MockAffectedFile('foo.h', self._make_h('not_macros', 'ASSIGN')), | |
434 MockAffectedFile('bar.h', self._make_h('not_macros', 'COPY')), | |
435 MockAffectedFile('baz.h', self._make_h('not_macros', 'COPY_AND_ASSIGN')), | |
436 MockAffectedFile('qux.h', self._make_h('not_macros', 'EVIL')), | |
437 ] | |
438 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, | |
439 MockOutputApi()) | |
440 self.assertEqual(1, len(warnings)) | |
441 self.assertEqual(4, len(warnings[0].items)) | |
442 | |
443 def testBaseMacrosInHeadersGood(self): | |
444 mock_input_api = MockInputApi() | |
445 mock_input_api.files = [ | |
446 MockAffectedFile('foo.h', self._make_h('macros', 'ASSIGN')), | |
447 MockAffectedFile('bar.h', self._make_h('macros', 'COPY')), | |
448 MockAffectedFile('baz.h', self._make_h('macros', 'COPY_AND_ASSIGN')), | |
449 MockAffectedFile('qux.h', self._make_h('macros', 'EVIL')), | |
450 MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', '//')), | |
451 MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', ' //')), | |
452 ] | |
453 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, | |
454 MockOutputApi()) | |
455 self.assertEqual(0, len(warnings)) | |
456 | |
457 | |
458 class InvalidOSMacroNamesTest(unittest.TestCase): | 419 class InvalidOSMacroNamesTest(unittest.TestCase): |
459 def testInvalidOSMacroNames(self): | 420 def testInvalidOSMacroNames(self): |
460 lines = ['#if defined(OS_WINDOWS)', | 421 lines = ['#if defined(OS_WINDOWS)', |
461 ' #elif defined(OS_WINDOW)', | 422 ' #elif defined(OS_WINDOW)', |
462 ' # if defined(OS_MACOSX) || defined(OS_CHROME)', | 423 ' # if defined(OS_MACOSX) || defined(OS_CHROME)', |
463 '# else // defined(OS_MAC)', | 424 '# else // defined(OS_MAC)', |
464 '#endif // defined(OS_MACOS)'] | 425 '#endif // defined(OS_MACOS)'] |
465 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( | 426 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( |
466 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) | 427 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
467 self.assertEqual(len(lines), len(errors)) | 428 self.assertEqual(len(lines), len(errors)) |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 ['char* host = "https://www.aol.com"; // google.com']) | 972 ['char* host = "https://www.aol.com"; // google.com']) |
1012 ] | 973 ] |
1013 | 974 |
1014 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( | 975 warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( |
1015 input_api, MockOutputApi()) | 976 input_api, MockOutputApi()) |
1016 self.assertEqual(0, len(warnings)) | 977 self.assertEqual(0, len(warnings)) |
1017 | 978 |
1018 | 979 |
1019 if __name__ == '__main__': | 980 if __name__ == '__main__': |
1020 unittest.main() | 981 unittest.main() |
OLD | NEW |