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 = [r'{', |
| 399 r" char a = '\\', b = '\0', c = '\'';", |
| 400 r' char d[] = "NOTREACHED();";', |
| 401 r' NOTREACHED(); // NOTREACHED();', |
| 402 r' /* NOTREACHED(); */', |
| 403 r' // line continuation \\', |
| 404 r' still inside comment', |
| 405 r' // comment followed by empty line', |
| 406 r'', |
| 407 r'}', |
| 408 r'switch (i) {', |
| 409 r' case 7: NOTREACHED(); break;', |
| 410 r'}'] |
| 411 output = PRESUBMIT._CheckContradictoryNotreachedUseInFile( |
| 412 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
| 413 self.assertEqual(0, len(output)) |
| 414 |
| 415 def testInvalid(self): |
| 416 lines = ['{', |
| 417 ' NOTREACHED();', |
| 418 ' return;', |
| 419 '}', |
| 420 '{', |
| 421 ' NOTREACHED();', |
| 422 ' /* */', |
| 423 ' return;', |
| 424 ' /* */', |
| 425 '}', |
| 426 'switch (i) {', |
| 427 ' case 7: NOTREACHED(); some_thing(); break;', |
| 428 '}'] |
| 429 output = PRESUBMIT._CheckContradictoryNotreachedUseInFile( |
| 430 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
| 431 self.assertEqual(3, len(output)) |
| 432 |
| 433 |
396 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): | 434 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): |
397 def testFilesToCheckForIncomingDeps(self): | 435 def testFilesToCheckForIncomingDeps(self): |
398 changed_lines = [ | 436 changed_lines = [ |
399 '"+breakpad",', | 437 '"+breakpad",', |
400 '"+chrome/installer",', | 438 '"+chrome/installer",', |
401 '"+chrome/plugin/chrome_content_plugin_client.h",', | 439 '"+chrome/plugin/chrome_content_plugin_client.h",', |
402 '"+chrome/utility/chrome_content_utility_client.h",', | 440 '"+chrome/utility/chrome_content_utility_client.h",', |
403 '"+chromeos/chromeos_paths.h",', | 441 '"+chromeos/chromeos_paths.h",', |
404 '"+components/breakpad",', | 442 '"+components/breakpad",', |
405 '"+components/nacl/common",', | 443 '"+components/nacl/common",', |
(...skipping 20 matching lines...) Expand all Loading... |
426 'policy/DEPS', | 464 'policy/DEPS', |
427 'sandbox/DEPS', | 465 'sandbox/DEPS', |
428 'tools/memory_watcher/DEPS', | 466 'tools/memory_watcher/DEPS', |
429 'third_party/lss/linux_syscall_support.h', | 467 'third_party/lss/linux_syscall_support.h', |
430 ]) | 468 ]) |
431 self.assertEqual(expected, files_to_check); | 469 self.assertEqual(expected, files_to_check); |
432 | 470 |
433 | 471 |
434 if __name__ == '__main__': | 472 if __name__ == '__main__': |
435 unittest.main() | 473 unittest.main() |
OLD | NEW |