-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp.py
36 lines (31 loc) · 893 Bytes
/
comp.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
#utf-8
import subprocess, shlex
filename='testrun'
a=subprocess.Popen(['g++', filename+'.cpp'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stats=a.communicate()
if stats[0].decode() != '':
print('Output:\n')
print(stats[0].decode())
if stats[1].decode() != '':
print("Compile time error:\n")
print(stats[1].decode())
tcf=open('testcases.txt', 'r')
tc=tcf.readlines()
tcf.close()
print("Testing:\n")
run=[]
i = 0
while i<len(tc):
args=shlex.split('./a.out > '+filename+'.txt')
b=subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
b.stdin.write(tc[i].encode('utf-8'))
b.stdin.close()
output = b.stdout.read().decode()
error = b.stderr.read().decode()
print(output)
print(tc[i+1])
if output==tc[i+1].rstrip('\n'):
run.append('Success')
else:
run.append('Failed')
i+=2