-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrun-tests.py
executable file
·71 lines (51 loc) · 1.52 KB
/
run-tests.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/python3
import os
import os.path
from sys import exit, argv
from subprocess import call, DEVNULL
DIR = "tests"
num_tests = 0
success = 0
failure = 0
def run_test(path, filename):
global num_tests
global success
global failure
print("### Running " + path)
# Prepare doc
latex_res = call(["xelatex", "-interaction", "errorstopmode", filename], cwd=DIR, stdout=DEVNULL)
if latex_res != 0:
print("WARNING: xelatex failed")
# Run test
res = call(["crosstex" , "-v", filename], cwd=DIR)
# Compile final doc
latex_res = latex_res and call(["xelatex", "-interaction", "errorstopmode", filename], cwd=DIR, stdout=DEVNULL)
num_tests += 1
if res == 0 and latex_res == 0:
success += 1
else:
failure += 1
# Cleanup
call(["rm", "-f", "*.cache", filename + ".log", filename + ".aux"], cwd=DIR)
def run_all_tests():
for filename in os.listdir(DIR):
if not filename.endswith(".tex"):
continue
filename = filename.replace(".tex", "")
path = DIR + "/" + filename
run_test(path, filename)
if len(argv) < 2 or argv[1] == "all":
run_all_tests()
else:
name = argv[1]
if not os.path.isfile(DIR + "/" + name + ".tex"):
print("No such test " + name)
else:
run_test(DIR + "/" + name, name)
print("")
print(str(success) + "/" + str(num_tests) + " tests successful")
print(str(failure) + "/" + str(num_tests) + " tests failed")
if failure == 0:
exit(0)
else:
exit(-1)