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

Fix the ALL_CAPS black list regexp.

Add some regexp unit test.

TEST=unit test
BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18139 0039d316-1c4b-4281-b951-d872f2087c98
parent 92022ec6
......@@ -17,6 +17,7 @@ import cStringIO # Exposed through the API.
import exceptions
import fnmatch
import glob
import logging
import marshal # Exposed through the API.
import optparse
import os # Somewhat exposed through the API.
......@@ -162,10 +163,10 @@ class InputApi(object):
r".*\bxcodebuild[\\\/].*",
r".*\bsconsbuild[\\\/].*",
# All caps files like README and LICENCE.
r".*\b[A-Z0-9_]+",
# SCM (can happen in dual SCM configuration)
r".*\b\.git[\\\/].*",
r".*\b\.svn[\\\/].*",
r".*\b[A-Z0-9_]+$",
# SCM (can happen in dual SCM configuration). (Slightly over aggressive)
r".*\.git[\\\/].*",
r".*\.svn[\\\/].*",
)
def __init__(self, change, presubmit_path, is_committing):
......@@ -294,7 +295,9 @@ class InputApi(object):
"""
def Find(affected_file, list):
for item in list:
if self.re.match(item, affected_file.LocalPath()):
local_path = affected_file.LocalPath()
if self.re.match(item, local_path):
logging.debug("%s matched %s" % (item, local_path))
return True
return False
return (Find(affected_file, white_list or self.DEFAULT_WHITE_LIST) and
......
......@@ -113,7 +113,8 @@ class PresubmitUnittest(PresubmitTestsBase):
'OutputApi', 'ParseFiles', 'PresubmitExecuter',
'ScanSubDirs', 'SvnAffectedFile',
'cPickle', 'cStringIO', 'exceptions',
'fnmatch', 'gcl', 'gclient', 'glob', 'marshal', 'normpath', 'optparse',
'fnmatch', 'gcl', 'gclient', 'glob', 'logging', 'marshal', 'normpath',
'optparse',
'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys',
'tempfile', 'traceback', 'types', 'unittest', 'urllib2', 'warnings',
]
......@@ -654,6 +655,77 @@ class InputApiUnittest(PresubmitTestsBase):
self.assertEqual(rhs_lines[2][0].LocalPath(), presubmit.normpath(another))
self.assertEqual(rhs_lines[3][0].LocalPath(), presubmit.normpath(another))
def testDefaultWhiteListBlackListFilters(self):
def f(x):
return presubmit.AffectedFile(x, 'M')
files = [
(
[
# To be tested.
f('a/experimental/b'),
f('experimental/b'),
f('a/experimental'),
f('a/experimental.cc'),
],
[
# Expected.
'a/experimental',
'a/experimental.cc',
],
),
(
[
# To be tested.
f('a/third_party/b'),
f('third_party/b'),
f('a/third_party'),
f('a/third_party.cc'),
],
[
# Expected.
'a/third_party',
'a/third_party.cc',
],
),
(
[
# To be tested.
f('a/LOL_FILE/b'),
f('b.c/LOL_FILE'),
f('a/PRESUBMIT.py'),
],
[
# Expected.
'a/LOL_FILE/b',
'a/PRESUBMIT.py',
],
),
(
[
# To be tested.
f('a/.git'),
f('b.c/.git'),
f('a/.git/bleh.py'),
f('.git/bleh.py'),
],
[
# Expected.
'b.c/.git',
],
),
]
input_api = presubmit.InputApi(None, './PRESUBMIT.py', False)
self.mox.ReplayAll()
self.assertEqual(len(input_api.DEFAULT_BLACK_LIST), 9)
for item in files:
results = filter(input_api.FilterSourceFile, item[0])
for i in range(len(results)):
self.assertEquals(results[i].LocalPath(),
presubmit.normpath(item[1][i]))
# Same number of expected results.
self.assertEquals(len(results), len(item[1]))
def testCustomFilter(self):
def FilterSourceFile(affected_file):
return 'a' in affected_file.LocalPath()
......
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