Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: PRESUBMIT_test.py

Issue 344563003: Add PRESUBMIT.py warning for contradictory NOTREACHED() use. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 CheckContradictoryNotreachedUseTest(unittest.TestCase):
417 def testValid(self):
418 lines = ['{',
419 ' // NOTREACHED();',
420 ' /* NOTREACHED(); */',
421 " char a = '\\\\', b = '\\0', c = '\\'';",
422 ' char d[] = "NOTREACHED();";',
423 ' NOTREACHED(); // blah',
424 ' /* comment */',
425 ' // line continuation \\',
426 ' still inside comment',
427 ' // comment followed by empty line',
428 '',
429 ' ;; ; ;;;',
430 '}',
431 'switch (i) {',
432 ' case 7: NOTREACHED(); break;',
433 '}']
434 output = PRESUBMIT._CheckContradictoryNotreachedUseInFile(
435 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
436 self.assertEqual(0, len(output))
437
438 def testInvalid(self):
439 lines = ['{',
440 ' NOTREACHED();',
441 ' return;',
442 '}',
443 '{',
444 ' NOTREACHED();',
445 ' /* */',
446 ' return;',
447 ' /* */',
448 '}',
449 '{',
450 ' NOTREACHED();',
451 ' // trailing space, not a line continuation \\ ',
452 ' return;',
453 '}',
454 'switch (i) {',
455 ' case 7: NOTREACHED(); some_thing(); break;',
456 '}']
457 output = PRESUBMIT._CheckContradictoryNotreachedUseInFile(
458 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
459 self.assertEqual(4, len(output))
460
461
416 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): 462 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase):
417 def testFilesToCheckForIncomingDeps(self): 463 def testFilesToCheckForIncomingDeps(self):
418 changed_lines = [ 464 changed_lines = [
419 '"+breakpad",', 465 '"+breakpad",',
420 '"+chrome/installer",', 466 '"+chrome/installer",',
421 '"+chrome/plugin/chrome_content_plugin_client.h",', 467 '"+chrome/plugin/chrome_content_plugin_client.h",',
422 '"+chrome/utility/chrome_content_utility_client.h",', 468 '"+chrome/utility/chrome_content_utility_client.h",',
423 '"+chromeos/chromeos_paths.h",', 469 '"+chromeos/chromeos_paths.h",',
424 '"+components/breakpad",', 470 '"+components/breakpad",',
425 '"+components/nacl/common",', 471 '"+components/nacl/common",',
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 for (filename, contents, _) in test_data] 689 for (filename, contents, _) in test_data]
644 690
645 for (filename, _, expected_error) in test_data: 691 for (filename, _, expected_error) in test_data:
646 actual_error = PRESUBMIT._GetIDLParseError(input_api, filename) 692 actual_error = PRESUBMIT._GetIDLParseError(input_api, filename)
647 self.assertTrue(expected_error in str(actual_error), 693 self.assertTrue(expected_error in str(actual_error),
648 "'%s' not found in '%s'" % (expected_error, actual_error)) 694 "'%s' not found in '%s'" % (expected_error, actual_error))
649 695
650 696
651 if __name__ == '__main__': 697 if __name__ == '__main__':
652 unittest.main() 698 unittest.main()
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698