From 2558001d58db2f54b55d82b64ad54758af940ee0 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 26 Feb 2024 11:09:07 +0100 Subject: [PATCH 1/2] Fix `TEST_DL_PATHS` to be multi-args Signed-off-by: Cristian Le --- extras/CatchAddTests.cmake | 4 ++-- tests/TestScripts/DiscoverTests/CMakeLists.txt | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake index 692e340566..a0731941b2 100644 --- a/extras/CatchAddTests.cmake +++ b/extras/CatchAddTests.cmake @@ -21,8 +21,8 @@ function(catch_discover_tests_impl) cmake_parse_arguments( "" "" - "TEST_EXECUTABLE;TEST_WORKING_DIR;TEST_DL_PATHS;TEST_OUTPUT_DIR;TEST_OUTPUT_PREFIX;TEST_OUTPUT_SUFFIX;TEST_PREFIX;TEST_REPORTER;TEST_SPEC;TEST_SUFFIX;TEST_LIST;CTEST_FILE" - "TEST_EXTRA_ARGS;TEST_PROPERTIES;TEST_EXECUTOR" + "TEST_EXECUTABLE;TEST_WORKING_DIR;TEST_OUTPUT_DIR;TEST_OUTPUT_PREFIX;TEST_OUTPUT_SUFFIX;TEST_PREFIX;TEST_REPORTER;TEST_SPEC;TEST_SUFFIX;TEST_LIST;CTEST_FILE" + "TEST_EXTRA_ARGS;TEST_PROPERTIES;TEST_EXECUTOR;TEST_DL_PATHS" ${ARGN} ) diff --git a/tests/TestScripts/DiscoverTests/CMakeLists.txt b/tests/TestScripts/DiscoverTests/CMakeLists.txt index d19f2f8897..2919303e7e 100644 --- a/tests/TestScripts/DiscoverTests/CMakeLists.txt +++ b/tests/TestScripts/DiscoverTests/CMakeLists.txt @@ -11,6 +11,12 @@ add_executable(tests add_subdirectory(${CATCH2_PATH} catch2-build) target_link_libraries(tests PRIVATE Catch2::Catch2WithMain) -include(CTest) +enable_testing() include(Catch) -catch_discover_tests(tests) +set(extra_args) +if (CMAKE_VERSION GREATER_EQUAL 3.27) + list(APPEND extra_args + DL_PATHS "$" + ) +endif () +catch_discover_tests(tests ${extra_args}) From a6627f87a623d6af86f1b3b3d8997c2668832f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 26 Mar 2024 17:49:55 +0100 Subject: [PATCH 2/2] Add tests for multiple args to DL_PATHS in catch_discover_tests --- .../TestScripts/DiscoverTests/CMakeLists.txt | 2 +- .../DiscoverTests/VerifyRegistration.py | 42 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/tests/TestScripts/DiscoverTests/CMakeLists.txt b/tests/TestScripts/DiscoverTests/CMakeLists.txt index 2919303e7e..5105cddb64 100644 --- a/tests/TestScripts/DiscoverTests/CMakeLists.txt +++ b/tests/TestScripts/DiscoverTests/CMakeLists.txt @@ -16,7 +16,7 @@ include(Catch) set(extra_args) if (CMAKE_VERSION GREATER_EQUAL 3.27) list(APPEND extra_args - DL_PATHS "$" + DL_PATHS "${CMAKE_CURRENT_LIST_DIR};${CMAKE_CURRENT_LIST_DIR}/.." ) endif () catch_discover_tests(tests ${extra_args}) diff --git a/tests/TestScripts/DiscoverTests/VerifyRegistration.py b/tests/TestScripts/DiscoverTests/VerifyRegistration.py index 9ec42f24ca..9800674f25 100644 --- a/tests/TestScripts/DiscoverTests/VerifyRegistration.py +++ b/tests/TestScripts/DiscoverTests/VerifyRegistration.py @@ -10,7 +10,24 @@ import os import subprocess import sys +import re +import json +cmake_version_regex = re.compile('cmake version (\d+)\.(\d+)\.(\d+)') + +def get_cmake_version(): + result = subprocess.run(['cmake', '--version'], + capture_output = True, + check = True, + text = True) + version_match = cmake_version_regex.match(result.stdout) + if not version_match: + print('Could not find cmake version in output') + print(f"output: '{result.stdout}'") + exit(4) + return (int(version_match.group(1)), + int(version_match.group(2)), + int(version_match.group(3))) def build_project(sources_dir, output_base_path, catch2_path): build_dir = os.path.join(output_base_path, 'ctest-registration-test') @@ -62,8 +79,7 @@ def get_test_names(build_path): root = ET.fromstring(result.stdout) return [tc.text for tc in root.findall('TestCase/Name')] - -def list_ctest_tests(build_path): +def get_ctest_listing(build_path): old_path = os.getcwd() os.chdir(build_path) @@ -73,10 +89,10 @@ def list_ctest_tests(build_path): check = True, text = True) os.chdir(old_path) + return result.stdout - import json - - ctest_response = json.loads(result.stdout) +def extract_tests_from_ctest(ctest_output): + ctest_response = json.loads(ctest_output) tests = ctest_response['tests'] test_names = [] for test in tests: @@ -90,6 +106,15 @@ def list_ctest_tests(build_path): return test_names +def check_DL_PATHS(ctest_output): + ctest_response = json.loads(ctest_output) + tests = ctest_response['tests'] + for test in tests: + properties = test['properties'] + for property in properties: + if property['name'] == 'ENVIRONMENT_MODIFICATION': + assert len(property['value']) == 2, f"The test provides 2 arguments to DL_PATHS, but instead found {len(property['value'])}" + def escape_catch2_test_name(name): for char in ('\\', ',', '[', ']'): name = name.replace(char, f"\\{char}") @@ -106,7 +131,8 @@ def escape_catch2_test_name(name): build_path = build_project(sources_dir, output_base_path, catch2_path) catch_test_names = [escape_catch2_test_name(name) for name in get_test_names(build_path)] - ctest_test_names = list_ctest_tests(build_path) + ctest_output = get_ctest_listing(build_path) + ctest_test_names = extract_tests_from_ctest(ctest_output) mismatched = 0 for catch_test in catch_test_names: @@ -121,3 +147,7 @@ def escape_catch2_test_name(name): if mismatched: print(f"Found {mismatched} mismatched tests catch test names and ctest test commands!") exit(1) + + cmake_version = get_cmake_version() + if cmake_version >= (3, 27): + check_DL_PATHS(ctest_output)