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

Unified Diff: run_unittests

Issue 777413002: Add new tests to presubmit, fix errors (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: "go vet" Created 6 years 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
« go/gitinfo/gitinfo.go ('K') | « perf/go/vec/vec_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: run_unittests
diff --git a/run_unittests b/run_unittests
index 0c5d87a27eae886212a058f6e3680380919ec6f3..eba9111ce1938fb0237aa775ba761041050b0718 100755
--- a/run_unittests
+++ b/run_unittests
@@ -14,7 +14,7 @@ import unittest
BUILDBOT_PATH = os.path.dirname(os.path.abspath(__file__))
-GO_TESTS = [
+GO_DIRS = [
'.',
'perf',
'monitoring',
@@ -24,6 +24,7 @@ GO_TESTS = [
GO_TEST_FAILED = (
'''======================================================================
Go test failed: %s
+CWD: %s
----------------------------------------------------------------------
%s
----------------------------------------------------------------------
@@ -53,30 +54,59 @@ def FilterDirectory(dirpath, filenames):
return True
-def TestGo(testname):
- # TODO(borenet): Switch to 'make test' once we're sure the karma-based tests
- # will run in headless mode.
- p = subprocess.Popen(['make', 'testgo'], cwd=testname,
+def RunGoTest(cmd, cwd):
+ p = subprocess.Popen(cmd, cwd=cwd,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE)
output = p.communicate()[0]
if p.returncode != 0:
- return GO_TEST_FAILED % (testname, output)
- return None
+ return [GO_TEST_FAILED % (' '.join(cmd), cwd, output)]
+ return []
+
+def GoTests(cwd):
+ # TODO(borenet): Switch to 'make test' once we're sure the karma-based tests
+ # will run in headless mode.
+ return RunGoTest(['make', 'testgo'], cwd)
+
+
+def GoVet(cwd):
+ # We need to actually point to go packages. Find any directories in cwd
+ # which contain .go files and run "go vet" on them.
jcgregorio 2014/12/05 15:57:33 Doesn't this work? $ go vet ./...
borenet 2014/12/05 16:07:00 It sure does!
+ modules = []
+ go_path = os.path.join(cwd, 'go')
+ for item in os.listdir(go_path):
+ item_path = os.path.join(go_path, item)
+ if os.path.isdir(item_path):
+ for f in os.listdir(item_path):
+ file_path = os.path.join(item_path, f)
+ if os.path.isfile(file_path) and f.endswith('.go'):
+ modules.append(item_path)
+ break
-def GoImports():
+ errors = []
+ for m in modules:
+ errors.extend(RunGoTest(['go', 'vet'], m))
+ return errors
+
+
+def GoImports(cwd):
+ cmd = ['goimports', '-l', 'go']
try:
- diff_files = subprocess.check_output(['goimports', '-l', '.'],
+ diff_files = subprocess.check_output(cmd, cwd=cwd,
stderr=subprocess.PIPE).splitlines()
except subprocess.CalledProcessError:
- return ('goimports failed to run! Is it installed? You may need to run: \n'
- 'go get http://code.google.com/p/go.tools/cmd/goimports')
+ return [GO_TEST_FAILED % (
+ ' '.join(cmd), cwd,
+ ('goimports failed to run! Is it installed? You may need to run:\n'
+ 'go get http://code.google.com/p/go.tools/cmd/goimports'))]
if len(diff_files) > 0:
- return ('goimports found diffs in the following files: %s' %
- ', '.join(diff_files))
- return None
+ return [GO_TEST_FAILED % (
+ ' '.join(cmd), cwd,
+ ('goimports found diffs in the following files: %s' %
+ ', '.join(diff_files)))]
+ return []
if __name__ == '__main__':
@@ -91,9 +121,11 @@ if __name__ == '__main__':
continue
tests_to_run.extend(test_modules)
- builtin_tests = [GoImports]
+ go_tests = [GoTests,
+ GoImports,
+ GoVet]
- num_tests = len(tests_to_run) + len(GO_TESTS) + len(builtin_tests)
+ num_tests = len(tests_to_run) + len(GO_DIRS) * len(go_tests)
print 'Found %d tests.' % num_tests
errors = []
for test in tests_to_run:
@@ -102,20 +134,13 @@ if __name__ == '__main__':
if proc.wait() != 0:
errors.append(proc.communicate()[0])
- for go_test in GO_TESTS:
- error = TestGo(go_test)
- if error:
- errors.append(error)
-
- for builtin_test in builtin_tests:
- error = builtin_test()
- if error:
- errors.append(error)
+ for go_dir in GO_DIRS:
+ for test in go_tests:
+ errors.extend(test(go_dir))
if errors:
for error in errors:
print error
- print 'Failed %d of %d.' % (len(errors), num_tests)
sys.exit(1)
else:
print 'All tests succeeded.'
« go/gitinfo/gitinfo.go ('K') | « perf/go/vec/vec_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698