mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	Add tests for multiple args to DL_PATHS in catch_discover_tests
This commit is contained in:
		| @@ -16,7 +16,7 @@ include(Catch) | |||||||
| set(extra_args) | set(extra_args) | ||||||
| if (CMAKE_VERSION GREATER_EQUAL 3.27) | if (CMAKE_VERSION GREATER_EQUAL 3.27) | ||||||
|     list(APPEND extra_args |     list(APPEND extra_args | ||||||
|             DL_PATHS "$<TARGET_RUNTIME_DLL_DIRS:tests>" |             DL_PATHS "${CMAKE_CURRENT_LIST_DIR};${CMAKE_CURRENT_LIST_DIR}/.." | ||||||
|     ) |     ) | ||||||
| endif () | endif () | ||||||
| catch_discover_tests(tests ${extra_args}) | catch_discover_tests(tests ${extra_args}) | ||||||
|   | |||||||
| @@ -10,7 +10,24 @@ | |||||||
| import os | import os | ||||||
| import subprocess | import subprocess | ||||||
| import sys | 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): | def build_project(sources_dir, output_base_path, catch2_path): | ||||||
|     build_dir = os.path.join(output_base_path, 'ctest-registration-test') |     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) |     root = ET.fromstring(result.stdout) | ||||||
|     return [tc.text for tc in root.findall('TestCase/Name')] |     return [tc.text for tc in root.findall('TestCase/Name')] | ||||||
|  |  | ||||||
|  | def get_ctest_listing(build_path): | ||||||
| def list_ctest_tests(build_path): |  | ||||||
|     old_path = os.getcwd() |     old_path = os.getcwd() | ||||||
|     os.chdir(build_path) |     os.chdir(build_path) | ||||||
|  |  | ||||||
| @@ -73,10 +89,10 @@ def list_ctest_tests(build_path): | |||||||
|                             check = True, |                             check = True, | ||||||
|                             text = True) |                             text = True) | ||||||
|     os.chdir(old_path) |     os.chdir(old_path) | ||||||
|  |     return result.stdout | ||||||
|  |  | ||||||
|     import json | def extract_tests_from_ctest(ctest_output): | ||||||
|  |     ctest_response = json.loads(ctest_output) | ||||||
|     ctest_response = json.loads(result.stdout) |  | ||||||
|     tests = ctest_response['tests'] |     tests = ctest_response['tests'] | ||||||
|     test_names = [] |     test_names = [] | ||||||
|     for test in tests: |     for test in tests: | ||||||
| @@ -90,6 +106,15 @@ def list_ctest_tests(build_path): | |||||||
|  |  | ||||||
|     return test_names |     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): | def escape_catch2_test_name(name): | ||||||
|     for char in ('\\', ',', '[', ']'): |     for char in ('\\', ',', '[', ']'): | ||||||
|         name = name.replace(char, f"\\{char}") |         name = name.replace(char, f"\\{char}") | ||||||
| @@ -106,7 +131,8 @@ if __name__ == '__main__': | |||||||
|     build_path = build_project(sources_dir, output_base_path, catch2_path) |     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)] |     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 |     mismatched = 0 | ||||||
|     for catch_test in catch_test_names: |     for catch_test in catch_test_names: | ||||||
| @@ -121,3 +147,7 @@ if __name__ == '__main__': | |||||||
|     if mismatched: |     if mismatched: | ||||||
|         print(f"Found {mismatched} mismatched tests catch test names and ctest test commands!") |         print(f"Found {mismatched} mismatched tests catch test names and ctest test commands!") | ||||||
|         exit(1) |         exit(1) | ||||||
|  |  | ||||||
|  |     cmake_version = get_cmake_version() | ||||||
|  |     if cmake_version >= (3, 27): | ||||||
|  |         check_DL_PATHS(ctest_output) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský