Pārlūkot izejas kodu

Fake $HOME to isolate tests from user

On platforms with $HOME in the environment, some of our features use it
to store information in the user home directory.  However, tests for
these features should not touch the real user home directory.  Instead
we configure a fake $HOME that points inside the build tree for use
during testing.

See issue #9949.
Brad King 16 gadi atpakaļ
vecāks
revīzija
647d7105b4
1 mainītis faili ar 7 papildinājumiem un 0 dzēšanām
  1. 7 0
      Tests/EnforceConfig.cmake.in

+ 7 - 0
Tests/EnforceConfig.cmake.in

@@ -27,3 +27,10 @@ IF(NOT CTEST_CONFIGURATION_TYPE AND CONFIG_REQUIRED)
   ENDIF(NOT CTEST_CONFIGURATION_TYPE)
   MESSAGE("Guessing configuration ${CTEST_CONFIGURATION_TYPE}")
 ENDIF(NOT CTEST_CONFIGURATION_TYPE AND CONFIG_REQUIRED)
+
+# Fake a user home directory to avoid polluting the real one.
+IF(DEFINED ENV{HOME})
+  SET(HOME "@CMake_BINARY_DIR@/Tests/CMakeFiles/TestHome")
+  FILE(MAKE_DIRECTORY "${HOME}")
+  SET(ENV{HOME} "${HOME}")
+ENDIF(DEFINED ENV{HOME})