-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2e_tests.py
More file actions
39 lines (33 loc) · 1.4 KB
/
e2e_tests.py
File metadata and controls
39 lines (33 loc) · 1.4 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
import os
import subprocess
import tempfile
import sys
import re
files = [f for f in os.listdir('test_programs')]
if len(sys.argv) > 1 and sys.argv[1] == "local":
local = True
else:
local = False
for f in files:
with open(f'test_programs/{f}', 'r') as file:
print(f'Running test file {f}')
test_file = file.read()
tests = filter(lambda x: x != '', re.split('^---$', test_file, flags=re.MULTILINE))
for test in tests:
input_file = str(tempfile.NamedTemporaryFile(mode='w', delete=True).name)
output_file = str(tempfile.NamedTemporaryFile(mode='w', delete=True).name)
test_source = test.split('out:\n')[0]
expected = test.split('out:\n')[1]
with open(input_file, 'w') as input_f:
input_f.write(test_source)
code = os.system(f'./run{"_local" if local else ""}.sh {input_file} {output_file}')
if code != 0:
print(f'Failed to compile {f}')
exit(1)
else:
subprocess.run(['chmod', 'u+x', output_file], check=True)
program_output = subprocess.check_output(output_file, shell=True).decode()
if program_output != expected:
print(f'Failed test {test_source} in {f}, expected {expected} but got {program_output}')
else:
print(f'Passed test in {f}')