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 self.assertTrue(':1 OS_WINDOWS' in errors[0]) | 406 self.assertTrue(':1 OS_WINDOWS' in errors[0]) |
407 self.assertTrue('(did you mean OS_WIN?)' in errors[0]) | 407 self.assertTrue('(did you mean OS_WIN?)' in errors[0]) |
408 | 408 |
409 def testValidOSMacroNames(self): | 409 def testValidOSMacroNames(self): |
410 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] | 410 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] |
411 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( | 411 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( |
412 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) | 412 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
413 self.assertEqual(0, len(errors)) | 413 self.assertEqual(0, len(errors)) |
414 | 414 |
415 | 415 |
416 class InvalidOverideAndFinalTest(unittest.TestCase): | |
417 def testValidOverrideConstructs(self): | |
418 mock_input_api = MockInputApi() | |
419 lines = ['foo1() override;', | |
420 'foo2() final;', | |
421 '#DEFINE OVERRIDE_METHOD_OVERLOAD', | |
422 '#DEFINE FINAL_METHOD', | |
423 '#DEFINE OVERRIDE_OVERRIDE_SOMETHING', | |
424 '#DEFINE SOMETHING_OVERRIDE_SOMETHING', | |
425 '#DEFINE SOMETHING_SOMETHING_OVERRIDE', | |
426 '#DEFINE FINAL_OVERRIDE_FINAL', | |
427 '#DEFINE SOMETHING_OVERRIDE_FINAL', | |
428 '#DEFINE OVERRIDE_OVERRIDE_OVERRIDE', | |
429 '#endif // FINAL_METHOD', | |
430 '#endif // OVERRIDE_METHOD_OVERLOAD'] | |
431 mock_file_h = MockFile('something.h', lines) | |
432 mock_input_api.files = [mock_file_h] | |
433 errors = PRESUBMIT._CheckForOverrideAndFinalRules(mock_input_api, | |
434 MockOutputApi()) | |
435 self.assertEqual(0, len(errors)) | |
436 | |
437 def testInvalidOverrideConstructsInHeaders(self): | |
438 mock_input_api = MockInputApi() | |
439 lines_cpp = ['foo2() FINAL;'] | |
440 lines_h = ['foo1() OVERRIDE;'] | |
441 mock_file_cpp = MockFile('something.cpp', lines_cpp) | |
442 mock_file_h = MockFile('something.h', lines_h) | |
443 mock_input_api.files = [mock_file_cpp, mock_file_h] | |
444 errors = PRESUBMIT._CheckForOverrideAndFinalRules(mock_input_api, | |
445 MockOutputApi()) | |
446 self.assertEqual(1, len(errors)) | |
447 | |
448 def testInvalidOverrideConstructsInCpp(self): | |
449 mock_input_api = MockInputApi() | |
450 lines_cpp = ['foo2() FINAL;'] | |
451 mock_file_cpp = MockFile('something.cpp', lines_cpp) | |
452 mock_input_api.files = [mock_file_cpp] | |
453 errors = PRESUBMIT._CheckForOverrideAndFinalRules(mock_input_api, | |
454 MockOutputApi()) | |
455 self.assertEqual(1, len(errors)) | |
456 | |
457 def testInvalidOverrideConstructsInCc(self): | |
458 mock_input_api = MockInputApi() | |
459 lines_cc = ['foo3() override FINAL;'] | |
460 mock_file_cc = MockFile('something.cc', lines_cc) | |
461 mock_input_api.files = [mock_file_cc] | |
462 errors = PRESUBMIT._CheckForOverrideAndFinalRules(mock_input_api, | |
463 MockOutputApi()) | |
464 self.assertEqual(1, len(errors)) | |
465 | |
466 def testInvalidOverrideConstructsInMm(self): | |
467 mock_input_api = MockInputApi() | |
468 lines_mm = ['foo4() OVERRIDE final;'] | |
469 mock_file_mm = MockFile('something.mm', lines_mm) | |
470 mock_input_api.files = [mock_file_mm] | |
471 errors = PRESUBMIT._CheckForOverrideAndFinalRules(mock_input_api, | |
472 MockOutputApi()) | |
473 self.assertEqual(1, len(errors)) | |
474 | |
475 | |
476 class InvalidIfDefinedMacroNamesTest(unittest.TestCase): | 416 class InvalidIfDefinedMacroNamesTest(unittest.TestCase): |
477 def testInvalidIfDefinedMacroNames(self): | 417 def testInvalidIfDefinedMacroNames(self): |
478 lines = ['#if defined(TARGET_IPHONE_SIMULATOR)', | 418 lines = ['#if defined(TARGET_IPHONE_SIMULATOR)', |
479 '#if !defined(TARGET_IPHONE_SIMULATOR)', | 419 '#if !defined(TARGET_IPHONE_SIMULATOR)', |
480 '#elif defined(TARGET_IPHONE_SIMULATOR)', | 420 '#elif defined(TARGET_IPHONE_SIMULATOR)', |
481 '#ifdef TARGET_IPHONE_SIMULATOR', | 421 '#ifdef TARGET_IPHONE_SIMULATOR', |
482 ' # ifdef TARGET_IPHONE_SIMULATOR', | 422 ' # ifdef TARGET_IPHONE_SIMULATOR', |
483 '# if defined(VALID) || defined(TARGET_IPHONE_SIMULATOR)', | 423 '# if defined(VALID) || defined(TARGET_IPHONE_SIMULATOR)', |
484 '# else // defined(TARGET_IPHONE_SIMULATOR)', | 424 '# else // defined(TARGET_IPHONE_SIMULATOR)', |
485 '#endif // defined(TARGET_IPHONE_SIMULATOR)',] | 425 '#endif // defined(TARGET_IPHONE_SIMULATOR)',] |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 } | 776 } |
837 for master, bots in bots.iteritems(): | 777 for master, bots in bots.iteritems(): |
838 for bot in bots: | 778 for bot in bots: |
839 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), | 779 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), |
840 'bot=%s: expected %s, computed %s' % ( | 780 'bot=%s: expected %s, computed %s' % ( |
841 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) | 781 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) |
842 | 782 |
843 | 783 |
844 if __name__ == '__main__': | 784 if __name__ == '__main__': |
845 unittest.main() | 785 unittest.main() |
OLD | NEW |