diff options
author | Brad King <brad.king@kitware.com> | 2021-10-27 13:20:30 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-10-27 13:20:45 (GMT) |
commit | 964af18dc11a2272ceb11bd7a7205ca72a6e4c21 (patch) | |
tree | df1cdbb0276cfe2d3da938c935b0483d6d809146 | |
parent | 550c25981957d4f387705dacba406ea38ffd1023 (diff) | |
parent | 69f95cf1d93945ace09ee9a87c0185b1ee6e4a47 (diff) | |
download | CMake-964af18dc11a2272ceb11bd7a7205ca72a6e4c21.zip CMake-964af18dc11a2272ceb11bd7a7205ca72a6e4c21.tar.gz CMake-964af18dc11a2272ceb11bd7a7205ca72a6e4c21.tar.bz2 |
Merge topic 'envmod-support-mod-to-new-variables' into release-3.22
69f95cf1d9 cmCTestRunTest: fix modifying non-existent envvars
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !6663
-rw-r--r-- | Source/CTest/cmCTestRunTest.cxx | 8 | ||||
-rw-r--r-- | Tests/Environment/CMakeLists.txt | 18 | ||||
-rw-r--r-- | Tests/Environment/check_mod.cmake | 8 |
3 files changed, 27 insertions, 7 deletions
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 20f0ed3..2d1562a 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -800,13 +800,9 @@ bool cmCTestRunTest::ForkProcess( auto apply_diff = [&env_application](const std::string& name, std::function<void(std::string&)> const& apply) { - auto entry = env_application.find(name); - std::string output; - if (entry != env_application.end() && entry->second) { - output = *entry->second; - } + std::string output = env_application[name].value_or(std::string{}); apply(output); - entry->second = output; + env_application[name] = output; }; bool err_occurred = false; diff --git a/Tests/Environment/CMakeLists.txt b/Tests/Environment/CMakeLists.txt index 17009bd..5f1edbf 100644 --- a/Tests/Environment/CMakeLists.txt +++ b/Tests/Environment/CMakeLists.txt @@ -45,6 +45,12 @@ set_property(TEST EchoEnvironment3 "STRING_MANIP=string_append:suffix" "STRING_MANIP=string_prepend:prefix" + # String manipulation on non-existent. + "STRING_DNE=string_append:post-" + "STRING_DNE=string_prepend:-pre" + "STRING_DNE=string_append:suffix" + "STRING_DNE=string_prepend:prefix" + # Path manipulation. "PATH_MANIP=set:core" "PATH_MANIP=path_list_append:post" @@ -52,10 +58,22 @@ set_property(TEST EchoEnvironment3 "PATH_MANIP=path_list_append:suffix" "PATH_MANIP=path_list_prepend:prefix" + # Path manipulation on non-existent. + "PATH_DNE=path_list_append:post" + "PATH_DNE=path_list_prepend:pre" + "PATH_DNE=path_list_append:suffix" + "PATH_DNE=path_list_prepend:prefix" + # CMake list manipulation. "CMAKE_LIST_MANIP=set:core" "CMAKE_LIST_MANIP=cmake_list_append:post" "CMAKE_LIST_MANIP=cmake_list_prepend:pre" "CMAKE_LIST_MANIP=cmake_list_append:suffix" "CMAKE_LIST_MANIP=cmake_list_prepend:prefix" + + # CMake list manipulation on non-existent. + "CMAKE_LIST_DNE=cmake_list_append:post" + "CMAKE_LIST_DNE=cmake_list_prepend:pre" + "CMAKE_LIST_DNE=cmake_list_append:suffix" + "CMAKE_LIST_DNE=cmake_list_prepend:prefix" ) diff --git a/Tests/Environment/check_mod.cmake b/Tests/Environment/check_mod.cmake index 16d02f2..179bd7a 100644 --- a/Tests/Environment/check_mod.cmake +++ b/Tests/Environment/check_mod.cmake @@ -20,12 +20,18 @@ set(expect_DIRECT "new") set(expect_STRING_MANIP "prefix-pre-core-post-suffix") set(expect_PATH_MANIP "prefix${path_sep}pre${path_sep}core${path_sep}post${path_sep}suffix") set(expect_CMAKE_LIST_MANIP "prefix;pre;core;post;suffix") +set(expect_STRING_DNE "prefix-prepost-suffix") +set(expect_PATH_DNE "prefix${path_sep}pre${path_sep}post${path_sep}suffix") +set(expect_CMAKE_LIST_DNE "prefix;pre;post;suffix") set(expected_vars DIRECT STRING_MANIP PATH_MANIP - CMAKE_LIST_MANIP) + CMAKE_LIST_MANIP + STRING_DNE + PATH_DNE + CMAKE_LIST_DNE) while (out) string(FIND "${out}" "\n" nl_pos) |