From 2ba8ac07ed50b11946c52c37ddab4f65536d36ea Mon Sep 17 00:00:00 2001 From: Ryan Thornton Date: Wed, 11 Mar 2020 13:34:06 -0500 Subject: 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. --- Modules/GoogleTestAddTests.cmake | 6 ++++-- 1 file 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() -- cgit v0.12