forked from stoopidOrganization/stoopid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
45 lines (40 loc) · 1.27 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
#Tests for stoopid interpreter
import os,sys
def test_file(file):
with open(file, "r") as f:
header = f.readlines()[0]
if header.startswith("#expected"):
print(f"{file} is a valid test file\n")
else:
print(f"{file} is not a valid test file")
exit(1)
#get the expected output
with open(file,"r") as f:
expected=header.split(":")[1].split(",")
print("The expected output is:")
for i in expected:
print(" "+i.strip())
print()
os.system(f"python stoopid.py {file} --log output.txt --silent")
with open("output.txt","r") as f:
output=f.readlines()
print("The output is:")
o=[]
for i in output:
if i.strip().replace("\n","")!="":
o.append(i.strip().replace("\n",""))
failed="Passed"
for i in range(len(expected)):
try:
print(" "+o[i],end="")
if o[i].strip()!=expected[i].strip():
print(f"\t<-- Missmatch! Expected {expected[i]}",end="")
failed="Failed"
print()
except Exception:
print(f"{file} failed in line {i+1} (something happened, idk)")
failed="Failed"
print(f"\n {file} {failed}")
os.system("del output.txt")
return 1
test_file(sys.argv[1])