OLD | NEW |
| (Empty) |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 """Top-level presubmit script for blimp. | |
6 | |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | |
8 for more details about the presubmit API built into depot_tools. | |
9 """ | |
10 | |
11 import re | |
12 | |
13 BLIMP_SOURCE_FILES=(r'^blimp[\\/].*\.(cc|h)$',) | |
14 | |
15 def CheckChangeLintsClean(input_api, output_api): | |
16 source_filter = lambda x: input_api.FilterSourceFile( | |
17 x, white_list=BLIMP_SOURCE_FILES, black_list=None) | |
18 | |
19 return input_api.canned_checks.CheckChangeLintsClean( | |
20 input_api, output_api, source_filter, lint_filters=[], verbose_level=1) | |
21 | |
22 def _NeedsTest(name): | |
23 is_cc = name.endswith('.cc') | |
24 is_test = name.endswith('test.cc') | |
25 is_test_support = name.startswith('blimp/test/support/') | |
26 return is_cc and not is_test and not is_test_support | |
27 | |
28 def CheckNewFilesHaveTests(input_api, output_api): | |
29 unittest_files = set() | |
30 files_needing_unittest = set() | |
31 | |
32 for source_file in input_api.AffectedFiles(): | |
33 if source_file.Action() == 'A': | |
34 name = source_file.LocalPath() | |
35 if name.endswith('_unittest.cc'): | |
36 unittest_files.add(name) | |
37 elif _NeedsTest(name): | |
38 files_needing_unittest.add(name) | |
39 | |
40 missing_unittest_files = [] | |
41 | |
42 for name in files_needing_unittest: | |
43 unittest_name = re.sub(r'\.cc$', '_unittest.cc', name) | |
44 if unittest_name not in unittest_files: | |
45 missing_unittest_files.append(name) | |
46 | |
47 if missing_unittest_files: | |
48 message = 'The following new files are missing unit tests:' | |
49 return [output_api.PresubmitPromptWarning(message, missing_unittest_files)] | |
50 else: | |
51 return [] | |
52 | |
53 def CheckChangeOnUpload(input_api, output_api): | |
54 results = [] | |
55 results += CheckChangeLintsClean(input_api, output_api) | |
56 results += CheckNewFilesHaveTests(input_api, output_api) | |
57 return results | |
OLD | NEW |