Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: blimp/PRESUBMIT.py

Issue 2005023002: Blimp presubmit to check for unit tests on new .cc files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 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 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 """Top-level presubmit script for blimp. 5 """Top-level presubmit script for blimp.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools. 8 for more details about the presubmit API built into depot_tools.
9 """ 9 """
10 10
11 import re 11 import re
12 12
13 BLIMP_SOURCE_FILES=(r'^blimp[\\/].*\.(cc|h)$',) 13 BLIMP_SOURCE_FILES=(r'^blimp[\\/].*\.(cc|h)$',)
14 14
15 def CheckChangeLintsClean(input_api, output_api): 15 def CheckChangeLintsClean(input_api, output_api):
16 source_filter = lambda x: input_api.FilterSourceFile( 16 source_filter = lambda x: input_api.FilterSourceFile(
17 x, white_list=BLIMP_SOURCE_FILES, black_list=None) 17 x, white_list=BLIMP_SOURCE_FILES, black_list=None)
18 18
19 return input_api.canned_checks.CheckChangeLintsClean( 19 return input_api.canned_checks.CheckChangeLintsClean(
20 input_api, output_api, source_filter, lint_filters=[], verbose_level=1) 20 input_api, output_api, source_filter, lint_filters=[], verbose_level=1)
21 21
22 def CheckNewFilesHaveTests(input_api, output_api):
23 unittest_files = set()
Kevin M 2016/05/23 23:57:39 Does this check files that live outside of blimp/
Wez 2016/05/24 00:44:54 path/PRESUBMIT.py only gets called for files that
Brian Goldman 2016/06/01 22:56:57 I tested this. It only checks files under blimp.
24 files_needing_unittest = set()
Wez 2016/05/24 00:44:54 nit: How about new_unittest_files and new_source_f
Brian Goldman 2016/06/01 22:56:57 I'm going to leave the names as-is even though I d
25
Kevin M 2016/05/23 23:57:39 Also need something analogous for Java tests, whic
Wez 2016/05/24 00:44:54 Feels like a follow-up CL?
Brian Goldman 2016/06/01 22:56:57 Yes :)
26 for source_file in input_api.AffectedFiles():
27 if source_file.Action() == 'A':
28 name = source_file.LocalPath()
29 if re.search(r'_unittest\.cc$', name):
Kevin M 2016/05/23 23:57:39 Can we be consistent with search vs match?
Kevin M 2016/05/23 23:57:39 Should we also exclude anything with "test" in the
Wez 2016/05/24 00:44:54 And use re.compile() to compile the REs once each,
Wez 2016/05/24 00:44:54 This is only generating a warning, though, so it w
Brian Goldman 2016/06/01 22:56:57 I ended up getting rid of regex for this section e
Brian Goldman 2016/06/01 22:56:57 I'm going with the assumption that if it ends in "
Brian Goldman 2016/06/01 22:56:57 No more regexes in this section. I do use one for
30 unittest_files.add(name)
31 elif re.match(r'^blimp[\\/].*\.cc$', name):
32 files_needing_unittest.add(name)
33
34 missing = []
Wez 2016/05/24 00:44:54 nit: missing_unittest_files?
35
36 for name in files_needing_unittest:
37 unittest_name = re.sub(r'\.cc$', '_unittest.cc', name)
38 if unittest_name not in unittest_files:
39 missing.append(name)
40
41 if missing:
42 message = 'The following new files are missing unit tests:'
43 return [output_api.PresubmitPromptWarning(message, missing)]
44 else:
45 return []
46
22 def CheckChangeOnUpload(input_api, output_api): 47 def CheckChangeOnUpload(input_api, output_api):
23 results = [] 48 results = []
24 results += CheckChangeLintsClean(input_api, output_api) 49 results += CheckChangeLintsClean(input_api, output_api)
50 results += CheckNewFilesHaveTests(input_api, output_api)
25 return results 51 return results
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698