-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.py
executable file
·59 lines (49 loc) · 1.76 KB
/
run_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
57
58
59
#!/usr/bin/env python3
import os
import signal
import sys
import time
import subprocess
def signal_handler(sig, frame):
print("\033[1;34m --testing cancelled-- \033[0m")
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
total_compile_time = 0
compile_times = []
test_files = []
os.chdir('tests')
def run_test(test_file):
print(f"\033[1;33mRunning test: {test_file}\033[0m")
start_time = time.time_ns()
result = subprocess.run(["ela", test_file, "--test"])
end_time = time.time_ns()
if result.returncode == 0:
compile_time = (end_time - start_time) // 1000000
compile_times.append(compile_time)
test_files.append(test_file)
global total_compile_time
total_compile_time += compile_time
run_result = subprocess.run([f"./{test_file[:-4]}"])
if run_result.returncode == 0 and os.path.isfile(test_file[:-4]):
os.remove(test_file[:-4])
else:
print(f"\033[1;31mCompilation failed for {test_file}\033[0m")
def main():
if len(sys.argv) > 1 and sys.argv[1] != "--time":
test_file = f"{sys.argv[1]}.ela"
if os.path.isfile(test_file):
run_test(test_file)
sys.exit(0)
else:
print(f"\033[1;31mTest file {test_file} does not exist\033[0m")
sys.exit(1)
for test_file in os.listdir('.'):
if test_file.endswith('.ela'):
run_test(test_file)
if len(sys.argv) > 1 and sys.argv[1] == "--time":
for i, compile_time in enumerate(compile_times):
print(f"\033[1;36m\033[1m{test_files[i]}\033[0m took \033[1;32m\033[1m{compile_time}ms\033[0m")
print(f"\033[0mran \033[1;33m\033[1m{len(compile_times)}\033[0m in \033[1;32m{total_compile_time}ms\033[0m")
if __name__ == "__main__":
main()