aboutsummaryrefslogtreecommitdiff
path: root/run_tests_for.py
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-06-20 08:56:58 -0700
committerTobias Bosch <tbosch@google.com>2019-06-20 23:08:36 +0000
commit7f186707b1989eb35c8c42503077edb8d62247a7 (patch)
treeceaec61902f6c3f4411feb9c5a9060d01d8d5e1b /run_tests_for.py
parentef8f969c8ea2498c2a8aa701cb2e83833339f9a8 (diff)
downloadtoolchain-utils-7f186707b1989eb35c8c42503077edb8d62247a7.tar.gz
Call go fmt, go lint, go test and go vet
(via go test) during presubmit and git hooks. Will only warn when the go commands are not available as go is not part of depot_tools. BUG=chromium:976903 TEST=Tried with and without go/gofmt/golint in the path. TEST=Tried on go and non go files. TEST=Tried on go files with and without errors. Change-Id: I8a6aa4227f0d8649f7c390ab59f187f14955293c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1669745 Reviewed-by: George Burgess <gbiv@chromium.org> Commit-Queue: Tobias Bosch <tbosch@google.com> Tested-by: Tobias Bosch <tbosch@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Diffstat (limited to 'run_tests_for.py')
-rwxr-xr-xrun_tests_for.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/run_tests_for.py b/run_tests_for.py
index 0130deaa..444020ce 100755
--- a/run_tests_for.py
+++ b/run_tests_for.py
@@ -165,7 +165,7 @@ def _fix_python_path(toolchain_utils):
os.environ['PYTHONPATH'] = toolchain_utils + pypath
-def _find_forced_subdir_tests(test_paths, toolchain_utils):
+def _find_forced_subdir_python_tests(test_paths, toolchain_utils):
assert all(os.path.isabs(path) for path in test_paths)
# Directories under toolchain_utils for which any change will cause all tests
@@ -193,6 +193,19 @@ def _find_forced_subdir_tests(test_paths, toolchain_utils):
return results
+def _find_go_tests(test_paths):
+ """Returns TestSpecs for the go folders of the given files"""
+ assert all(os.path.isabs(path) for path in test_paths)
+
+ dirs_with_gofiles = set(
+ os.path.dirname(p) for p in test_paths if p.endswith(".go"))
+ command = ["go", "test", "-vet=all"]
+ # Note: We sort the directories to be deterministic.
+ return [
+ TestSpec(directory=d, command=command) for d in sorted(dirs_with_gofiles)
+ ]
+
+
def main(argv):
default_toolchain_utils = os.path.abspath(os.path.dirname(__file__))
@@ -219,9 +232,11 @@ def main(argv):
_fix_python_path(toolchain_utils)
- tests_to_run = _find_forced_subdir_tests(modified_files, toolchain_utils)
+ tests_to_run = _find_forced_subdir_python_tests(modified_files,
+ toolchain_utils)
for f in modified_files:
tests_to_run += _autodetect_python_tests_for(f)
+ tests_to_run += _find_go_tests(modified_files)
# TestSpecs have lists, so we can't use a set. We'd likely want to keep them
# sorted for determinism anyway.