-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_tests.py
92 lines (77 loc) · 2.96 KB
/
run_tests.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
from subprocess import check_output, DEVNULL
import sys
is_ci = sys.argv[1] == 'ci'
def getAllTestFiles() -> list:
from os import listdir
from os.path import isfile, join
test_path=".\Team36\Tests36"
return [f for f in listdir(test_path) if isfile(join(test_path, f))]
def getAllTestCases(tc_files):
return sorted(list(set([int(f.split('_')[0]) for f in tc_files])))
tc_files = getAllTestFiles()
tc_description_map = {int(f.split('_')[0]): f.split('_')[1] for f in tc_files if 'source' in f}
def parseArg(arg: str):
if arg.isdigit():
return [int(arg)]
if arg == 'all' or arg == 'ci':
return getAllTestCases(tc_files)
if '-' in arg:
l = arg.split('-')
return range(int(l[0]), int(l[1]) + 1)
if ',' in arg:
l = arg.split(',')
return [int(i) for i in l]
print("Invalid Args")
exit(1)
# CHECK
if len(sys.argv) < 2:
print("\nExample Usage:")
print("\tpython .\\run_tests.py 1-5 \t# Run Testcase 1-5")
print("\tpython .\\run_tests.py 1,2 \t# Run Testcase 1 and 2")
print("\tpython .\\run_tests.py 1 \t# Run Testcase 1")
print("\tpython .\\run_tests.py 1-15 105-106 \t# Run Testcase 1-5 and 105-106\n")
exit(1)
unflattened_testcases = [parseArg(sys.argv[i]) for i in range(1,len(sys.argv))]
testcases = [i for sublst in unflattened_testcases for i in sublst]
# BUILD
print("Building...", end="",flush=True)
if is_ci == False:
from os import path
possible_locations = [
"C:\Program Files (x86)\Microsoft Visual Studio\\2019\Community\MSBuild\Current\Bin\MSBuild.exe",
"C:\Program Files\Microsoft Visual Studio\\2022\Community\Msbuild\Current\Bin\MSBuild.exe",
]
msbuild=''
for p in possible_locations:
if path.exists(p):
msbuild = p
break
if not msbuild:
print("MSBuild not found.")
exit(1)
sln_path =".\Team36\Code36\StartupSPASolution.sln"
if not "Build succeeded." in str(check_output((msbuild, sln_path))):
print("Build Failed.")
exit(1)
print("Done.")
# TEST
from time import time
autotester = ".\Team36\Code36\Debug\AutoTester.exe"
score = 0
start_time = time()
for i in testcases:
test_cmd = f"{autotester} .\Team36\Tests36\{i}_{tc_description_map[i]}_source.txt .\Team36\Tests36\{i}_{tc_description_map[i]}_queries.txt .\Team36\Code36\Tests\out.xml"
output = check_output(test_cmd, stderr=DEVNULL).decode()
if "Missing:" in output:
if is_ci:
raise Exception(f"[TEST CASE {i}] [{tc_description_map[i]}] FAILED")
else:
print(f"[TEST CASE {i}] [{tc_description_map[i]}] FAILED -----> Log File : ./TEST_CASE_{i}.out")
with open(f"TEST_CASE_{i}.out", "w") as f: f.write(output)
else:
score+=1
print(f"[TEST CASE {i}] PASSED")
end_time = time()
print(f"Score : {score} / {len(testcases)}")
print(f"Time Taken : {end_time - start_time}s")