diff options
author | Moritz Haase <Moritz.Haase@bmw.de> | 2023-12-05 13:09:37 (GMT) |
---|---|---|
committer | Moritz Haase <Moritz.Haase@bmw.de> | 2023-12-06 11:52:18 (GMT) |
commit | 0767016eabf17ab124ae7b454b9ca910dcc17c56 (patch) | |
tree | c0b5e3115f618691206235468a18407d7017884d /Modules | |
parent | 98cbe249189463a9f31ba3b3bdd37dfd0710753d (diff) | |
download | CMake-0767016eabf17ab124ae7b454b9ca910dcc17c56.zip CMake-0767016eabf17ab124ae7b454b9ca910dcc17c56.tar.gz CMake-0767016eabf17ab124ae7b454b9ca910dcc17c56.tar.bz2 |
GoogleTest: Avoid silent failures of dynamic test discovery
The internal helper variable '_GOOGLETEST_DISCOVER_TESTS_SCRIPT' can have gone
out-of-scope when 'gtest_discover_tests()' is called, depending on where the
GoogleTest module is actually included. This leads to a silent failure of
dynamic test discovery, since the custom post-build commands actually does
nothing (it basically invokes 'cmake -P ""'). Ctest will then fail to run the
tests, considering them to be 'not built'.
Fix this by determining the path to the GoogleTest module based on
'${CMAKE_ROOT}' instead, which is always available.
A new test case was added to test suite 'RunCMake/GoogleTest' to ensure that
'gtest_discover_tests()' works correctly when invoked in a different variable
scope.
Fixes: #25477
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/GoogleTest.cmake | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index 57a7476..3c12e14 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -500,7 +500,7 @@ function(gtest_discover_tests TARGET) -D "CTEST_FILE=${ctest_tests_file}" -D "TEST_DISCOVERY_TIMEOUT=${_DISCOVERY_TIMEOUT}" -D "TEST_XML_OUTPUT_DIR=${_XML_OUTPUT_DIR}" - -P "${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}" + -P "${CMAKE_ROOT}/Modules/GoogleTestAddTests.cmake" VERBATIM ) @@ -526,7 +526,7 @@ function(gtest_discover_tests TARGET) " if(NOT EXISTS \"${ctest_tests_file}\" OR" "\n" " NOT \"${ctest_tests_file}\" IS_NEWER_THAN \"$<TARGET_FILE:${TARGET}>\" OR\n" " NOT \"${ctest_tests_file}\" IS_NEWER_THAN \"\${CMAKE_CURRENT_LIST_FILE}\")\n" - " include(\"${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}\")" "\n" + " include(\"${CMAKE_ROOT}/Modules/GoogleTestAddTests.cmake\")" "\n" " gtest_discover_tests_impl(" "\n" " TEST_EXECUTABLE" " [==[" "$<TARGET_FILE:${TARGET}>" "]==]" "\n" " TEST_EXECUTOR" " [==[" "${crosscompiling_emulator}" "]==]" "\n" @@ -573,9 +573,5 @@ endfunction() ############################################################################### -set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT - ${CMAKE_CURRENT_LIST_DIR}/GoogleTestAddTests.cmake -) - # Restore project's policies cmake_policy(POP) |