-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.py
56 lines (45 loc) · 1.48 KB
/
test.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
"""
Btw this test code was mostly written for farkon00/cont repo.
But it's owner(farkon00) granted permission with MIT License to use it.
And this code was added orginally by him.
"""
import os
import subprocess
import pytest
tests = os.listdir("tests")
try:
os.mkdir("tests/results")
except FileExistsError:
tests.remove("results")
try:
os.mkdir("tests/temp")
except FileExistsError:
tests.remove("temp")
@pytest.mark.parametrize("test_name", tests)
def test(test_name):
with open(f"tests/{test_name}", "r") as f:
test = f.read()
parts = test.split("\n:\n")
with open("tests/temp/code.vlang", "w") as f:
f.write(parts[0])
with open("tests/temp/stdin", "w") as f:
if len(parts) > 2:
f.write(parts[2])
exp_stdout = parts[1]
if len(parts) > 3:
exp_stderr = parts[3]
else:
exp_stderr = ""
stdout = open(f"tests/results/{test_name}_stdout", "w")
stderr = open(f"tests/results/{test_name}_stderr", "w")
stdin = open("tests/temp/stdin", "r")
subprocess.run(["python3", "src/main.py", "tests/temp/code.vlang", "-r", "-s"], stdout=stdout, stderr=stderr, stdin=stdin)
stdout.close()
stderr.close()
stdin.close()
with open(f"tests/results/{test_name}_stdout", "r") as f:
stdout_content = f.read()
with open(f"tests/results/{test_name}_stderr", "r") as f:
stderr_content = f.read()
assert stdout_content == exp_stdout
assert stderr_content == exp_stderr