diff options
author | David Cole <david.cole@kitware.com> | 2008-11-26 19:38:43 (GMT) |
---|---|---|
committer | David Cole <david.cole@kitware.com> | 2008-11-26 19:38:43 (GMT) |
commit | ceaef94cccf10a02e1bcce29d3cfa6955acf4565 (patch) | |
tree | a0cbd04050fee7082c6e3e3ad38c73877fa6f806 /Source/cmCTest.cxx | |
parent | 003dbff85d58d6fc2668f2e1819b413a6357b2bc (diff) | |
download | CMake-ceaef94cccf10a02e1bcce29d3cfa6955acf4565.zip CMake-ceaef94cccf10a02e1bcce29d3cfa6955acf4565.tar.gz CMake-ceaef94cccf10a02e1bcce29d3cfa6955acf4565.tar.bz2 |
ENH: Implement feature request from issue 7885. Allow setting environment variables on a per-test basis for ctest using set_test_properties ENVIRONMENT.
Diffstat (limited to 'Source/cmCTest.cxx')
-rw-r--r-- | Source/cmCTest.cxx | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 049248e..629282b 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1105,8 +1105,12 @@ int cmCTest::RunMakeCommand(const char* command, std::string* output, //---------------------------------------------------------------------- int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *retVal, - std::ostream* log, double testTimeOut) + std::ostream* log, double testTimeOut, + std::vector<std::string>* environment) { + std::vector<std::string> origEnv; + bool modifyEnv = (environment && environment->size()>0); + // determine how much time we have double timeout = this->GetRemainingTimeAllowed() - 120; if (this->TimeOut && this->TimeOut < timeout) @@ -1156,6 +1160,11 @@ int cmCTest::RunTest(std::vector<const char*> argv, } std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory(); + if (modifyEnv) + { + origEnv = cmSystemTools::AppendEnv(environment); + } + *retVal = inst.Run(args, output); if ( *log ) { @@ -1166,6 +1175,12 @@ int cmCTest::RunTest(std::vector<const char*> argv, cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Internal cmCTest object used to run test." << std::endl << *output << std::endl); + + if (modifyEnv) + { + cmSystemTools::RestoreEnv(origEnv); + } + return cmsysProcess_State_Exited; } std::vector<char> tempOutput; @@ -1174,6 +1189,11 @@ int cmCTest::RunTest(std::vector<const char*> argv, *output = ""; } + if (modifyEnv) + { + origEnv = cmSystemTools::AppendEnv(environment); + } + cmsysProcess* cp = cmsysProcess_New(); cmsysProcess_SetCommand(cp, &*argv.begin()); cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl); @@ -1233,6 +1253,11 @@ int cmCTest::RunTest(std::vector<const char*> argv, } cmsysProcess_Delete(cp); + if (modifyEnv) + { + cmSystemTools::RestoreEnv(origEnv); + } + return result; } |