-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautotest.py
33 lines (24 loc) · 1012 Bytes
/
autotest.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
import subprocess
from subprocess import PIPE
class TmpFileManager:
def __init__(self, dirs, files):
self.dirs = dirs
self.files = files
def __enter__(self):
for d in self.dirs:
subprocess.run(f"mkdir {d}", shell=True)
for f in self.files:
subprocess.run(f"touch {f}", shell=True)
def __exit__(self, ex_type, ex_value, trace):
for f in self.files:
subprocess.run(f"rm {f}", shell=True)
for d in self.dirs:
subprocess.run(f"rm -r {d}", shell=True)
if __name__=='__main__':
proc = subprocess.run("cargo run", shell=True, stdout=PIPE)
with TmpFileManager(['tmp'], ['tmp/test.ll', "tmp/main.out"]):
with open('tmp/test.ll', 'wb') as wb:
wb.write(proc.stdout)
subprocess.run("clang tmp/test.ll -o tmp/main.out", shell=True)
proc = subprocess.run("tmp/main.out",shell=True, stdout=PIPE, stderr=PIPE)
print(f"status code: {proc.returncode}")