-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
executable file
·43 lines (35 loc) · 1.16 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
#!/usr/bin/env python3
"""
This script tests every file in the test folder to check if it works.
If one or more tests fail, then there is a problem with the compiler.
All tests must succed for new commits to be merged.
"""
from genericpath import isdir
import subprocess
import os
import sys
chirpc = './chirpc'
test_dir = 'tests'
suite_count = len([n for n in os.scandir(test_dir) if os.path.isdir(n)])
def run_command(*args):
try:
return subprocess.run(args, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL).returncode
except:
return -1
if run_command(chirpc, '--help') != 0:
print("Cannot run test. chirpc executable cannot be found")
sys.exit(-1)
print('Running Chirpc Tests.')
i = 1
for suite in os.scandir(test_dir):
if not suite.is_dir():
continue
print(f"-- Testing suite: {suite.name} ({i}/{suite_count}) --")
i += 1
for test in os.scandir(suite.path):
print(f'> Running test: {test.name}')
cmd = chirpc, test.path
if run_command(*cmd) != 0:
print(f"\"{test.name}\" Test failed (command: {' '.join(map(repr, cmd))})")
sys.exit(-1)
print('\nAll tests succeded!')