diff options
Diffstat (limited to 'Modules/GoogleTestAddTests.cmake')
-rw-r--r-- | Modules/GoogleTestAddTests.cmake | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake index 4abbbec..753319f 100644 --- a/Modules/GoogleTestAddTests.cmake +++ b/Modules/GoogleTestAddTests.cmake @@ -1,6 +1,8 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. +cmake_minimum_required(VERSION ${CMAKE_VERSION}) + set(prefix "${TEST_PREFIX}") set(suffix "${TEST_SUFFIX}") set(extra_args ${TEST_EXTRA_ARGS}) @@ -8,18 +10,43 @@ set(properties ${TEST_PROPERTIES}) set(script) set(suite) set(tests) +set(tests_buffer) + +# Overwrite possibly existing ${CTEST_FILE} with empty file +set(flush_tests_MODE WRITE) + +# Flushes script to ${CTEST_FILE} +macro(flush_script) + file(${flush_tests_MODE} "${CTEST_FILE}" "${script}") + set(flush_tests_MODE APPEND) + + set(script "") +endmacro() + +# Flushes tests_buffer to tests +macro(flush_tests_buffer) + list(APPEND tests "${tests_buffer}") + set(tests_buffer "") +endmacro() -function(add_command NAME) +macro(add_command NAME) set(_args "") foreach(_arg ${ARGN}) if(_arg MATCHES "[^-./:a-zA-Z0-9_]") - set(_args "${_args} [==[${_arg}]==]") + string(APPEND _args " [==[${_arg}]==]") else() - set(_args "${_args} ${_arg}") + string(APPEND _args " ${_arg}") endif() endforeach() - set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) -endfunction() + string(APPEND script "${NAME}(${_args})\n") + string(LENGTH "${script}" _script_len) + if(${_script_len} GREATER "50000") + flush_script() + endif() + # Unsets macro local variables to prevent leakage outside of this macro. + unset(_args) + unset(_script_len) +endmacro() # Run test executable to get list of available tests if(NOT EXISTS "${TEST_EXECUTABLE}") @@ -72,6 +99,11 @@ foreach(line ${output}) endif() string(REGEX REPLACE "^DISABLED_" "" pretty_test "${pretty_test}") string(REGEX REPLACE "#.*" "" test "${test}") + if(NOT TEST_XML_OUTPUT_DIR STREQUAL "") + set(TEST_XML_OUTPUT_PARAM "--gtest_output=xml:${TEST_XML_OUTPUT_DIR}/${prefix}${pretty_suite}.${pretty_test}${suffix}.xml") + else() + unset(TEST_XML_OUTPUT_PARAM) + endif() # ...and add to script add_command(add_test "${prefix}${pretty_suite}.${pretty_test}${suffix}" @@ -79,6 +111,7 @@ foreach(line ${output}) "${TEST_EXECUTABLE}" "--gtest_filter=${suite}.${test}" "--gtest_also_run_disabled_tests" + ${TEST_XML_OUTPUT_PARAM} ${extra_args} ) if(suite MATCHES "^DISABLED" OR test MATCHES "^DISABLED") @@ -93,14 +126,20 @@ foreach(line ${output}) WORKING_DIRECTORY "${TEST_WORKING_DIR}" ${properties} ) - list(APPEND tests "${prefix}${pretty_suite}.${pretty_test}${suffix}") + list(APPEND tests_buffer "${prefix}${pretty_suite}.${pretty_test}${suffix}") + list(LENGTH tests_buffer tests_buffer_length) + if(${tests_buffer_length} GREATER "250") + flush_tests_buffer() + endif() endif() endif() endforeach() + # Create a list of all discovered tests, which users may use to e.g. set # properties on the tests +flush_tests_buffer() add_command(set ${TEST_LIST} ${tests}) # Write CTest script -file(WRITE "${CTEST_FILE}" "${script}") +flush_script() |