mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Added new DL_PATHS option to catch_discover_tests() (#2467)
This enables setting the required PATH/LD_LIBRARY_PATH environment variables both when retrieving the list of text cases and when executing the tests. Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
This commit is contained in:
parent
5f9109a8dc
commit
a63ad74554
@ -116,6 +116,13 @@ same as the Catch name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
|
|||||||
``--out dir/<test_name>suffix``. This can be used to add a file extension to
|
``--out dir/<test_name>suffix``. This can be used to add a file extension to
|
||||||
the output e.g. ".xml".
|
the output e.g. ".xml".
|
||||||
|
|
||||||
|
``DL_PATHS path...``
|
||||||
|
Specifies paths that need to be set for the dynamic linker to find shared
|
||||||
|
libraries/DLLs when running the test executable (PATH/LD_LIBRARY_PATH respectively).
|
||||||
|
These paths will both be set when retrieving the list of test cases from the
|
||||||
|
test executable and when the tests are executed themselves. This requires
|
||||||
|
cmake/ctest >= 3.22.
|
||||||
|
|
||||||
#]=======================================================================]
|
#]=======================================================================]
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
@ -124,7 +131,7 @@ function(catch_discover_tests TARGET)
|
|||||||
""
|
""
|
||||||
""
|
""
|
||||||
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;REPORTER;OUTPUT_DIR;OUTPUT_PREFIX;OUTPUT_SUFFIX"
|
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;REPORTER;OUTPUT_DIR;OUTPUT_PREFIX;OUTPUT_SUFFIX"
|
||||||
"TEST_SPEC;EXTRA_ARGS;PROPERTIES"
|
"TEST_SPEC;EXTRA_ARGS;PROPERTIES;DL_PATHS"
|
||||||
${ARGN}
|
${ARGN}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -135,6 +142,12 @@ function(catch_discover_tests TARGET)
|
|||||||
set(_TEST_LIST ${TARGET}_TESTS)
|
set(_TEST_LIST ${TARGET}_TESTS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (_DL_PATHS)
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS "3.22.0")
|
||||||
|
message(FATAL_ERROR "The DL_PATHS option requires at least cmake 3.22")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
## Generate a unique name based on the extra arguments
|
## Generate a unique name based on the extra arguments
|
||||||
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS} ${_REPORTER} ${_OUTPUT_DIR} ${_OUTPUT_PREFIX} ${_OUTPUT_SUFFIX}")
|
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS} ${_REPORTER} ${_OUTPUT_DIR} ${_OUTPUT_PREFIX} ${_OUTPUT_SUFFIX}")
|
||||||
string(SUBSTRING ${args_hash} 0 7 args_hash)
|
string(SUBSTRING ${args_hash} 0 7 args_hash)
|
||||||
@ -164,6 +177,7 @@ function(catch_discover_tests TARGET)
|
|||||||
-D "TEST_OUTPUT_DIR=${_OUTPUT_DIR}"
|
-D "TEST_OUTPUT_DIR=${_OUTPUT_DIR}"
|
||||||
-D "TEST_OUTPUT_PREFIX=${_OUTPUT_PREFIX}"
|
-D "TEST_OUTPUT_PREFIX=${_OUTPUT_PREFIX}"
|
||||||
-D "TEST_OUTPUT_SUFFIX=${_OUTPUT_SUFFIX}"
|
-D "TEST_OUTPUT_SUFFIX=${_OUTPUT_SUFFIX}"
|
||||||
|
-D "TEST_DL_PATHS=${_DL_PATHS}"
|
||||||
-D "CTEST_FILE=${ctest_tests_file}"
|
-D "CTEST_FILE=${ctest_tests_file}"
|
||||||
-P "${_CATCH_DISCOVER_TESTS_SCRIPT}"
|
-P "${_CATCH_DISCOVER_TESTS_SCRIPT}"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
|
@ -10,10 +10,17 @@ set(reporter ${TEST_REPORTER})
|
|||||||
set(output_dir ${TEST_OUTPUT_DIR})
|
set(output_dir ${TEST_OUTPUT_DIR})
|
||||||
set(output_prefix ${TEST_OUTPUT_PREFIX})
|
set(output_prefix ${TEST_OUTPUT_PREFIX})
|
||||||
set(output_suffix ${TEST_OUTPUT_SUFFIX})
|
set(output_suffix ${TEST_OUTPUT_SUFFIX})
|
||||||
|
set(dl_paths ${TEST_DL_PATHS})
|
||||||
set(script)
|
set(script)
|
||||||
set(suite)
|
set(suite)
|
||||||
set(tests)
|
set(tests)
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
set(dl_paths_variable_name PATH)
|
||||||
|
else()
|
||||||
|
set(dl_paths_variable_name LD_LIBRARY_PATH)
|
||||||
|
endif()
|
||||||
|
|
||||||
function(add_command NAME)
|
function(add_command NAME)
|
||||||
set(_args "")
|
set(_args "")
|
||||||
# use ARGV* instead of ARGN, because ARGN splits arrays into multiple arguments
|
# use ARGV* instead of ARGN, because ARGN splits arrays into multiple arguments
|
||||||
@ -35,6 +42,12 @@ if(NOT EXISTS "${TEST_EXECUTABLE}")
|
|||||||
"Specified test executable '${TEST_EXECUTABLE}' does not exist"
|
"Specified test executable '${TEST_EXECUTABLE}' does not exist"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(dl_paths)
|
||||||
|
cmake_path(CONVERT "${dl_paths}" TO_NATIVE_PATH_LIST paths)
|
||||||
|
set(ENV{${dl_paths_variable_name}} "${paths}")
|
||||||
|
endif()
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-tests --verbosity quiet
|
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-tests --verbosity quiet
|
||||||
OUTPUT_VARIABLE output
|
OUTPUT_VARIABLE output
|
||||||
@ -85,6 +98,13 @@ if(output_dir AND NOT IS_ABSOLUTE ${output_dir})
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(dl_paths)
|
||||||
|
foreach(path ${dl_paths})
|
||||||
|
cmake_path(NATIVE_PATH path native_path)
|
||||||
|
list(APPEND environment_modifications "${dl_paths_variable_name}=path_list_prepend:${native_path}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Parse output
|
# Parse output
|
||||||
foreach(line ${output})
|
foreach(line ${output})
|
||||||
set(test ${line})
|
set(test ${line})
|
||||||
@ -115,6 +135,14 @@ foreach(line ${output})
|
|||||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
||||||
${properties}
|
${properties}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(environment_modifications)
|
||||||
|
add_command(set_tests_properties
|
||||||
|
"${prefix}${test}${suffix}"
|
||||||
|
PROPERTIES
|
||||||
|
ENVIRONMENT_MODIFICATION "${environment_modifications}")
|
||||||
|
endif()
|
||||||
|
|
||||||
list(APPEND tests "${prefix}${test}${suffix}")
|
list(APPEND tests "${prefix}${test}${suffix}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user