Skip to content

Commit

Permalink
BUG: Fix setting of test launch environment using "environment modifi…
Browse files Browse the repository at this point in the history
…cations"
  • Loading branch information
jcfr committed Jan 13, 2024
1 parent 6d6e94c commit a91ebcf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMake/ctkMacroSimpleTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ macro(SIMPLE_TEST testname)
add_test(NAME ${testname} COMMAND $<TARGET_FILE:${KIT}CppTests> ${testname} ${ARGN})
set_property(TEST ${testname} PROPERTY LABELS ${KIT})

set_property(TEST ${testname} PROPERTY ENVIRONMENT "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT}")
set_property(TEST ${testname} PROPERTY ENVIRONMENT_MODIFICATION "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION}")

endmacro()

2 changes: 1 addition & 1 deletion CMake/ctkMacroSimpleTestWithData.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ macro(SIMPLE_TEST_WITH_DATA testname baseline_relative_location)
)
set_property(TEST ${testname} PROPERTY LABELS ${KIT})

set_property(TEST ${testname} PROPERTY ENVIRONMENT "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT}")
set_property(TEST ${testname} PROPERTY ENVIRONMENT_MODIFICATION "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION}")
endmacro()

42 changes: 24 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1065,11 +1065,13 @@ set(CTK_PATHS_LAUNCHER_BUILD )
set(CTK_LIBRARY_PATHS_LAUNCHER_BUILD )
set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT )

if(${CMAKE_VERSION} VERSION_EQUAL "3.9" OR ${CMAKE_VERSION} VERSION_GREATER "3.9")
if(${CMAKE_VERSION} VERSION_EQUAL "3.22" OR ${CMAKE_VERSION} VERSION_GREATER "3.22")

# CMake 3.9 introduces support for "$<IF:...>" generator expression
# and GENERATOR_IS_MULTI_CONFIG property.

# CMake 3.22 introduces support for ENVIRONMENT_MODIFICATION test property.

# Generate expression evaluating to the current build configuration or "."
# for single configuration generator
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
Expand Down Expand Up @@ -1106,32 +1108,36 @@ if(${CMAKE_VERSION} VERSION_EQUAL "3.9" OR ${CMAKE_VERSION} VERSION_GREATER "3.9
list(APPEND CTK_PATHS_LAUNCHER_BUILD ${value})
endforeach()

# Set test launch environment specific to the build tree
if(WIN32)
# On Windows, create semicolon-separated strings for paths and library paths
set(separator "$<SEMICOLON>")
ctk_list_to_string(${separator} "${CTK_PATHS_LAUNCHER_BUILD};${CTK_LIBRARY_PATHS_LAUNCHER_BUILD}" env_paths)
# Set test launch "environment modification" specific to the build tree
set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION)

string(REPLACE ";" "${separator}" sanitized_current_path "$ENV{PATH}")
if(WIN32)
# Paths and Library paths
foreach(value IN LISTS CTK_PATHS_LAUNCHER_BUILD CTK_LIBRARY_PATHS_LAUNCHER_BUILD)
list(APPEND CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:${value}"
)
endforeach()

set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT
"PATH=${env_paths}${separator}${sanitized_current_path}"
)
else()
# On UNIX-like systems, create colon-separated strings for paths and library paths
set(separator ":")
ctk_list_to_string(${separator} "${CTK_PATHS_LAUNCHER_BUILD}" env_paths)
ctk_list_to_string(${separator} "${CTK_LIBRARY_PATHS_LAUNCHER_BUILD}" env_library_paths)
# Path
foreach(value IN LISTS CTK_PATHS_LAUNCHER_BUILD)
list(APPEND CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:${value}"
)
endforeach()

# Library paths
set(variable_name "LD_LIBRARY_PATH")
if(APPLE)
set(variable_name "DYLD_LIBRARY_PATH")
endif()

set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT
"PATH=${env_paths}${separator}$ENV{PATH}"
"${variable_name}=${env_library_paths}${separator}$ENV{${variable_name}}"
)
foreach(value IN LISTS CTK_LIBRARY_PATHS_LAUNCHER_BUILD)
list(APPEND CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION
"${variable_name}=path_list_prepend:${value}"
)
endforeach()
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion Libs/DICOM/Widgets/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ SIMPLE_TEST(ctkDICOMThumbnailListWidgetTest1
if(EXISTS "${CTKData_DIR}")
SIMPLE_TEST(ctkDICOMAppWidgetTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD)
SIMPLE_TEST(ctkDICOMBrowserTest)
set_property(TEST ctkDICOMBrowserTest PROPERTY ENVIRONMENT "CTKData_DIR=${CTKData_DIR}" APPEND)
set_property(TEST ctkDICOMBrowserTest PROPERTY ENVIRONMENT "CTKData_DIR=${CTKData_DIR}")
SIMPLE_TEST(ctkDICOMBrowserTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD)
SIMPLE_TEST(ctkDICOMItemViewTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD/000055.IMA)
SIMPLE_TEST(ctkDICOMImageTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD/000055.IMA)
Expand Down

0 comments on commit a91ebcf

Please sign in to comment.