forked from xi-editor/xi-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.local
executable file
·59 lines (46 loc) · 1.59 KB
/
ci.local
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
import glob
import os
import signal
import subprocess
import sys
import tempfile
from multiprocessing import cpu_count, Pool
SCRIPT_DIR = os.path.dirname(__file__)
MANIFESTS = [os.path.join(SCRIPT_DIR, "rust", "Cargo.toml")] + glob.glob(os.path.join(SCRIPT_DIR, "rust", "*", "Cargo.toml"))
def run_test(manifest):
print >> sys.stderr, "Starting test {}".format(manifest)
with tempfile.TemporaryFile("rw+b", prefix="xi-test", suffix=".log") as log:
result = subprocess.call(
["cargo", "test", "--manifest-path", manifest], stdout=log,
stderr=subprocess.STDOUT)
test_output = None
if result != 0:
log.seek(0)
test_output = log.read()
return (manifest, result, test_output)
def run_tests(test_pool, manifests):
results = test_pool.imap_unordered(run_test, MANIFESTS, chunksize=1)
for manifest, result, test_output in results:
relative_manifest = os.path.relpath(manifest, SCRIPT_DIR)
if result == 0:
print >> sys.stderr, "Test for {} passed".format(relative_manifest)
else:
print >> sys.stderr, "Test for {} failed with exit code {}".format(
manifest, result)
if test_output:
print >> sys.stderr, test_output
if __name__ == "__main__":
original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
test_pool = Pool(cpu_count())
signal.signal(signal.SIGINT, original_sigint_handler)
try:
run_tests(test_pool, MANIFESTS)
except KeyboardInterrupt:
print >> sys.stderr, "Terminating tests"
test_pool.terminate()
raise
else:
test_pool.close()
finally:
test_pool.join()