-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests
executable file
·80 lines (65 loc) · 2.35 KB
/
run_tests
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
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
from pathlib import Path
import subprocess
import sys
import textwrap
try:
import rich
def print_result(*args):
text = " ".join(str(arg) for arg in args)
text = text.replace("PASS", "[green]PASS[/green]")
text = text.replace("FAIL", "[red]FAIL[/red]")
text = text.replace("ERROR", "[red]ERROR[/red]")
rich.print(text)
except ImportError:
print_result = print
# I promise that I can write cleaner Python than this :)
# I just need something in place for CI
input_test_names = [Path(path).resolve() for path in sys.argv[1:]]
windows_exe = Path(__file__).parent.joinpath("zig-out/bin/shimlang.exe")
linux_exe = Path(__file__).parent.joinpath("zig-out/bin/shimlang")
if windows_exe.exists():
interpreter = windows_exe.as_posix()
else:
print(linux_exe.parent.iterdir())
interpreter = linux_exe.as_posix()
test_dir = Path(__file__).parent / "tests"
check_script_output = sorted(test_dir.glob("check_output/**/*.shm"))
if input_test_names:
check_script_output = [
path for path in check_script_output if path.resolve() in input_test_names
]
if not check_script_output:
sys.exit("No 'check_script_output' scripts found")
failed = False
for script in check_script_output:
expected_output_file = script.with_suffix(".out")
if not expected_output_file.exists():
failed = True
print_result("FAIL -", script, "(no output file)")
continue
expected = expected_output_file.read_text()
result = subprocess.run(
[interpreter, script.as_posix()],
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if result.returncode:
failed = True
print_result("ERROR -", script, f"(non-zero exit code {result.returncode})")
# Only give more detail when a test is explicitly asked for
if input_test_names:
print(" Got:")
print(textwrap.indent(result.stdout, " "))
elif result.stdout == expected:
print_result("PASS -", script)
else:
failed = True
print_result("FAIL -", script, "(output does not match expected)")
print(" Expected:")
print(textwrap.indent(repr(expected), " "))
print(" Got:")
print(textwrap.indent(repr(result.stdout), " "))
if failed:
sys.exit(1)