mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 10:50:16 -06:00
GoogleTest: Fix CTest not failing if gtest_discover_tests fails
Fixes regression introduceddac201442d(GoogleTest: Optimize gtest_discover_tests, 2020-02-18). The generated CTest include files has the form: if(EXISTS "foo_tests.cmake") include("foo_tests.cmake") else() add_test(foo_NOT_BUILT foo_test_NOT_BUILT) endif() Starting indac201442d, an empty discovery_timeout_test[1]_tests.cmake was written as soon as GoogleTestAddTests was processed. This meant, that even if test discovery would fail (due to a crash or timeout in the executable), we would always produce an empty CTest file. So instead of reporting: Unable to find executable: foo_NOT_BUILT Errors while running CTest We instead get: No tests were found!!! To fix the problem, we WRITE the file on the first call to flush_script, thus creating the file once we know we have valid output and the call to gtest_discover_tests hasn't failed. After creating the file, we then set the mode to APPEND and append to the file for every subsequent call.
This commit is contained in:
@@ -13,11 +13,13 @@ set(tests)
|
||||
set(tests_buffer)
|
||||
|
||||
# Overwrite possibly existing ${CTEST_FILE} with empty file
|
||||
file(WRITE "${CTEST_FILE}" "")
|
||||
set(flush_tests_MODE WRITE)
|
||||
|
||||
# Flushes script to ${CTEST_FILE}
|
||||
macro(flush_script)
|
||||
file(APPEND "${CTEST_FILE}" "${script}")
|
||||
file(${flush_tests_MODE} "${CTEST_FILE}" "${script}")
|
||||
set(flush_tests_MODE APPEND)
|
||||
|
||||
set(script "")
|
||||
endmacro()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user