OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
6 | 6 |
7 | 7 |
8 ### Description checks | 8 ### Description checks |
9 | 9 |
10 def CheckChangeHasTestField(input_api, output_api): | 10 def CheckChangeHasTestField(input_api, output_api): |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 It's mainly a wrapper for RunUnitTests. USe whitelist and blacklist to filter | 470 It's mainly a wrapper for RunUnitTests. USe whitelist and blacklist to filter |
471 tests accordingly. | 471 tests accordingly. |
472 """ | 472 """ |
473 unit_tests = [] | 473 unit_tests = [] |
474 test_path = input_api.os_path.abspath( | 474 test_path = input_api.os_path.abspath( |
475 input_api.os_path.join(input_api.PresubmitLocalPath(), directory)) | 475 input_api.os_path.join(input_api.PresubmitLocalPath(), directory)) |
476 | 476 |
477 def check(filename, filters): | 477 def check(filename, filters): |
478 return any(True for i in filters if input_api.re.match(i, filename)) | 478 return any(True for i in filters if input_api.re.match(i, filename)) |
479 | 479 |
| 480 to_run = found = 0 |
480 for filename in input_api.os_listdir(test_path): | 481 for filename in input_api.os_listdir(test_path): |
| 482 found += 1 |
481 fullpath = input_api.os_path.join(test_path, filename) | 483 fullpath = input_api.os_path.join(test_path, filename) |
482 if not input_api.os_path.isfile(fullpath): | 484 if not input_api.os_path.isfile(fullpath): |
483 continue | 485 continue |
484 if whitelist and not check(filename, whitelist): | 486 if whitelist and not check(filename, whitelist): |
485 continue | 487 continue |
486 if blacklist and check(filename, blacklist): | 488 if blacklist and check(filename, blacklist): |
487 continue | 489 continue |
488 unit_tests.append(input_api.os_path.join(directory, filename)) | 490 unit_tests.append(input_api.os_path.join(directory, filename)) |
| 491 to_run += 1 |
| 492 input_api.logging.debug('Found %d files, running %d' % (found, to_run)) |
| 493 if not to_run: |
| 494 return [ |
| 495 output_api.PresubmitPromptWarning( |
| 496 'Out of %d files, found none that matched w=%r, b=%r in directory %s' |
| 497 % (found, whitelist, blacklist, directory)) |
| 498 ] |
489 return RunUnitTests(input_api, output_api, unit_tests) | 499 return RunUnitTests(input_api, output_api, unit_tests) |
490 | 500 |
491 | 501 |
492 def RunUnitTests(input_api, output_api, unit_tests): | 502 def RunUnitTests(input_api, output_api, unit_tests): |
493 """Runs all unit tests in a directory. | 503 """Runs all unit tests in a directory. |
494 | 504 |
495 On Windows, sys.executable is used for unit tests ending with ".py". | 505 On Windows, sys.executable is used for unit tests ending with ".py". |
496 """ | 506 """ |
497 # We don't want to hinder users from uploading incomplete patches. | 507 # We don't want to hinder users from uploading incomplete patches. |
498 if input_api.is_committing: | 508 if input_api.is_committing: |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 952 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
943 input_api, output_api)) | 953 input_api, output_api)) |
944 snapshot("checking license") | 954 snapshot("checking license") |
945 results.extend(input_api.canned_checks.CheckLicense( | 955 results.extend(input_api.canned_checks.CheckLicense( |
946 input_api, output_api, license_header, source_file_filter=sources)) | 956 input_api, output_api, license_header, source_file_filter=sources)) |
947 snapshot("checking was uploaded") | 957 snapshot("checking was uploaded") |
948 results.extend(input_api.canned_checks.CheckChangeWasUploaded( | 958 results.extend(input_api.canned_checks.CheckChangeWasUploaded( |
949 input_api, output_api)) | 959 input_api, output_api)) |
950 snapshot("done") | 960 snapshot("done") |
951 return results | 961 return results |
OLD | NEW |