Tests: Isolate test suite from user-wide configuration

This commit is contained in:
Brad King 2024-08-22 09:55:36 -04:00
parent 320b81847d
commit a991a5019b
2 changed files with 7 additions and 2 deletions

View File

@ -32,10 +32,14 @@ endmacro()
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckSwift.cmake)
# Isolate tests from user-wide configuration.
set(TEST_HOME "${CMake_BINARY_DIR}/Tests/CMakeFiles/TestHome")
set(TEST_CONFIG_ENV_CODE "# Isolate tests from user-wide configuration.
set(ENV{CMAKE_CONFIG_DIR} \"${TEST_HOME}/.config/cmake\")\n")
file(MAKE_DIRECTORY "${TEST_HOME}/.config/cmake")
# Fake a user home directory to avoid polluting the real one.
if(NOT CTEST_NO_TEST_HOME AND (NOT WIN32 OR DEFINED ENV{HOME}))
set(TEST_HOME "${CMake_BINARY_DIR}/Tests/CMakeFiles/TestHome")
file(MAKE_DIRECTORY "${TEST_HOME}")
set(TEST_HOME_ENV_CODE "# Fake a user home directory to avoid polluting the real one.
# But provide original ENV{HOME} value in ENV{CTEST_REAL_HOME} for tests that
# need access to the real HOME directory.

View File

@ -38,5 +38,6 @@ unset(ENV{CMAKE_EXPORT_COMPILE_COMMANDS})
# Verify that our module implementations do not recurse too much.
set(ENV{CMAKE_MAXIMUM_RECURSION_DEPTH} 100)
@TEST_CONFIG_ENV_CODE@
@TEST_HOME_ENV_CODE@
@TEST_WARN_VS_CODE@