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 os | 6 import os |
7 import re | 7 import re |
8 import unittest | 8 import unittest |
9 | 9 |
10 import PRESUBMIT | 10 import PRESUBMIT |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 self.assertTrue(':1 OS_WINDOWS' in errors[0]) | 386 self.assertTrue(':1 OS_WINDOWS' in errors[0]) |
387 self.assertTrue('(did you mean OS_WIN?)' in errors[0]) | 387 self.assertTrue('(did you mean OS_WIN?)' in errors[0]) |
388 | 388 |
389 def testValidOSMacroNames(self): | 389 def testValidOSMacroNames(self): |
390 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] | 390 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS] |
391 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( | 391 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( |
392 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) | 392 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
393 self.assertEqual(0, len(errors)) | 393 self.assertEqual(0, len(errors)) |
394 | 394 |
395 | 395 |
| 396 class CheckContradictoryNotreachedUseTest(unittest.TestCase): |
| 397 def testValid(self): |
| 398 lines = ['{', |
| 399 ' // NOTREACHED();', |
| 400 ' /* NOTREACHED(); */', |
| 401 " char a = '\\\\', b = '\\0', c = '\\'';", |
| 402 ' char d[] = "NOTREACHED();";', |
| 403 ' NOTREACHED(); // blah', |
| 404 ' /* comment */', |
| 405 ' // line continuation \\', |
| 406 ' still inside comment', |
| 407 ' // line continuation with MS-DOS line end \\\r', |
| 408 ' still inside comment', |
| 409 ' // comment followed by empty line', |
| 410 '', |
| 411 ' ;; ; ;;;', |
| 412 '}', |
| 413 'switch (i) {', |
| 414 ' case 7: NOTREACHED(); break;', |
| 415 '}'] |
| 416 output = PRESUBMIT._CheckContradictoryNotreachedUseInFile( |
| 417 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
| 418 self.assertEqual(0, len(output)) |
| 419 |
| 420 def testInvalid(self): |
| 421 lines = ['{', |
| 422 ' NOTREACHED();', |
| 423 ' return;', |
| 424 '}', |
| 425 '{', |
| 426 ' NOTREACHED();', |
| 427 ' /* */', |
| 428 ' return;', |
| 429 ' /* */', |
| 430 '}', |
| 431 '{', |
| 432 ' NOTREACHED();', |
| 433 ' // trailing space, not a line continuation \\ ', |
| 434 ' return;', |
| 435 '}', |
| 436 'switch (i) {', |
| 437 ' case 7: NOTREACHED(); some_thing(); break;', |
| 438 '}'] |
| 439 output = PRESUBMIT._CheckContradictoryNotreachedUseInFile( |
| 440 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
| 441 self.assertEqual(4, len(output)) |
| 442 |
| 443 |
396 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): | 444 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): |
397 def testFilesToCheckForIncomingDeps(self): | 445 def testFilesToCheckForIncomingDeps(self): |
398 changed_lines = [ | 446 changed_lines = [ |
399 '"+breakpad",', | 447 '"+breakpad",', |
400 '"+chrome/installer",', | 448 '"+chrome/installer",', |
401 '"+chrome/plugin/chrome_content_plugin_client.h",', | 449 '"+chrome/plugin/chrome_content_plugin_client.h",', |
402 '"+chrome/utility/chrome_content_utility_client.h",', | 450 '"+chrome/utility/chrome_content_utility_client.h",', |
403 '"+chromeos/chromeos_paths.h",', | 451 '"+chromeos/chromeos_paths.h",', |
404 '"+components/breakpad",', | 452 '"+components/breakpad",', |
405 '"+components/nacl/common",', | 453 '"+components/nacl/common",', |
(...skipping 20 matching lines...) Expand all Loading... |
426 'policy/DEPS', | 474 'policy/DEPS', |
427 'sandbox/DEPS', | 475 'sandbox/DEPS', |
428 'tools/memory_watcher/DEPS', | 476 'tools/memory_watcher/DEPS', |
429 'third_party/lss/linux_syscall_support.h', | 477 'third_party/lss/linux_syscall_support.h', |
430 ]) | 478 ]) |
431 self.assertEqual(expected, files_to_check); | 479 self.assertEqual(expected, files_to_check); |
432 | 480 |
433 | 481 |
434 if __name__ == '__main__': | 482 if __name__ == '__main__': |
435 unittest.main() | 483 unittest.main() |
OLD | NEW |