From 2c9680eec59fb52b4bf60b2b995101c86a906ca5 Mon Sep 17 00:00:00 2001 From: Ryan Thornton Date: Wed, 11 Mar 2020 14:18:32 -0500 Subject: GoogleTest: Add missing test case for gtest_discover_tests failure Discovery timeout test needs split out into two components: - build - test Building the project should result in a failure due to the timeout when executing gtest discovery as a post build step. Likewise, if you ran CTest after this build failure, we should *also* detect that the discovery_timeout_test has not been built because no discovery_timeout_test[1]_tests.cmake has been created due to the test discovery failure (caused by the timeout). --- .../GoogleTest-discovery-timeout-build-result.txt | 1 + .../GoogleTest-discovery-timeout-build-stdout.txt | 7 +++++++ .../GoogleTest/GoogleTest-discovery-timeout-result.txt | 1 - .../GoogleTest/GoogleTest-discovery-timeout-stdout.txt | 7 ------- .../GoogleTest-discovery-timeout-test-result.txt | 1 + .../GoogleTest-discovery-timeout-test-stderr.txt | 2 ++ .../GoogleTest-discovery-timeout-test-stdout.txt | 18 ++++++++++++++++++ Tests/RunCMake/GoogleTest/RunCMakeTest.cmake | 9 ++++++++- 8 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-build-result.txt create mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-build-stdout.txt delete mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-result.txt delete mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-stdout.txt create mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-result.txt create mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-stderr.txt create mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-stdout.txt diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-build-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-build-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-build-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-build-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-build-stdout.txt new file mode 100644 index 0000000..3a6572c --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-build-stdout.txt @@ -0,0 +1,7 @@ +( *|[0-9]+>)CMake Error at .*GoogleTestAddTests.cmake:[0-9]+ \(message\): +( *|[0-9]+>) Error running test executable. +?( *|[0-9]+>) +( *|[0-9]+>) Path: '.*discovery_timeout_test(\.exe)?' +( *|[0-9]+>) Result: Process terminated due to timeout +( *|[0-9]+>) Output: +( *|[0-9]+>) + diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-result.txt deleted file mode 100644 index d197c91..0000000 --- a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-result.txt +++ /dev/null @@ -1 +0,0 @@ -[^0] diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-stdout.txt deleted file mode 100644 index 3a6572c..0000000 --- a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-stdout.txt +++ /dev/null @@ -1,7 +0,0 @@ -( *|[0-9]+>)CMake Error at .*GoogleTestAddTests.cmake:[0-9]+ \(message\): -( *|[0-9]+>) Error running test executable. -?( *|[0-9]+>) -( *|[0-9]+>) Path: '.*discovery_timeout_test(\.exe)?' -( *|[0-9]+>) Result: Process terminated due to timeout -( *|[0-9]+>) Output: -( *|[0-9]+>) + diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-stderr.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-stderr.txt new file mode 100644 index 0000000..f6be939 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-stderr.txt @@ -0,0 +1,2 @@ +Unable to find executable: discovery_timeout_test_NOT_BUILT +Errors while running CTest diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-stdout.txt new file mode 100644 index 0000000..d4c4e7b --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-timeout-test-stdout.txt @@ -0,0 +1,18 @@ +Test project .*GoogleTest-build +[ \t]*Start [0-9]+: discovery_timeout_test_NOT_BUILT +Could not find executable discovery_timeout_test_NOT_BUILT +Looked in the following places: +discovery_timeout_test_NOT_BUILT +discovery_timeout_test_NOT_BUILT(\.exe)? +Debug/discovery_timeout_test_NOT_BUILT +Debug/discovery_timeout_test_NOT_BUILT(\.exe)? +Debug/discovery_timeout_test_NOT_BUILT +Debug/discovery_timeout_test_NOT_BUILT(\.exe)? +[^\n]+discovery_timeout_test_NOT_BUILT +\.+\*\*\*Not Run +[0-9.]+ sec ++ +0% tests passed, 1 tests failed out of 1 ++ +Total Test time \(real\) = +[0-9.]+ sec ++ +The following tests FAILED: +[^\n]+discovery_timeout_test_NOT_BUILT \(Not Run\) diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake index 0fa4e2a..8c6b507 100644 --- a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake @@ -27,7 +27,7 @@ function(run_GoogleTest) ) set(RunCMake_TEST_OUTPUT_MERGE 1) - run_cmake_command(GoogleTest-discovery-timeout + run_cmake_command(GoogleTest-discovery-timeout-build ${CMAKE_COMMAND} --build . --config Debug @@ -69,6 +69,13 @@ function(run_GoogleTest) -R property_timeout\\.case_with_discovery --no-label-summary ) + + run_cmake_command(GoogleTest-discovery-timeout-test + ${CMAKE_CTEST_COMMAND} + -C Debug + -R discovery_timeout_test + --no-label-summary + ) endfunction() run_GoogleTest() -- cgit v0.12 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