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

Unified Diff: presubmit_canned_checks.py

Issue 281013002: Recursively find all tests in a repo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index bd3c361f2742f1145df08607e22f754f7b61b705..646491e188666e6d5cf089a436308340097c5c59 100644
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -562,6 +562,49 @@ def GetUnitTests(input_api, output_api, unit_tests, env=None):
return results
+def GetGitUnitTestsRecursively(input_api, output_api, directory,
+ whitelist, blacklist):
+ """Gets all files in the directory tree (git repo) that match the whitelist.
+
+ Restricts itself to only find files within the Change's source repo, not
+ dependencies.
+ """
+ def curry_check(whitelist, blacklist):
M-A Ruel 2014/05/14 00:20:57 This is not necessary, the values are bound anyhow
agable 2014/05/14 22:43:20 But but but I have to pay honor to Haskell Curry!
+ def check(filename):
+ return (any(input_api.re.match(f, filename) for f in whitelist) and
+ not any(input_api.re.match(f, filename) for f in blacklist))
+ return check
+ check = curry_check(whitelist, blacklist)
+
+ tests = []
+
+ repo_root = input_api.change.RepositoryRoot()
+ toplevel = input_api.os_path.abspath(
+ input_api.os_path.join(input_api.PresubmitLocalPath(), directory))
+ to_run = found = 0
+ for root, dirs, files in input_api.os_walk(toplevel):
+ git_toplevel = input_api.subprocess.check_output(
+ ['git', 'rev-parse', '--show-toplevel'], cwd=root).strip()
M-A Ruel 2014/05/14 00:20:57 That's not how I thought about doing it, my take w
agable 2014/05/14 22:43:20 PTAL. I added one for SVN too.
+ if git_toplevel != repo_root:
+ del dirs[:]
+ continue
+ for name in files:
+ found += 1
+ fullname = input_api.os_path.join(root, name)
+ if check(fullname):
+ to_run += 1
+ tests.append(fullname)
+ input_api.logging.debug('Found %d files, running %d' % (found, to_run))
+ if not to_run:
+ return [
+ output_api.PresubmitPromptWarning(
+ 'Out of %d files, found none that matched w=%r, b=%r in directory %s'
+ % (found, whitelist, blacklist, directory))
+ ]
+
+ return GetUnitTests(input_api, output_api, tests)
+
+
def GetPythonUnitTests(input_api, output_api, unit_tests):
"""Run the unit tests out of process, capture the output and use the result
code to determine success.
@@ -744,7 +787,7 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None,
if True:
return [GetPylintCmd(files)]
else:
- return map(GetPylintCmd, files)
+ return map(lambda x: GetPylintCmd([x]), files)
def RunPylint(input_api, *args, **kwargs):
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698