-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·52 lines (42 loc) · 1.46 KB
/
test.py
File metadata and controls
executable file
·52 lines (42 loc) · 1.46 KB
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
#!/usr/bin/env python
import os
import re
import subprocess
# Config
enabled_tests = {}
ignored_tests = {"tests"}
# Generate tests
hpp_files = []
test_functions = []
files_with_tests = set()
test_case_declaration_pattern = re.compile(
r"^(test|utest)\((?P<function_name>[A-Za-z_0-9][A-Za-z_0-9]*),\n$"
)
for root, _, files in os.walk("./test"):
hpp_files.extend([os.path.join(root, f) for f in files if f.endswith(".hpp")])
for filepath in hpp_files:
with open(filepath, "r", encoding="utf-8") as file:
for line_num, line in enumerate(file, 1):
match = test_case_declaration_pattern.match(line)
if not match:
continue
function_name = match.group("function_name")
if function_name not in ignored_tests and (
len(enabled_tests) == 0 or function_name in enabled_tests
):
test_functions.append(function_name)
files_with_tests.add(filepath)
hpp_files = [x.split("/")[-1] for x in hpp_files if x in files_with_tests]
hpp_files.sort()
test_functions.sort()
includes = [f'#include "{file}"' for file in hpp_files]
test_main_call = f"test_main({', '.join(test_functions)})"
output = "\n".join(includes + [""] + [test_main_call])
with open("./test/main.cpp", "w", encoding="utf-8") as f:
f.write(output)
# Compile tests
os.chdir("build")
subprocess.run(["cmake", ".."])
subprocess.run(["cmake", "--build", "."])
# Run tests
subprocess.run(["./test"])