-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgolden_test.py
More file actions
42 lines (31 loc) · 1.42 KB
/
Copy pathgolden_test.py
File metadata and controls
42 lines (31 loc) · 1.42 KB
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
import os
import subprocess
import tempfile
import pytest
import shlex
def run_command( command ):
subprocess.call(shlex.split(command), shell=False, cwd='..')
@pytest.mark.golden_test("golden/*.yml")
def test_translator_and_machine(golden):
with tempfile.TemporaryDirectory() as tmpdirname:
source = os.path.join(tmpdirname, "source.sasm")
input_stream = os.path.join(tmpdirname, "input.txt")
output_stream = os.path.join(tmpdirname, "output.txt")
log_stream = os.path.join(tmpdirname, "comp_log.txt")
target = os.path.join(tmpdirname, "target.o")
with open(source, "w", encoding="utf-8") as file:
file.write(golden["in_source"])
with open(input_stream, "w", encoding="utf-8") as file:
file.write(golden["in_stdin"])
run_command(f"./gradlew asm:run --args=\"{source} {target}\"")
run_command(f"./gradlew comp:run "
f"--args=\"-p {target} -i {input_stream} -o {output_stream} -l {log_stream}\"")
with open(target, "r", encoding="utf-8") as file:
code = file.read()
with open(output_stream, "r", encoding="utf-8") as file:
output = file.read()
with open(log_stream, "r", encoding="utf-8") as file:
log = file.read()
assert code == golden.out["out_code"]
assert output == golden.out["out_stdout"]
assert log == golden.out["out_log"]