Commit 115ae6ca authored by maruel@chromium.org's avatar maruel@chromium.org

Makefiles will always contain tabs so make the notab check filter them out.

Review URL: http://codereview.chromium.org/2814017

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@50251 0039d316-1c4b-4281-b951-d872f2087c98
parent ba0fce74
...@@ -213,8 +213,16 @@ def CheckChangeHasNoTabs(input_api, output_api, source_file_filter=None): ...@@ -213,8 +213,16 @@ def CheckChangeHasNoTabs(input_api, output_api, source_file_filter=None):
"""Checks that there are no tab characters in any of the text files to be """Checks that there are no tab characters in any of the text files to be
submitted. submitted.
""" """
# In addition to the filter, make sure that makefiles are blacklisted.
if not source_file_filter:
# It's the default filter.
source_file_filter = input_api.FilterSourceFile
def filter_more(affected_file):
return (not input_api.os_path.basename(affected_file.LocalPath()) in
('Makefile', 'makefile') and
source_file_filter(affected_file))
tabs = [] tabs = []
for f, line_num, line in input_api.RightHandSideLines(source_file_filter): for f, line_num, line in input_api.RightHandSideLines(filter_more):
if '\t' in line: if '\t' in line:
tabs.append('%s, line %s' % (f.LocalPath(), line_num)) tabs.append('%s, line %s' % (f.LocalPath(), line_num))
if tabs: if tabs:
......
...@@ -1161,6 +1161,7 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -1161,6 +1161,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
input_api1 = self.MockInputApi(change1, False) input_api1 = self.MockInputApi(change1, False)
affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file.LocalPath().AndReturn('foo.cc') affected_file.LocalPath().AndReturn('foo.cc')
# Format is (file, line number, line content)
output1 = [ output1 = [
(affected_file, 42, 'yo, ' + content1), (affected_file, 42, 'yo, ' + content1),
(affected_file, 43, 'yer'), (affected_file, 43, 'yer'),
...@@ -1327,6 +1328,44 @@ class CannedChecksUnittest(PresubmitTestsBase): ...@@ -1327,6 +1328,44 @@ class CannedChecksUnittest(PresubmitTestsBase):
'blah blah', 'blah\tblah', 'blah blah', 'blah\tblah',
presubmit.OutputApi.PresubmitPromptWarning) presubmit.OutputApi.PresubmitPromptWarning)
# Make sure makefiles are ignored.
change1 = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None,
0, 0)
input_api1 = self.MockInputApi(change1, False)
affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file1.LocalPath().AndReturn('foo.cc')
affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file2.LocalPath().AndReturn('foo/Makefile')
affected_file3 = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file3.LocalPath().AndReturn('makefile')
# Only this one will trigger.
affected_file4 = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file4.LocalPath().AndReturn('makefile.foo')
affected_file4.LocalPath().AndReturn('makefile.foo')
output1 = [
(affected_file1, 42, 'yo, '),
(affected_file2, 43, 'yer\t'),
(affected_file3, 45, 'yr\t'),
(affected_file4, 46, 'ye\t'),
]
def test(source_filter):
for i in output1:
if source_filter(i[0]):
yield i
# Override the mock of these functions.
input_api1.FilterSourceFile = lambda x: x
input_api1.RightHandSideLines = test
self.mox.ReplayAll()
results1 = presubmit_canned_checks.CheckChangeHasNoTabs(input_api1,
presubmit.OutputApi, None)
self.assertEquals(len(results1), 1)
self.assertEquals(results1[0].__class__,
presubmit.OutputApi.PresubmitPromptWarning)
self.assertEquals(results1[0]._long_text,
'makefile.foo, line 46')
def testCannedCheckLongLines(self): def testCannedCheckLongLines(self):
check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z)
self.ContentTest(check, '', 'blah blah blah', self.ContentTest(check, '', 'blah blah blah',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment