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.path |
6 import re | 7 import re |
7 import subprocess | 8 import subprocess |
8 import unittest | 9 import unittest |
9 | 10 |
10 import PRESUBMIT | 11 import PRESUBMIT |
11 from PRESUBMIT_test_mocks import MockChange, MockFile, MockAffectedFile | 12 from PRESUBMIT_test_mocks import MockChange, MockFile, MockAffectedFile |
12 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi | 13 from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi |
13 | 14 |
14 _TEST_DATA_DIR = 'base/test/data/presubmit' | 15 _TEST_DATA_DIR = 'base/test/data/presubmit' |
15 | 16 |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 463 |
463 def testValidIfDefinedMacroNames(self): | 464 def testValidIfDefinedMacroNames(self): |
464 lines = ['#if defined(FOO)', | 465 lines = ['#if defined(FOO)', |
465 '#ifdef BAR',] | 466 '#ifdef BAR',] |
466 errors = PRESUBMIT._CheckForInvalidIfDefinedMacrosInFile( | 467 errors = PRESUBMIT._CheckForInvalidIfDefinedMacrosInFile( |
467 MockInputApi(), MockFile('some/path/source.cc', lines)) | 468 MockInputApi(), MockFile('some/path/source.cc', lines)) |
468 self.assertEqual(0, len(errors)) | 469 self.assertEqual(0, len(errors)) |
469 | 470 |
470 | 471 |
471 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): | 472 class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase): |
472 def testFilesToCheckForIncomingDeps(self): | 473 |
473 changed_lines = [ | 474 def calculate(self, old_include_rules, old_specific_include_rules, |
474 '"+breakpad",', | 475 new_include_rules, new_specific_include_rules): |
475 '"+chrome/installer",', | 476 return PRESUBMIT._CalculateAddedDeps( |
476 '"+chrome/plugin/chrome_content_plugin_client.h",', | 477 os.path, 'include_rules = %r\nspecific_include_rules = %r' % ( |
477 '"+chrome/utility/chrome_content_utility_client.h",', | 478 old_include_rules, old_specific_include_rules), |
478 '"+chromeos/chromeos_paths.h",', | 479 'include_rules = %r\nspecific_include_rules = %r' % ( |
479 '"+components/crash/content",', | 480 new_include_rules, new_specific_include_rules)) |
480 '"+components/nacl/common",', | 481 |
481 '"+content/public/browser/render_process_host.h",', | 482 def testCalculateAddedDeps(self): |
482 '"+jni/fooblat.h",', | 483 old_include_rules = [ |
483 '"+grit", # For generated headers', | 484 '+base', |
484 '"+grit/generated_resources.h",', | 485 '-chrome', |
485 '"+grit/",', | 486 '+content', |
486 '"+policy", # For generated headers and source', | 487 '-grit', |
487 '"+sandbox",', | 488 '-grit/",', |
488 '"+tools/memory_watcher",', | 489 '+jni/fooblat.h', |
489 '"+third_party/lss/linux_syscall_support.h",', | 490 '!sandbox', |
490 ] | 491 ] |
491 files_to_check = PRESUBMIT._FilesToCheckForIncomingDeps(re, changed_lines) | 492 old_specific_include_rules = { |
| 493 'compositor\.*': { |
| 494 '+cc', |
| 495 }, |
| 496 } |
| 497 |
| 498 new_include_rules = [ |
| 499 '-ash', |
| 500 '+base', |
| 501 '+chrome', |
| 502 '+components', |
| 503 '+content', |
| 504 '+grit', |
| 505 '+grit/generated_resources.h",', |
| 506 '+grit/",', |
| 507 '+jni/fooblat.h', |
| 508 '+policy', |
| 509 '+third_party/WebKit', |
| 510 ] |
| 511 new_specific_include_rules = { |
| 512 'compositor\.*': { |
| 513 '+cc', |
| 514 }, |
| 515 'widget\.*': { |
| 516 '+gpu', |
| 517 }, |
| 518 } |
| 519 |
492 expected = set([ | 520 expected = set([ |
493 'breakpad/DEPS', | 521 'chrome/DEPS', |
494 'chrome/installer/DEPS', | 522 'gpu/DEPS', |
495 'chrome/plugin/chrome_content_plugin_client.h', | 523 'components/DEPS', |
496 'chrome/utility/chrome_content_utility_client.h', | 524 'policy/DEPS', |
497 'chromeos/chromeos_paths.h', | 525 'third_party/WebKit/DEPS', |
498 'components/crash/content/DEPS', | |
499 'components/nacl/common/DEPS', | |
500 'content/public/browser/render_process_host.h', | |
501 'policy/DEPS', | |
502 'sandbox/DEPS', | |
503 'tools/memory_watcher/DEPS', | |
504 'third_party/lss/linux_syscall_support.h', | |
505 ]) | 526 ]) |
506 self.assertEqual(expected, files_to_check); | 527 self.assertEqual( |
| 528 expected, |
| 529 self.calculate(old_include_rules, old_specific_include_rules, |
| 530 new_include_rules, new_specific_include_rules)) |
| 531 |
| 532 def testCalculateAddedDepsIgnoresPermutations(self): |
| 533 old_include_rules = [ |
| 534 '+base', |
| 535 '+chrome', |
| 536 ] |
| 537 new_include_rules = [ |
| 538 '+chrome', |
| 539 '+base', |
| 540 ] |
| 541 self.assertEqual(set(), |
| 542 self.calculate(old_include_rules, {}, new_include_rules, |
| 543 {})) |
507 | 544 |
508 | 545 |
509 class JSONParsingTest(unittest.TestCase): | 546 class JSONParsingTest(unittest.TestCase): |
510 def testSuccess(self): | 547 def testSuccess(self): |
511 input_api = MockInputApi() | 548 input_api = MockInputApi() |
512 filename = 'valid_json.json' | 549 filename = 'valid_json.json' |
513 contents = ['// This is a comment.', | 550 contents = ['// This is a comment.', |
514 '{', | 551 '{', |
515 ' "key1": ["value1", "value2"],', | 552 ' "key1": ["value1", "value2"],', |
516 ' "key2": 3 // This is an inline comment.', | 553 ' "key2": 3 // This is an inline comment.', |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 mock_input_api.files = [ | 1333 mock_input_api.files = [ |
1297 MockAffectedFile('chrome/browser/resources/blah.js', 'arrow => OK here'), | 1334 MockAffectedFile('chrome/browser/resources/blah.js', 'arrow => OK here'), |
1298 ] | 1335 ] |
1299 warnings = PRESUBMIT._CheckForRiskyJsFeatures( | 1336 warnings = PRESUBMIT._CheckForRiskyJsFeatures( |
1300 mock_input_api, MockOutputApi()) | 1337 mock_input_api, MockOutputApi()) |
1301 self.assertEqual(0, len(warnings)) | 1338 self.assertEqual(0, len(warnings)) |
1302 | 1339 |
1303 | 1340 |
1304 if __name__ == '__main__': | 1341 if __name__ == '__main__': |
1305 unittest.main() | 1342 unittest.main() |
OLD | NEW |