From e419096bffa6eb3d6a90e66a592a1aa04677f210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D0=B0=D0=BB=D0=BE=D0=B2=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20=D0=92=D0=BB?= =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 9 Oct 2026 14:10:44 +0300 Subject: [PATCH] fix(tools): ignore test names when checking executable registration --- CMakeLists.txt | 2 ++ tools/check_test_registration.py | 3 ++- tools/tests/test_test_registration.py | 37 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tools/tests/test_test_registration.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d9ff089f..f71c2a4de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} diff --git a/tools/check_test_registration.py b/tools/check_test_registration.py index 87fd459cb..991cdb59c 100644 --- a/tools/check_test_registration.py +++ b/tools/check_test_registration.py @@ -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"): diff --git a/tools/tests/test_test_registration.py b/tools/tests/test_test_registration.py new file mode 100644 index 000000000..4010ca6bd --- /dev/null +++ b/tools/tests/test_test_registration.py @@ -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()