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