Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TEST_DL_PATHS to multi-args #2825

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extras/CatchAddTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand Down
10 changes: 8 additions & 2 deletions tests/TestScripts/DiscoverTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "${CMAKE_CURRENT_LIST_DIR};${CMAKE_CURRENT_LIST_DIR}/.."
)
endif ()
catch_discover_tests(tests ${extra_args})
42 changes: 36 additions & 6 deletions tests/TestScripts/DiscoverTests/VerifyRegistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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}")
Expand All @@ -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:
Expand All @@ -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)
Loading