diff options
author | Brad King <brad.king@kitware.com> | 2021-07-13 12:24:28 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-07-13 12:24:36 (GMT) |
commit | 3265fa51cd4feec492a157506fff505dbd4c7d37 (patch) | |
tree | 1a734924e446176ca42aaa69e6000c3c584af5c0 /Tests | |
parent | 95c97a12e8c8498f3ed7142e3644a8b6a7eeb9e1 (diff) | |
parent | de4f1f26b0a3217f7caf842c50857b1ac90d9b7d (diff) | |
download | CMake-3265fa51cd4feec492a157506fff505dbd4c7d37.zip CMake-3265fa51cd4feec492a157506fff505dbd4c7d37.tar.gz CMake-3265fa51cd4feec492a157506fff505dbd4c7d37.tar.bz2 |
Merge topic 'ctest-environment-modifications'
de4f1f26b0 CTest: add an ENVIRONMENT_MODIFICATION property
4c757fa3c8 Help/prop_test/ENVIRONMENT: clarify the scope of the changes
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6299
Diffstat (limited to 'Tests')
15 files changed, 146 insertions, 0 deletions
diff --git a/Tests/Environment/CMakeLists.txt b/Tests/Environment/CMakeLists.txt index 2b18d24..17009bd 100644 --- a/Tests/Environment/CMakeLists.txt +++ b/Tests/Environment/CMakeLists.txt @@ -9,6 +9,7 @@ add_test(Environment1 Environment) add_test(Environment2 Environment) add_test(EchoEnvironment1 ${CMAKE_COMMAND} -E environment) add_test(EchoEnvironment2 ${CMAKE_COMMAND} -E environment) +add_test(EchoEnvironment3 ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/check_mod.cmake") # Make sure "CMAKE_ENV.*Happy Thanksgiving" is in the output of # the "1" tests: @@ -24,3 +25,37 @@ set_tests_properties(Environment1 EchoEnvironment1 PROPERTIES set_tests_properties(Environment2 EchoEnvironment2 PROPERTIES FAIL_REGULAR_EXPRESSION "CMAKE_ENV.*Happy Thanksgiving" ) + +set_property(TEST EchoEnvironment3 + PROPERTY ENVIRONMENT_MODIFICATION + # Variables expected to be unset. + "UNSET_EXPLICIT=set:value" + "UNSET_EXPLICIT=unset:" + "UNSET_VIA_RESET=set:value" + "UNSET_VIA_RESET=reset:" + + # Direct settings. + "DIRECT=set:old" + "DIRECT=set:new" + + # String manipulation. + "STRING_MANIP=set:-core-" + "STRING_MANIP=string_append:post-" + "STRING_MANIP=string_prepend:-pre" + "STRING_MANIP=string_append:suffix" + "STRING_MANIP=string_prepend:prefix" + + # Path manipulation. + "PATH_MANIP=set:core" + "PATH_MANIP=path_list_append:post" + "PATH_MANIP=path_list_prepend:pre" + "PATH_MANIP=path_list_append:suffix" + "PATH_MANIP=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" +) diff --git a/Tests/Environment/check_mod.cmake b/Tests/Environment/check_mod.cmake new file mode 100644 index 0000000..16d02f2 --- /dev/null +++ b/Tests/Environment/check_mod.cmake @@ -0,0 +1,55 @@ +execute_process( + COMMAND ${CMAKE_COMMAND} -E environment + OUTPUT_VARIABLE out + ERROR_VARIABLE err + RESULT_VARIABLE res) + +if (res) + message(FATAL_ERROR "Failed with exit code ${res}: ${err}") +endif () + +if (CMAKE_HOST_WIN32) + set(path_sep ";") +else () + set(path_sep ":") +endif () + +set(unexpect_UNSET_EXPLICIT "") +set(unexpect_UNSET_VIA_RESET "") +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(expected_vars + DIRECT + STRING_MANIP + PATH_MANIP + CMAKE_LIST_MANIP) + +while (out) + string(FIND "${out}" "\n" nl_pos) + string(SUBSTRING "${out}" 0 "${nl_pos}" line) + math(EXPR line_next "${nl_pos} + 1") + string(SUBSTRING "${out}" "${line_next}" -1 out) + + string(FIND "${line}" "=" eq_pos) + string(SUBSTRING "${line}" 0 "${eq_pos}" name) + math(EXPR value_start "${eq_pos} + 1") + string(SUBSTRING "${line}" "${value_start}" -1 value) + + if (DEFINED "unexpect_${name}") + message(SEND_ERROR "Found `${name}=${value}` when it should have been unset") + elseif (DEFINED "expect_${name}") + list(REMOVE_ITEM expected_vars "${name}") + if (expect_${name} STREQUAL value) + message(STATUS "Found `${name}=${value}` as expected") + else () + message(SEND_ERROR "Found `${name}=${value}` when it should have been ${expect_${name}}") + endif () + endif () +endwhile () + +if (expected_vars) + message(SEND_ERROR "Did not test expected variables: ${expected_vars}") +endif () diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index da79e0e..ef797f7 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -374,6 +374,7 @@ add_RunCMake_test(ctest_disabled_test) add_RunCMake_test(ctest_skipped_test) add_RunCMake_test(ctest_update) add_RunCMake_test(ctest_upload) +add_RunCMake_test(ctest_environment) add_RunCMake_test(ctest_fixtures) add_RunCMake_test(file -DMSYS=${MSYS}) add_RunCMake_test(file-CHMOD -DMSYS=${MSYS}) diff --git a/Tests/RunCMake/ctest_environment/CMakeLists.txt.in b/Tests/RunCMake/ctest_environment/CMakeLists.txt.in new file mode 100644 index 0000000..c9c4a64 --- /dev/null +++ b/Tests/RunCMake/ctest_environment/CMakeLists.txt.in @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.21.0) +project("@CASE_NAME@" NONE) +include("@CASE_SOURCE_DIR@/@CASE_NAME@.cmake") diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op-result.txt b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op-result.txt new file mode 100644 index 0000000..b57e2de --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op-result.txt @@ -0,0 +1 @@ +(-1|255) diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op-stderr.txt b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op-stderr.txt new file mode 100644 index 0000000..5b56d6f --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op-stderr.txt @@ -0,0 +1 @@ +Error: Unrecognized environment manipulation argument: unknown diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op.cmake b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op.cmake new file mode 100644 index 0000000..d6ca4b2 --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-invalid-op.cmake @@ -0,0 +1,6 @@ +include(CTest) +add_test(NAME cmake_version COMMAND "${CMAKE_COMMAND}" --version) + +set_property(TEST cmake_version + PROPERTY ENVIRONMENT_MODIFICATION + INVALID_OP=unknown:) diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon-result.txt b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon-result.txt new file mode 100644 index 0000000..b57e2de --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon-result.txt @@ -0,0 +1 @@ +(-1|255) diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon-stderr.txt b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon-stderr.txt new file mode 100644 index 0000000..3ba6ba7 --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon-stderr.txt @@ -0,0 +1 @@ +Error: Missing `:` after the operation in: MISSING_COLON=unset diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon.cmake b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon.cmake new file mode 100644 index 0000000..601dd8b --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-colon.cmake @@ -0,0 +1,6 @@ +include(CTest) + +add_test(NAME cmake_version COMMAND "${CMAKE_COMMAND}" --version) +set_property(TEST cmake_version + PROPERTY ENVIRONMENT_MODIFICATION + MISSING_COLON=unset) diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals-result.txt b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals-result.txt new file mode 100644 index 0000000..b57e2de --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals-result.txt @@ -0,0 +1 @@ +(-1|255) diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals-stderr.txt b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals-stderr.txt new file mode 100644 index 0000000..20bc9a5 --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals-stderr.txt @@ -0,0 +1 @@ +Error: Missing `=` after the variable name in: MISSING_EQUAL diff --git a/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals.cmake b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals.cmake new file mode 100644 index 0000000..18448cf --- /dev/null +++ b/Tests/RunCMake/ctest_environment/ENVIRONMENT_MODIFICATION-no-equals.cmake @@ -0,0 +1,6 @@ +include(CTest) + +add_test(NAME cmake_version COMMAND "${CMAKE_COMMAND}" --version) +set_property(TEST cmake_version + PROPERTY ENVIRONMENT_MODIFICATION + MISSING_EQUAL) diff --git a/Tests/RunCMake/ctest_environment/RunCMakeTest.cmake b/Tests/RunCMake/ctest_environment/RunCMakeTest.cmake new file mode 100644 index 0000000..3447779 --- /dev/null +++ b/Tests/RunCMake/ctest_environment/RunCMakeTest.cmake @@ -0,0 +1,12 @@ +include(RunCTest) + +# Isolate our ctest runs from external environment. +unset(ENV{CTEST_PARALLEL_LEVEL}) +unset(ENV{CTEST_OUTPUT_ON_FAILURE}) + +set(CASE_SOURCE_DIR "${RunCMake_SOURCE_DIR}") +set(RunCTest_VERBOSE_FLAG "-VV") + +run_ctest(ENVIRONMENT_MODIFICATION-invalid-op) +run_ctest(ENVIRONMENT_MODIFICATION-no-colon) +run_ctest(ENVIRONMENT_MODIFICATION-no-equals) diff --git a/Tests/RunCMake/ctest_environment/test.cmake.in b/Tests/RunCMake/ctest_environment/test.cmake.in new file mode 100644 index 0000000..ca23c83 --- /dev/null +++ b/Tests/RunCMake/ctest_environment/test.cmake.in @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.7) + +set(CTEST_SITE "test-site") +set(CTEST_BUILD_NAME "test-build-name") +set(CTEST_SOURCE_DIRECTORY "@RunCMake_BINARY_DIR@/@CASE_NAME@") +set(CTEST_BINARY_DIRECTORY "@RunCMake_BINARY_DIR@/@CASE_NAME@-build") +set(CTEST_CMAKE_GENERATOR "@RunCMake_GENERATOR@") +set(CTEST_CMAKE_GENERATOR_PLATFORM "@RunCMake_GENERATOR_PLATFORM@") +set(CTEST_CMAKE_GENERATOR_TOOLSET "@RunCMake_GENERATOR_TOOLSET@") +set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}") + +set(ctest_test_args "@CASE_CTEST_TEST_ARGS@") +ctest_start(Experimental) +ctest_configure() +ctest_build() +ctest_test(${ctest_test_args}) |