Skip to content

Commit

Permalink
CMake: Add function to add tests that change working directory.
Browse files Browse the repository at this point in the history
Add a new CMake function that help to add tests that change their
working directory to somewhere else than the directory with the
libarpack library.

In that case, the environment variable PATH is set to include the
directory with the library on Windows while running the tests.

Use that new CMake function for the three ctests involving the Eigen
library.
  • Loading branch information
mmuetzel committed Jun 30, 2024
1 parent 23c7caf commit 596c110
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,19 @@ endif()
############################
# TEST
############################
function(build_tests)

function(add_test_with_working_dir test_name)
# Add test which sets a current working directory that doesn't contain the
# libarpack library.
add_test(NAME ${test_name} ${ARGN})
if (WIN32 AND BUILD_SHARED_LIBS)
set_tests_properties(${test_name}
PROPERTIES
ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:arpack>")
endif()
endfunction()

function(build_tests)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/TESTS)

add_executable(dnsimp_test TESTS/dnsimp.f TESTS/mmio.f TESTS/debug.h)
Expand Down Expand Up @@ -704,18 +716,19 @@ function(build_tests)
configure_file(EXAMPLES/MATRIX_MARKET/B.mtx ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/B.mtx)
configure_file(EXAMPLES/MATRIX_MARKET/Bz.mtx ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Bz.mtx)
configure_file(EXAMPLES/MATRIX_MARKET/arpackmm.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/arpackmm.sh)
add_test(NAME arpackmm_tst WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${BASH_PROGRAM} -eu arpackmm.sh)
add_test_with_working_dir(arpackmm_tst
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND ${BASH_PROGRAM} -eu arpackmm.sh)
configure_file(EXAMPLES/MATRIX_MARKET/issue401.mtx ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/issue401.mtx)
configure_file(EXAMPLES/MATRIX_MARKET/issue401.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/issue401.sh)
add_test(NAME issue401_tst WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${BASH_PROGRAM} -eu issue401.sh)
add_test_with_working_dir(issue401_tst
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND ${BASH_PROGRAM} -eu issue401.sh)
configure_file(EXAMPLES/MATRIX_MARKET/issue215.mtx ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/issue215.mtx)
configure_file(EXAMPLES/MATRIX_MARKET/issue215.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/issue215.sh)
add_test(NAME issue215_tst WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${BASH_PROGRAM} -eu issue215.sh)
if (WIN32 AND BUILD_SHARED_LIBS)
set_tests_properties(arpackmm_tst issue401_tst issue215_tst
PROPERTIES
ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:arpack>")
endif()
add_test_with_working_dir(issue215_tst
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND ${BASH_PROGRAM} -eu issue215.sh)
endif()

if (PYTHON3)
Expand Down Expand Up @@ -800,7 +813,7 @@ endfunction(build_tests)

if(TESTS)
enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V)
set(CMAKE_CTEST_COMMAND ctest -V)
build_tests()
endif()

Expand Down

0 comments on commit 596c110

Please sign in to comment.