forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] Add a PRESUBMIT check for TODO.
All TODOs in src/ios/ should follow the format TODO(crbug.com/######) so add a PRESUBMIT.py check (and corresponding unit tests) for that. BUG=677203 Change-Id: I360ad75c786f292d3a8ada8df519cb451c1c2828 Reviewed-on: https://chromium-review.googlesource.com/538613 Commit-Queue: Sylvain Defresne <sdefresne@chromium.org> Reviewed-by: Eugene But <eugenebut@chromium.org> Cr-Commit-Position: refs/heads/master@{#482589}
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2017 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
"""Presubmit script for ios. | ||
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | ||
for more details about the presubmit API built into depot_tools. | ||
""" | ||
|
||
TODO_PATTERN = r'TO[D]O\(([^\)]*)\)' | ||
CRBUG_PATTERN = r'crbug\.com/\d+$' | ||
|
||
def _CheckBugInToDo(input_api, output_api): | ||
""" Checks whether TODOs in ios code are identified by a bug number.""" | ||
todo_regex = input_api.re.compile(TODO_PATTERN) | ||
crbug_regex = input_api.re.compile(CRBUG_PATTERN) | ||
|
||
errors = [] | ||
for f in input_api.AffectedFiles(): | ||
for line_num, line in f.ChangedContents(): | ||
todo_match = todo_regex.search(line) | ||
if not todo_match: | ||
continue | ||
crbug_match = crbug_regex.match(todo_match.group(1)) | ||
if not crbug_match: | ||
errors.append('%s:%s' % (f.LocalPath(), line_num)) | ||
if not errors: | ||
return [] | ||
|
||
plural_suffix = '' if len(errors) == 1 else 's' | ||
error_message = '\n'.join([ | ||
'Found TO''DO%(plural)s without bug number%(plural)s (expected format is ' | ||
'\"TO''DO(crbug.com/######)\":' % {'plural': plural_suffix} | ||
] + errors) + '\n' | ||
|
||
return [output_api.PresubmitError(error_message)] | ||
|
||
|
||
def CheckChangeOnUpload(input_api, output_api): | ||
results = [] | ||
results.extend(_CheckBugInToDo(input_api, output_api)) | ||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2017 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import os | ||
import sys | ||
import unittest | ||
|
||
import PRESUBMIT | ||
|
||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
import PRESUBMIT_test_mocks | ||
|
||
|
||
class CheckTODOFormatTest(unittest.TestCase): | ||
"""Test the _CheckBugInToDo presubmit check.""" | ||
|
||
def testTODOs(self): | ||
bad_lines = ['TO''DO(ldap): fix this', | ||
'TO''DO(ladp): see crbug.com/8675309', | ||
'TO''DO(8675309): fix this', | ||
'TO''DO(http://crbug.com/8675309): fix this', | ||
'TO''DO( crbug.com/8675309): fix this', | ||
'TO''DO(crbug/8675309): fix this', | ||
'TO''DO(crbug.com): fix this'] | ||
good_lines = ['TO''DO(crbug.com/8675309): fix this', | ||
'TO''DO(crbug.com/8675309): fix this (please)'] | ||
mock_input = PRESUBMIT_test_mocks.MockInputApi() | ||
mock_input.files = [PRESUBMIT_test_mocks.MockFile( | ||
'ios/path/foo_controller.mm', bad_lines + good_lines)] | ||
mock_output = PRESUBMIT_test_mocks.MockOutputApi() | ||
errors = PRESUBMIT._CheckBugInToDo(mock_input, mock_output) | ||
self.assertEqual(len(errors), 1) | ||
self.assertEqual('error', errors[0].type) | ||
self.assertTrue('without bug numbers' in errors[0].message) | ||
error_lines = errors[0].message.split('\n') | ||
self.assertEqual(len(error_lines), len(bad_lines) + 2) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |