diff options
author | Brad King <brad.king@kitware.com> | 2021-11-01 13:07:39 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-11-01 13:08:11 (GMT) |
commit | 4c68a0e71a9fcc2d836173b253c4abea36cb68b5 (patch) | |
tree | 0fc2dfed71e8c40c4598b71ea3537feb27f4161a /Source/CTest | |
parent | 562ee8a50bf291300007ad8d14fdc977ef3a3371 (diff) | |
parent | 9c4d6404eb4ac0016d2d107d8c24c8097d4e2359 (diff) | |
download | CMake-4c68a0e71a9fcc2d836173b253c4abea36cb68b5.zip CMake-4c68a0e71a9fcc2d836173b253c4abea36cb68b5.tar.gz CMake-4c68a0e71a9fcc2d836173b253c4abea36cb68b5.tar.bz2 |
Merge topic 'envmod-test-modifying-existing'
9c4d6404eb Tests/Environment: also test modifying ambient values
7d52d48a32 cmCTestRunTest: get the default value from the environment
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6682
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestRunTest.cxx | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index f76fc3e..6cd3b09 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -784,6 +784,9 @@ bool cmCTestRunTest::ForkProcess( std::ostringstream envMeasurement; if (environment && !environment->empty()) { + // Environment modification works on the assumption that the environment is + // actually modified here. If another strategy is used, there will need to + // be updates below in `apply_diff`. cmSystemTools::AppendEnv(*environment); for (auto const& var : *environment) { envMeasurement << var << std::endl; @@ -802,7 +805,20 @@ bool cmCTestRunTest::ForkProcess( auto apply_diff = [&env_application](const std::string& name, std::function<void(std::string&)> const& apply) { - std::string output = env_application[name].value_or(std::string{}); + cm::optional<std::string> old_value = env_application[name]; + std::string output; + if (old_value) { + output = *old_value; + } else { + // This only works because the environment is actually modified above + // (`AppendEnv`). If CTest ever just creates an environment block + // directly, that block will need to be queried for the subprocess' + // value instead. + const char* curval = cmSystemTools::GetEnv(name); + if (curval) { + output = curval; + } + } apply(output); env_application[name] = output; }; |