Skip to content

Commit

Permalink
Add tests for multiple args to DL_PATHS in catch_discover_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Mar 26, 2024
1 parent 2558001 commit a6627f8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/TestScripts/DiscoverTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include(Catch)
set(extra_args)
if (CMAKE_VERSION GREATER_EQUAL 3.27)
list(APPEND extra_args
DL_PATHS "$<TARGET_RUNTIME_DLL_DIRS:tests>"
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)

0 comments on commit a6627f8

Please sign in to comment.