Index: run_unittests |
diff --git a/run_unittests b/run_unittests |
index 0c5d87a27eae886212a058f6e3680380919ec6f3..2412c3fd56efc911964b1667244ae9f23ebbc274 100755 |
--- a/run_unittests |
+++ b/run_unittests |
@@ -14,8 +14,9 @@ import unittest |
BUILDBOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
-GO_TESTS = [ |
+GO_DIRS = [ |
'.', |
+ 'ct', |
tfarina
2014/12/05 16:25:12
maybe we should start sorting this alphabetical? C
borenet
2014/12/05 18:14:06
Alphabetized. Now that goimports and "go vet" wor
|
'perf', |
'monitoring', |
'golden', |
@@ -24,6 +25,7 @@ GO_TESTS = [ |
GO_TEST_FAILED = ( |
'''====================================================================== |
Go test failed: %s |
+CWD: %s |
---------------------------------------------------------------------- |
%s |
---------------------------------------------------------------------- |
@@ -53,30 +55,43 @@ 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 GoImports(): |
+ |
+def GoVet(): |
+ return RunGoTest(['go', 'vet', './...'], '.') |
+ |
+ |
+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 +106,12 @@ if __name__ == '__main__': |
continue |
tests_to_run.extend(test_modules) |
- builtin_tests = [GoImports] |
+ go_tests = [GoVet] |
+ go_tests_cwd = [GoTests, |
+ GoImports] |
- num_tests = len(tests_to_run) + len(GO_TESTS) + len(builtin_tests) |
+ num_tests = (len(tests_to_run) + len(go_tests) + |
+ len(GO_DIRS) * len(go_tests_cwd)) |
print 'Found %d tests.' % num_tests |
errors = [] |
for test in tests_to_run: |
@@ -102,20 +120,15 @@ 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_cwd: |
+ errors.extend(test(go_dir)) |
+ for go_test in go_tests: |
+ errors.extend(go_test()) |
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.' |