fix(tools): ignore test names when checking executable registration

This commit is contained in:
Привалов Александр Владимирович 2026-10-09 14:10:44 +03:00 committed by Adrià Franch
parent a29bae31af
commit e419096bff
3 changed files with 41 additions and 1 deletions

View File

@ -49,6 +49,8 @@ if(BUILD_TESTING)
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_import_audit.py)
add_test(NAME conventions_function_bodies COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_check_conventions_comments.py)
add_test(NAME test_registration COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_test_registration.py)
add_test(NAME hardware_oracle COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/hw-oracle/test_hw_oracle.py)
add_test(NAME pr_overlap_exports COMMAND ${Python3_EXECUTABLE}

View File

@ -34,7 +34,8 @@ def registered(build):
found = re.match(r"\s*add_test\s*\((.*)\)\s*$", line)
if not found:
continue
for token in re.findall(r'"([^"]*)"|(\S+)', found.group(1)):
tokens = re.findall(r'"([^"]*)"|(\S+)', found.group(1))
for token in tokens[1:]:
argument = token[0] or token[1]
base = re.split(r"[\\/]", argument)[-1]
if base.endswith(".exe"):

View File

@ -0,0 +1,37 @@
from pathlib import Path
import sys
import tempfile
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import check_test_registration
class RegistrationTests(unittest.TestCase):
def registered(self, content):
with tempfile.TemporaryDirectory() as directory:
build = Path(directory)
(build / "CTestTestfile.cmake").write_text(content, encoding="utf-8")
return check_test_registration.registered(build)
def test_test_name_does_not_register_executable(self):
names = self.registered('add_test("missing_tests" "/usr/bin/python3" "unrelated.py")\n')
self.assertNotIn("missing_tests", names)
def test_direct_executable(self):
names = self.registered('add_test("bounds" "/build/tests/buffer_bounds_tests")\n')
self.assertIn("buffer_bounds_tests", names)
self.assertNotIn("bounds", names)
def test_wrapped_executable(self):
names = self.registered('add_test("bounds" "/usr/bin/python3" "runner.py" "/build/tests/buffer_bounds_tests")\n')
self.assertIn("buffer_bounds_tests", names)
def test_windows_executable_and_test_name(self):
names = self.registered('add_test("missing_tests.exe" "C:/Program Files/Python/python.exe" "runner.py" "C:/build/tests/buffer_bounds_tests.exe")\n')
self.assertIn("buffer_bounds_tests", names)
self.assertNotIn("missing_tests", names)
if __name__ == "__main__":
unittest.main()