| 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 406 |
| 407 def testSingletonInCC(self): | 407 def testSingletonInCC(self): |
| 408 diff_cc = ['Foo* foo = base::Singleton<Foo>::get();'] | 408 diff_cc = ['Foo* foo = base::Singleton<Foo>::get();'] |
| 409 mock_input_api = MockInputApi() | 409 mock_input_api = MockInputApi() |
| 410 mock_input_api.files = [MockAffectedFile('some/path/foo.cc', diff_cc)] | 410 mock_input_api.files = [MockAffectedFile('some/path/foo.cc', diff_cc)] |
| 411 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api, | 411 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api, |
| 412 MockOutputApi()) | 412 MockOutputApi()) |
| 413 self.assertEqual(0, len(warnings)) | 413 self.assertEqual(0, len(warnings)) |
| 414 | 414 |
| 415 | 415 |
| 416 class CheckBaseMacrosInHeadersTest(unittest.TestCase): |
| 417 def _make_h(self, macro, header): |
| 418 return (""" |
| 419 #include "base/%s.h" |
| 420 |
| 421 class Thing { |
| 422 private: |
| 423 DISALLOW_%s(Thing); |
| 424 }; |
| 425 """ % (macro, header)).splitlines() |
| 426 |
| 427 def testBaseMacrosInHeadersBad(self): |
| 428 mock_input_api = MockInputApi() |
| 429 mock_input_api.files = [ |
| 430 MockAffectedFile('foo.h', self._make_h('not_macros', 'ASSIGN')), |
| 431 MockAffectedFile('bar.h', self._make_h('not_macros', 'COPY')), |
| 432 MockAffectedFile('baz.h', self._make_h('not_macros', 'COPY_AND_ASSIGN')), |
| 433 MockAffectedFile('qux.h', self._make_h('not_macros', 'EVIL')), |
| 434 ] |
| 435 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, |
| 436 MockOutputApi()) |
| 437 self.assertEqual(1, len(warnings)) |
| 438 self.assertEqual(4, len(warnings[0].items)) |
| 439 |
| 440 def testBaseMacrosInHeadersGood(self): |
| 441 mock_input_api = MockInputApi() |
| 442 mock_input_api.files = [ |
| 443 MockAffectedFile('foo.h', self._make_h('macros', 'ASSIGN')), |
| 444 MockAffectedFile('bar.h', self._make_h('macros', 'COPY')), |
| 445 MockAffectedFile('baz.h', self._make_h('macros', 'COPY_AND_ASSIGN')), |
| 446 MockAffectedFile('qux.h', self._make_h('macros', 'EVIL')), |
| 447 ] |
| 448 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, |
| 449 MockOutputApi()) |
| 450 self.assertEqual(0, len(warnings)) |
| 451 |
| 452 |
| 416 class InvalidOSMacroNamesTest(unittest.TestCase): | 453 class InvalidOSMacroNamesTest(unittest.TestCase): |
| 417 def testInvalidOSMacroNames(self): | 454 def testInvalidOSMacroNames(self): |
| 418 lines = ['#if defined(OS_WINDOWS)', | 455 lines = ['#if defined(OS_WINDOWS)', |
| 419 ' #elif defined(OS_WINDOW)', | 456 ' #elif defined(OS_WINDOW)', |
| 420 ' # if defined(OS_MACOSX) || defined(OS_CHROME)', | 457 ' # if defined(OS_MACOSX) || defined(OS_CHROME)', |
| 421 '# else // defined(OS_MAC)', | 458 '# else // defined(OS_MAC)', |
| 422 '#endif // defined(OS_MACOS)'] | 459 '#endif // defined(OS_MACOS)'] |
| 423 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( | 460 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( |
| 424 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) | 461 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
| 425 self.assertEqual(len(lines), len(errors)) | 462 self.assertEqual(len(lines), len(errors)) |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 # Tag must not contain | 977 # Tag must not contain |
| 941 nb = len(msgs[4].items) | 978 nb = len(msgs[4].items) |
| 942 self.assertEqual(2, nb, | 979 self.assertEqual(2, nb, |
| 943 'Expected %d items, found %d: %s' % (2, nb, msgs[4].items)) | 980 'Expected %d items, found %d: %s' % (2, nb, msgs[4].items)) |
| 944 self.assertTrue('HasDottedTag.java' in msgs[4].items) | 981 self.assertTrue('HasDottedTag.java' in msgs[4].items) |
| 945 self.assertTrue('HasOldTag.java' in msgs[4].items) | 982 self.assertTrue('HasOldTag.java' in msgs[4].items) |
| 946 | 983 |
| 947 | 984 |
| 948 if __name__ == '__main__': | 985 if __name__ == '__main__': |
| 949 unittest.main() | 986 unittest.main() |
| OLD | NEW |