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
|
#!/usr/bin/env python3
""" Test runner """
import argparse
import os
import subprocess
def main():
""" Main function"""
parser = argparse.ArgumentParser(description='Run test executables')
parser.add_argument('-v', '--verbose', action='store_true', help='Show test stdout/stderr')
parser.add_argument('--valgrind', action='store_true', help='Run tests under valgrind')
parser.add_argument('test', type=str, nargs='+', help='test executable to run')
args = parser.parse_args()
cwd = os.getcwd()
fail_count = 0
for test in args.test:
cmd = []
if args.valgrind:
cmd += [ 'valgrind', '--leak-check=full', '--error-exitcode=128' ]
cmd.append(os.path.join(cwd, test))
#print(cmd)
if not args.verbose:
print(f' {test:.<48}', end='')
result = subprocess.run(cmd, capture_output=not args.verbose, check=False)
if not args.verbose:
print('ok' if result.returncode == 0 else 'failed')
if result.returncode != 0:
fail_count += 1
print(f' Ran {len(args.test)} tests, {fail_count} failed')
if __name__ == '__main__':
main()
|