diff options
author | Ryan Thornton <ThorntonRyan@JohnDeere.com> | 2020-03-11 18:34:06 (GMT) |
---|---|---|
committer | Ryan Thornton <ThorntonRyan@JohnDeere.com> | 2020-03-11 20:11:00 (GMT) |
commit | 2ba8ac07ed50b11946c52c37ddab4f65536d36ea (patch) | |
tree | 114d4ed1e212e4ec0079612ea3500e94893bdbb6 /Modules | |
parent | 2c9680eec59fb52b4bf60b2b995101c86a906ca5 (diff) | |
download | CMake-2ba8ac07ed50b11946c52c37ddab4f65536d36ea.zip CMake-2ba8ac07ed50b11946c52c37ddab4f65536d36ea.tar.gz CMake-2ba8ac07ed50b11946c52c37ddab4f65536d36ea.tar.bz2 |
GoogleTest: Fix CTest not failing if gtest_discover_tests fails
Fixes regression introduced dac201442d (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 in dac201442d, 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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/GoogleTestAddTests.cmake | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake index 4f52ad2..73e55ea 100644 --- a/Modules/GoogleTestAddTests.cmake +++ b/Modules/GoogleTestAddTests.cmake @@ -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() |