Commit 71626858 authored by maruel@chromium.org's avatar maruel@chromium.org

Make CheckLicense() to not trigger on empty files.

This is especially annoying on empty __init__.py files.

TEST=new unit test
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@64904 0039d316-1c4b-4281-b951-d872f2087c98
parent 488d0431
......@@ -275,13 +275,16 @@ def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None):
return []
def CheckLicense(input_api, output_api, license, source_file_filter=None):
def CheckLicense(input_api, output_api, license, source_file_filter=None,
accept_empty_files=True):
"""Verifies the license header.
"""
license_re = input_api.re.compile(license, input_api.re.MULTILINE)
bad_files = []
for f in input_api.AffectedSourceFiles(source_file_filter):
contents = input_api.ReadFile(f, 'rb')
if accept_empty_files and not contents:
continue
if not license_re.search(contents):
bad_files.append(f.LocalPath())
if bad_files:
......
......@@ -1386,7 +1386,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
'svn:eol-style', 'LF', '', False,
presubmit.OutputApi.PresubmitNotifyResult, True)
def _LicenseCheck(self, text, license, committing, expected_result):
def _LicenseCheck(self, text, license, committing, expected_result, **kwargs):
change = self.mox.CreateMock(presubmit.SvnChange)
change.scm = 'svn'
input_api = self.MockInputApi(change, committing)
......@@ -1398,7 +1398,8 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.mox.ReplayAll()
result = presubmit_canned_checks.CheckLicense(
input_api, presubmit.OutputApi, license, 42)
input_api, presubmit.OutputApi, license, source_file_filter=42,
**kwargs)
if expected_result:
self.assertEqual(len(result), 1)
self.assertEqual(result[0].__class__, expected_result)
......@@ -1446,6 +1447,14 @@ class CannedChecksUnittest(PresubmitTestsBase):
self._LicenseCheck(text, license, False,
presubmit.OutputApi.PresubmitNotifyResult)
def testCheckLicenseEmptySuccess(self):
text = ''
license = (
r".*? Copyright \(c\) 2037 Nobody." "\n"
r".*? All Rights Reserved\." "\n"
)
self._LicenseCheck(text, license, True, None, accept_empty_files=True)
def testCannedCheckSvnAccidentalSubmission(self):
modified_dir_file = 'foo/'
accidental_submssion_file = 'foo/bar.cc'
......
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