|
1 |
| -#!/usr/bin/env python3.4 |
| 1 | +#!/usr/bin/env python3 |
2 | 2 |
|
3 | 3 | # Copyright 2018 The go-python Authors. All rights reserved.
|
4 | 4 | # Use of this source code is governed by a BSD-style
|
|
15 | 15 | import os
|
16 | 16 | import sys
|
17 | 17 | from subprocess import Popen, PIPE, STDOUT
|
| 18 | +from collections import defaultdict |
18 | 19 |
|
19 |
| -testwith = ("python3.4", "gpython") |
| 20 | +py_version = "python3.4" |
20 | 21 |
|
21 |
| -def runtests(dirpath, filenames): |
22 |
| - """Run the tests found""" |
| 22 | +opt_install = "/opt/"+py_version |
| 23 | + |
| 24 | +bin_dirs = os.environ["PATH"].split(os.pathsep) + [ |
| 25 | + opt_install+"/bin", |
| 26 | + os.path.join(os.environ["HOME"], "bin/"+py_version+"/bin"), |
| 27 | +] |
| 28 | + |
| 29 | +def find_python(): |
| 30 | + """Find a version of python to run""" |
| 31 | + for bin_dir in bin_dirs: |
| 32 | + path = os.path.join(bin_dir, py_version) |
| 33 | + if os.path.exists(path): |
| 34 | + return path |
| 35 | + print("Couldn't find "+py_version+" on $PATH or "+" or ".join(bin_dirs[-2:])) |
| 36 | + print("Install "+py_version+" by doing:") |
| 37 | + print(" sudo mkdir -p "+opt_install) |
| 38 | + print(" sudo chown $USER "+opt_install) |
| 39 | + print(" ./bin/install-python.sh "+opt_install+'"') |
| 40 | + sys.exit(1) |
| 41 | + |
| 42 | +testwith = [find_python(), "gpython"] |
| 43 | + |
| 44 | +def runtests(dirpath, filenames, failures): |
| 45 | + """Run the tests found accumulating failures""" |
23 | 46 | print("Running tests in %s" % dirpath)
|
24 | 47 | for name in filenames:
|
25 | 48 | if not name.endswith(".py") or name.startswith("lib") or name.startswith("raise"):
|
26 | 49 | continue
|
27 |
| - print("Testing %s" % name) |
| 50 | + #print(" - %s" % name) |
28 | 51 | fullpath = os.path.join(dirpath, name)
|
29 | 52 | for cmd in testwith:
|
30 | 53 | prog = [cmd, fullpath]
|
31 | 54 | p = Popen(prog, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
32 | 55 | stdout, stderr = p.communicate("")
|
33 | 56 | rc = p.returncode
|
34 | 57 | if rc != 0:
|
35 |
| - print("*** %s %s Fail ***" % (cmd, fullpath)) |
36 |
| - print("="*60) |
37 |
| - sys.stdout.write(stdout.decode("utf-8")) |
38 |
| - print("="*60) |
39 |
| - |
| 58 | + failures[cmd][fullpath].append(stdout.decode("utf-8")) |
| 59 | + return failures |
| 60 | + |
40 | 61 | def main():
|
41 | 62 | binary = os.path.abspath(__file__)
|
42 | 63 | home = os.path.dirname(binary)
|
43 | 64 | os.chdir(home)
|
44 | 65 | print("Scanning %s for tests" % home)
|
45 | 66 |
|
| 67 | + failures = defaultdict(lambda: defaultdict(list)) |
46 | 68 | for dirpath, dirnames, filenames in os.walk("."):
|
47 | 69 | if os.path.basename(dirpath) == "tests":
|
48 |
| - runtests(dirpath, filenames) |
| 70 | + runtests(dirpath, filenames, failures) |
| 71 | + |
| 72 | + if not failures: |
| 73 | + print("All OK") |
| 74 | + return |
| 75 | + |
| 76 | + print() |
| 77 | + |
| 78 | + sep = "="*60+"\n" |
| 79 | + sep2 = "-"*60+"\n" |
| 80 | + |
| 81 | + for cmd in sorted(failures.keys()): |
| 82 | + for path in sorted(failures[cmd].keys()): |
| 83 | + print(sep+"Failures for "+cmd+" in "+path) |
| 84 | + sys.stdout.write(sep+sep2.join(failures[cmd][path])+sep) |
| 85 | + print() |
| 86 | + sys.exit(1) |
| 87 | + |
49 | 88 |
|
50 | 89 | if __name__ == "__main__":
|
51 | 90 | main()
|
0 commit comments