mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-14 21:41:06 -05:00
GoogleTest: Improve internally used variable names
- Use an "arg" prefix for cmake_parse_arguments() rather than an empty string or uppercase ARGS so that usages of parsed values don't start with a bare underscore or look fully uppercase. This makes it harder to miss them or mistake them for keywords. - Use lowercase for names of positional function arguments so they don't get mistaken for keywords.
This commit is contained in:
@@ -314,35 +314,35 @@ function(gtest_add_tests)
|
|||||||
|
|
||||||
unset(sources)
|
unset(sources)
|
||||||
if("${ARGV0}" IN_LIST allKeywords)
|
if("${ARGV0}" IN_LIST allKeywords)
|
||||||
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
set(autoAddSources YES)
|
set(autoAddSources YES)
|
||||||
else()
|
else()
|
||||||
# Non-keyword syntax, convert to keyword form
|
# Non-keyword syntax, convert to keyword form
|
||||||
if (ARGC LESS 3)
|
if (ARGC LESS 3)
|
||||||
message(FATAL_ERROR "gtest_add_tests() without keyword options requires at least 3 arguments")
|
message(FATAL_ERROR "gtest_add_tests() without keyword options requires at least 3 arguments")
|
||||||
endif()
|
endif()
|
||||||
set(ARGS_TARGET "${ARGV0}")
|
set(arg_TARGET "${ARGV0}")
|
||||||
set(ARGS_EXTRA_ARGS "${ARGV1}")
|
set(arg_EXTRA_ARGS "${ARGV1}")
|
||||||
if(NOT "${ARGV2}" STREQUAL "AUTO")
|
if(NOT "${ARGV2}" STREQUAL "AUTO")
|
||||||
set(ARGS_SOURCES "${ARGV}")
|
set(arg_SOURCES "${ARGV}")
|
||||||
list(REMOVE_AT ARGS_SOURCES 0 1)
|
list(REMOVE_AT arg_SOURCES 0 1)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# The non-keyword syntax allows the first argument to be an arbitrary
|
# The non-keyword syntax allows the first argument to be an arbitrary
|
||||||
# executable rather than a target if source files are also provided. In all
|
# executable rather than a target if source files are also provided. In all
|
||||||
# other cases, both forms require a target.
|
# other cases, both forms require a target.
|
||||||
if(NOT TARGET "${ARGS_TARGET}" AND NOT ARGS_SOURCES)
|
if(NOT TARGET "${arg_TARGET}" AND NOT arg_SOURCES)
|
||||||
message(FATAL_ERROR "${ARGS_TARGET} does not define an existing CMake target")
|
message(FATAL_ERROR "${arg_TARGET} does not define an existing CMake target")
|
||||||
endif()
|
endif()
|
||||||
if(NOT ARGS_WORKING_DIRECTORY)
|
if(NOT arg_WORKING_DIRECTORY)
|
||||||
unset(workDir)
|
unset(workDir)
|
||||||
else()
|
else()
|
||||||
set(workDir WORKING_DIRECTORY "${ARGS_WORKING_DIRECTORY}")
|
set(workDir WORKING_DIRECTORY "${arg_WORKING_DIRECTORY}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT ARGS_SOURCES)
|
if(NOT arg_SOURCES)
|
||||||
get_property(ARGS_SOURCES TARGET ${ARGS_TARGET} PROPERTY SOURCES)
|
get_property(arg_SOURCES TARGET ${arg_TARGET} PROPERTY SOURCES)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
unset(testList)
|
unset(testList)
|
||||||
@@ -351,8 +351,8 @@ function(gtest_add_tests)
|
|||||||
set(gtest_test_type_regex "(TYPED_TEST|TEST)_?[FP]?")
|
set(gtest_test_type_regex "(TYPED_TEST|TEST)_?[FP]?")
|
||||||
set(each_line_regex "([^\r\n]*[\r\n])")
|
set(each_line_regex "([^\r\n]*[\r\n])")
|
||||||
|
|
||||||
foreach(source IN LISTS ARGS_SOURCES)
|
foreach(source IN LISTS arg_SOURCES)
|
||||||
if(NOT ARGS_SKIP_DEPENDENCY)
|
if(NOT arg_SKIP_DEPENDENCY)
|
||||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${source})
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${source})
|
||||||
endif()
|
endif()
|
||||||
file(READ "${source}" contents)
|
file(READ "${source}" contents)
|
||||||
@@ -420,26 +420,26 @@ function(gtest_add_tests)
|
|||||||
orig_test_name "${gtest_test_name}"
|
orig_test_name "${gtest_test_name}"
|
||||||
)
|
)
|
||||||
set(ctest_test_name
|
set(ctest_test_name
|
||||||
${ARGS_TEST_PREFIX}${orig_test_name}${ARGS_TEST_SUFFIX}
|
${arg_TEST_PREFIX}${orig_test_name}${arg_TEST_SUFFIX}
|
||||||
)
|
)
|
||||||
add_test(NAME ${ctest_test_name}
|
add_test(NAME ${ctest_test_name}
|
||||||
${workDir}
|
${workDir}
|
||||||
COMMAND ${ARGS_TARGET}
|
COMMAND ${arg_TARGET}
|
||||||
--gtest_also_run_disabled_tests
|
--gtest_also_run_disabled_tests
|
||||||
--gtest_filter=${gtest_test_name}
|
--gtest_filter=${gtest_test_name}
|
||||||
${ARGS_EXTRA_ARGS}
|
${arg_EXTRA_ARGS}
|
||||||
)
|
)
|
||||||
set_tests_properties(${ctest_test_name} PROPERTIES DISABLED TRUE
|
set_tests_properties(${ctest_test_name} PROPERTIES DISABLED TRUE
|
||||||
DEF_SOURCE_LINE "${source}:${accumulate_line}")
|
DEF_SOURCE_LINE "${source}:${accumulate_line}")
|
||||||
list(APPEND testList ${ctest_test_name})
|
list(APPEND testList ${ctest_test_name})
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
set(ctest_test_name ${ARGS_TEST_PREFIX}${gtest_test_name}${ARGS_TEST_SUFFIX})
|
set(ctest_test_name ${arg_TEST_PREFIX}${gtest_test_name}${arg_TEST_SUFFIX})
|
||||||
add_test(NAME ${ctest_test_name}
|
add_test(NAME ${ctest_test_name}
|
||||||
${workDir}
|
${workDir}
|
||||||
COMMAND ${ARGS_TARGET}
|
COMMAND ${arg_TARGET}
|
||||||
--gtest_filter=${gtest_test_name}
|
--gtest_filter=${gtest_test_name}
|
||||||
${ARGS_EXTRA_ARGS}
|
${arg_EXTRA_ARGS}
|
||||||
)
|
)
|
||||||
# Makes sure a skipped GTest is reported as so by CTest
|
# Makes sure a skipped GTest is reported as so by CTest
|
||||||
set_tests_properties(
|
set_tests_properties(
|
||||||
@@ -453,49 +453,64 @@ function(gtest_add_tests)
|
|||||||
endforeach()
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if(ARGS_TEST_LIST)
|
if(arg_TEST_LIST)
|
||||||
set(${ARGS_TEST_LIST} ${testList} PARENT_SCOPE)
|
set(${arg_TEST_LIST} ${testList} PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
function(gtest_discover_tests TARGET)
|
function(gtest_discover_tests target)
|
||||||
cmake_parse_arguments(
|
set(options
|
||||||
""
|
NO_PRETTY_TYPES
|
||||||
"NO_PRETTY_TYPES;NO_PRETTY_VALUES"
|
NO_PRETTY_VALUES
|
||||||
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;DISCOVERY_TIMEOUT;XML_OUTPUT_DIR;DISCOVERY_MODE"
|
)
|
||||||
"EXTRA_ARGS;PROPERTIES;TEST_FILTER"
|
set(oneValueArgs
|
||||||
|
TEST_PREFIX
|
||||||
|
TEST_SUFFIX
|
||||||
|
WORKING_DIRECTORY
|
||||||
|
TEST_LIST
|
||||||
|
DISCOVERY_TIMEOUT
|
||||||
|
XML_OUTPUT_DIR
|
||||||
|
DISCOVERY_MODE
|
||||||
|
)
|
||||||
|
set(multiValueArgs
|
||||||
|
EXTRA_ARGS
|
||||||
|
PROPERTIES
|
||||||
|
TEST_FILTER
|
||||||
|
)
|
||||||
|
cmake_parse_arguments(arg
|
||||||
|
"${options}" "${oneValueArgs}" "${multiValueArgs}"
|
||||||
${ARGN}
|
${ARGN}
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT _WORKING_DIRECTORY)
|
if(NOT arg_WORKING_DIRECTORY)
|
||||||
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
set(arg_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
endif()
|
endif()
|
||||||
if(NOT _TEST_LIST)
|
if(NOT arg_TEST_LIST)
|
||||||
set(_TEST_LIST ${TARGET}_TESTS)
|
set(arg_TEST_LIST ${target}_TESTS)
|
||||||
endif()
|
endif()
|
||||||
if(NOT _DISCOVERY_TIMEOUT)
|
if(NOT arg_DISCOVERY_TIMEOUT)
|
||||||
set(_DISCOVERY_TIMEOUT 5)
|
set(arg_DISCOVERY_TIMEOUT 5)
|
||||||
endif()
|
endif()
|
||||||
if(NOT _DISCOVERY_MODE)
|
if(NOT arg_DISCOVERY_MODE)
|
||||||
if(NOT CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE)
|
if(NOT CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE)
|
||||||
set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE "POST_BUILD")
|
set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE "POST_BUILD")
|
||||||
endif()
|
endif()
|
||||||
set(_DISCOVERY_MODE ${CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE})
|
set(arg_DISCOVERY_MODE ${CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
get_property(
|
get_property(
|
||||||
has_counter
|
has_counter
|
||||||
TARGET ${TARGET}
|
TARGET ${target}
|
||||||
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
|
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
|
||||||
SET
|
SET
|
||||||
)
|
)
|
||||||
if(has_counter)
|
if(has_counter)
|
||||||
get_property(
|
get_property(
|
||||||
counter
|
counter
|
||||||
TARGET ${TARGET}
|
TARGET ${target}
|
||||||
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
|
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
|
||||||
)
|
)
|
||||||
math(EXPR counter "${counter} + 1")
|
math(EXPR counter "${counter} + 1")
|
||||||
@@ -503,17 +518,17 @@ function(gtest_discover_tests TARGET)
|
|||||||
set(counter 1)
|
set(counter 1)
|
||||||
endif()
|
endif()
|
||||||
set_property(
|
set_property(
|
||||||
TARGET ${TARGET}
|
TARGET ${target}
|
||||||
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
|
PROPERTY CTEST_DISCOVERED_TEST_COUNTER
|
||||||
${counter}
|
${counter}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Define rule to generate test list for aforementioned test executable
|
# Define rule to generate test list for aforementioned test executable
|
||||||
set(ctest_file_base "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}[${counter}]")
|
set(ctest_file_base "${CMAKE_CURRENT_BINARY_DIR}/${target}[${counter}]")
|
||||||
set(ctest_include_file "${ctest_file_base}_include.cmake")
|
set(ctest_include_file "${ctest_file_base}_include.cmake")
|
||||||
set(ctest_tests_file "${ctest_file_base}_tests.cmake")
|
set(ctest_tests_file "${ctest_file_base}_tests.cmake")
|
||||||
get_property(test_launcher
|
get_property(test_launcher
|
||||||
TARGET ${TARGET}
|
TARGET ${target}
|
||||||
PROPERTY TEST_LAUNCHER
|
PROPERTY TEST_LAUNCHER
|
||||||
)
|
)
|
||||||
cmake_policy(GET CMP0158 _CMP0158
|
cmake_policy(GET CMP0158 _CMP0158
|
||||||
@@ -521,7 +536,7 @@ function(gtest_discover_tests TARGET)
|
|||||||
)
|
)
|
||||||
if(NOT _CMP0158 OR _CMP0158 STREQUAL "OLD" OR _CMP0158 STREQUAL "NEW" AND CMAKE_CROSSCOMPILING)
|
if(NOT _CMP0158 OR _CMP0158 STREQUAL "OLD" OR _CMP0158 STREQUAL "NEW" AND CMAKE_CROSSCOMPILING)
|
||||||
get_property(crosscompiling_emulator
|
get_property(crosscompiling_emulator
|
||||||
TARGET ${TARGET}
|
TARGET ${target}
|
||||||
PROPERTY CROSSCOMPILING_EMULATOR
|
PROPERTY CROSSCOMPILING_EMULATOR
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
@@ -536,26 +551,26 @@ function(gtest_discover_tests TARGET)
|
|||||||
set(test_executor "")
|
set(test_executor "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(_DISCOVERY_MODE STREQUAL "POST_BUILD")
|
if(arg_DISCOVERY_MODE STREQUAL "POST_BUILD")
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET ${TARGET} POST_BUILD
|
TARGET ${target} POST_BUILD
|
||||||
BYPRODUCTS "${ctest_tests_file}"
|
BYPRODUCTS "${ctest_tests_file}"
|
||||||
COMMAND "${CMAKE_COMMAND}"
|
COMMAND "${CMAKE_COMMAND}"
|
||||||
-D "TEST_TARGET=${TARGET}"
|
-D "TEST_TARGET=${target}"
|
||||||
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
|
-D "TEST_EXECUTABLE=$<TARGET_FILE:${target}>"
|
||||||
-D "TEST_EXECUTOR=${test_executor}"
|
-D "TEST_EXECUTOR=${test_executor}"
|
||||||
-D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
|
-D "TEST_WORKING_DIR=${arg_WORKING_DIRECTORY}"
|
||||||
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
|
-D "TEST_EXTRA_ARGS=${arg_EXTRA_ARGS}"
|
||||||
-D "TEST_PROPERTIES=${_PROPERTIES}"
|
-D "TEST_PROPERTIES=${arg_PROPERTIES}"
|
||||||
-D "TEST_PREFIX=${_TEST_PREFIX}"
|
-D "TEST_PREFIX=${arg_TEST_PREFIX}"
|
||||||
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
|
-D "TEST_SUFFIX=${arg_TEST_SUFFIX}"
|
||||||
-D "TEST_FILTER=${_TEST_FILTER}"
|
-D "TEST_FILTER=${arg_TEST_FILTER}"
|
||||||
-D "NO_PRETTY_TYPES=${_NO_PRETTY_TYPES}"
|
-D "NO_PRETTY_TYPES=${arg_NO_PRETTY_TYPES}"
|
||||||
-D "NO_PRETTY_VALUES=${_NO_PRETTY_VALUES}"
|
-D "NO_PRETTY_VALUES=${arg_NO_PRETTY_VALUES}"
|
||||||
-D "TEST_LIST=${_TEST_LIST}"
|
-D "TEST_LIST=${arg_TEST_LIST}"
|
||||||
-D "CTEST_FILE=${ctest_tests_file}"
|
-D "CTEST_FILE=${ctest_tests_file}"
|
||||||
-D "TEST_DISCOVERY_TIMEOUT=${_DISCOVERY_TIMEOUT}"
|
-D "TEST_DISCOVERY_TIMEOUT=${arg_DISCOVERY_TIMEOUT}"
|
||||||
-D "TEST_XML_OUTPUT_DIR=${_XML_OUTPUT_DIR}"
|
-D "TEST_XML_OUTPUT_DIR=${arg_XML_OUTPUT_DIR}"
|
||||||
-P "${CMAKE_ROOT}/Modules/GoogleTestAddTests.cmake"
|
-P "${CMAKE_ROOT}/Modules/GoogleTestAddTests.cmake"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
@@ -564,10 +579,10 @@ function(gtest_discover_tests TARGET)
|
|||||||
"if(EXISTS \"${ctest_tests_file}\")\n"
|
"if(EXISTS \"${ctest_tests_file}\")\n"
|
||||||
" include(\"${ctest_tests_file}\")\n"
|
" include(\"${ctest_tests_file}\")\n"
|
||||||
"else()\n"
|
"else()\n"
|
||||||
" add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)\n"
|
" add_test(${target}_NOT_BUILT ${target}_NOT_BUILT)\n"
|
||||||
"endif()\n"
|
"endif()\n"
|
||||||
)
|
)
|
||||||
elseif(_DISCOVERY_MODE STREQUAL "PRE_TEST")
|
elseif(arg_DISCOVERY_MODE STREQUAL "PRE_TEST")
|
||||||
|
|
||||||
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL
|
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL
|
||||||
PROPERTY GENERATOR_IS_MULTI_CONFIG
|
PROPERTY GENERATOR_IS_MULTI_CONFIG
|
||||||
@@ -578,31 +593,31 @@ function(gtest_discover_tests TARGET)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
string(CONCAT ctest_include_content
|
string(CONCAT ctest_include_content
|
||||||
"if(EXISTS \"$<TARGET_FILE:${TARGET}>\")" "\n"
|
"if(EXISTS \"$<TARGET_FILE:${target}>\")" "\n"
|
||||||
" if(NOT EXISTS \"${ctest_tests_file}\" OR" "\n"
|
" if(NOT EXISTS \"${ctest_tests_file}\" OR" "\n"
|
||||||
" NOT \"${ctest_tests_file}\" IS_NEWER_THAN \"$<TARGET_FILE:${TARGET}>\" OR\n"
|
" NOT \"${ctest_tests_file}\" IS_NEWER_THAN \"$<TARGET_FILE:${target}>\" OR\n"
|
||||||
" NOT \"${ctest_tests_file}\" IS_NEWER_THAN \"\${CMAKE_CURRENT_LIST_FILE}\")\n"
|
" NOT \"${ctest_tests_file}\" IS_NEWER_THAN \"\${CMAKE_CURRENT_LIST_FILE}\")\n"
|
||||||
" include(\"${CMAKE_ROOT}/Modules/GoogleTestAddTests.cmake\")" "\n"
|
" include(\"${CMAKE_ROOT}/Modules/GoogleTestAddTests.cmake\")" "\n"
|
||||||
" gtest_discover_tests_impl(" "\n"
|
" gtest_discover_tests_impl(" "\n"
|
||||||
" TEST_EXECUTABLE" " [==[$<TARGET_FILE:${TARGET}>]==]" "\n"
|
" TEST_EXECUTABLE" " [==[$<TARGET_FILE:${target}>]==]" "\n"
|
||||||
" TEST_EXECUTOR" " [==[${test_executor}]==]" "\n"
|
" TEST_EXECUTOR" " [==[${test_executor}]==]" "\n"
|
||||||
" TEST_WORKING_DIR" " [==[${_WORKING_DIRECTORY}]==]" "\n"
|
" TEST_WORKING_DIR" " [==[${arg_WORKING_DIRECTORY}]==]" "\n"
|
||||||
" TEST_EXTRA_ARGS" " [==[${_EXTRA_ARGS}]==]" "\n"
|
" TEST_EXTRA_ARGS" " [==[${arg_EXTRA_ARGS}]==]" "\n"
|
||||||
" TEST_PROPERTIES" " [==[${_PROPERTIES}]==]" "\n"
|
" TEST_PROPERTIES" " [==[${arg_PROPERTIES}]==]" "\n"
|
||||||
" TEST_PREFIX" " [==[${_TEST_PREFIX}]==]" "\n"
|
" TEST_PREFIX" " [==[${arg_TEST_PREFIX}]==]" "\n"
|
||||||
" TEST_SUFFIX" " [==[${_TEST_SUFFIX}]==]" "\n"
|
" TEST_SUFFIX" " [==[${arg_TEST_SUFFIX}]==]" "\n"
|
||||||
" TEST_FILTER" " [==[${_TEST_FILTER}]==]" "\n"
|
" TEST_FILTER" " [==[${arg_TEST_FILTER}]==]" "\n"
|
||||||
" NO_PRETTY_TYPES" " [==[${_NO_PRETTY_TYPES}]==]" "\n"
|
" NO_PRETTY_TYPES" " [==[${arg_NO_PRETTY_TYPES}]==]" "\n"
|
||||||
" NO_PRETTY_VALUES" " [==[${_NO_PRETTY_VALUES}]==]" "\n"
|
" NO_PRETTY_VALUES" " [==[${arg_NO_PRETTY_VALUES}]==]" "\n"
|
||||||
" TEST_LIST" " [==[${_TEST_LIST}]==]" "\n"
|
" TEST_LIST" " [==[${arg_TEST_LIST}]==]" "\n"
|
||||||
" CTEST_FILE" " [==[${ctest_tests_file}]==]" "\n"
|
" CTEST_FILE" " [==[${ctest_tests_file}]==]" "\n"
|
||||||
" TEST_DISCOVERY_TIMEOUT" " [==[${_DISCOVERY_TIMEOUT}]==]" "\n"
|
" TEST_DISCOVERY_TIMEOUT" " [==[${arg_DISCOVERY_TIMEOUT}]==]" "\n"
|
||||||
" TEST_XML_OUTPUT_DIR" " [==[${_XML_OUTPUT_DIR}]==]" "\n"
|
" TEST_XML_OUTPUT_DIR" " [==[${arg_XML_OUTPUT_DIR}]==]" "\n"
|
||||||
" )" "\n"
|
" )" "\n"
|
||||||
" endif()" "\n"
|
" endif()" "\n"
|
||||||
" include(\"${ctest_tests_file}\")" "\n"
|
" include(\"${ctest_tests_file}\")" "\n"
|
||||||
"else()" "\n"
|
"else()" "\n"
|
||||||
" add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)" "\n"
|
" add_test(${target}_NOT_BUILT ${target}_NOT_BUILT)" "\n"
|
||||||
"endif()" "\n"
|
"endif()" "\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -628,7 +643,7 @@ function(gtest_discover_tests TARGET)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Unknown DISCOVERY_MODE: ${_DISCOVERY_MODE}")
|
message(FATAL_ERROR "Unknown DISCOVERY_MODE: ${arg_DISCOVERY_MODE}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Add discovered tests to directory TEST_INCLUDE_FILES
|
# Add discovered tests to directory TEST_INCLUDE_FILES
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.30)
|
cmake_minimum_required(VERSION 3.30)
|
||||||
|
|
||||||
# Overwrite possibly existing ${_CTEST_FILE} with empty file
|
# Overwrite possibly existing ${arg_CTEST_FILE} with empty file
|
||||||
set(flush_tests_MODE WRITE)
|
set(flush_tests_MODE WRITE)
|
||||||
|
|
||||||
# Flushes script to ${_CTEST_FILE}
|
# Flushes script to ${arg_CTEST_FILE}
|
||||||
macro(flush_script)
|
macro(flush_script)
|
||||||
file(${flush_tests_MODE} "${_CTEST_FILE}" "${script}")
|
file(${flush_tests_MODE} "${arg_CTEST_FILE}" "${script}")
|
||||||
set(flush_tests_MODE APPEND PARENT_SCOPE)
|
set(flush_tests_MODE APPEND PARENT_SCOPE)
|
||||||
|
|
||||||
set(script "")
|
set(script "")
|
||||||
@@ -20,7 +20,7 @@ macro(flush_tests_buffer)
|
|||||||
set(tests_buffer "")
|
set(tests_buffer "")
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
function(add_command NAME TEST_NAME)
|
function(add_command name test_name)
|
||||||
set(args "")
|
set(args "")
|
||||||
foreach(arg ${ARGN})
|
foreach(arg ${ARGN})
|
||||||
if(arg MATCHES "[^-./:a-zA-Z0-9_]")
|
if(arg MATCHES "[^-./:a-zA-Z0-9_]")
|
||||||
@@ -29,7 +29,7 @@ function(add_command NAME TEST_NAME)
|
|||||||
string(APPEND args " ${arg}")
|
string(APPEND args " ${arg}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
string(APPEND script "${NAME}(${TEST_NAME} ${args})\n")
|
string(APPEND script "${name}(${test_name} ${args})\n")
|
||||||
string(LENGTH "${script}" script_len)
|
string(LENGTH "${script}" script_len)
|
||||||
if(${script_len} GREATER "50000")
|
if(${script_len} GREATER "50000")
|
||||||
flush_script()
|
flush_script()
|
||||||
@@ -37,82 +37,98 @@ function(add_command NAME TEST_NAME)
|
|||||||
set(script "${script}" PARENT_SCOPE)
|
set(script "${script}" PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(generate_testname_guards OUTPUT OPEN_GUARD_VAR CLOSE_GUARD_VAR)
|
function(generate_testname_guards output open_guard_var close_guard_var)
|
||||||
set(open_guard "[=[")
|
set(open_guard "[=[")
|
||||||
set(close_guard "]=]")
|
set(close_guard "]=]")
|
||||||
set(counter 1)
|
set(counter 1)
|
||||||
while("${OUTPUT}" MATCHES "${close_guard}")
|
while("${output}" MATCHES "${close_guard}")
|
||||||
math(EXPR counter "${counter} + 1")
|
math(EXPR counter "${counter} + 1")
|
||||||
string(REPEAT "=" ${counter} equals)
|
string(REPEAT "=" ${counter} equals)
|
||||||
set(open_guard "[${equals}[")
|
set(open_guard "[${equals}[")
|
||||||
set(close_guard "]${equals}]")
|
set(close_guard "]${equals}]")
|
||||||
endwhile()
|
endwhile()
|
||||||
set(${OPEN_GUARD_VAR} "${open_guard}" PARENT_SCOPE)
|
set(${open_guard_var} "${open_guard}" PARENT_SCOPE)
|
||||||
set(${CLOSE_GUARD_VAR} "${close_guard}" PARENT_SCOPE)
|
set(${close_guard_var} "${close_guard}" PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(escape_square_brackets OUTPUT BRACKET PLACEHOLDER PLACEHOLDER_VAR OUTPUT_VAR)
|
function(escape_square_brackets output bracket placeholder placeholder_var output_var)
|
||||||
if("${OUTPUT}" MATCHES "\\${BRACKET}")
|
if("${output}" MATCHES "\\${bracket}")
|
||||||
set(placeholder "${PLACEHOLDER}")
|
set(placeholder "${placeholder}")
|
||||||
while("${OUTPUT}" MATCHES "${placeholder}")
|
while("${output}" MATCHES "${placeholder}")
|
||||||
set(placeholder "${placeholder}_")
|
set(placeholder "${placeholder}_")
|
||||||
endwhile()
|
endwhile()
|
||||||
string(REPLACE "${BRACKET}" "${placeholder}" OUTPUT "${OUTPUT}")
|
string(REPLACE "${bracket}" "${placeholder}" output "${output}")
|
||||||
set(${PLACEHOLDER_VAR} "${placeholder}" PARENT_SCOPE)
|
set(${placeholder_var} "${placeholder}" PARENT_SCOPE)
|
||||||
set(${OUTPUT_VAR} "${OUTPUT}" PARENT_SCOPE)
|
set(${output_var} "${output}" PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(gtest_discover_tests_impl)
|
function(gtest_discover_tests_impl)
|
||||||
|
|
||||||
cmake_parse_arguments(
|
set(options )
|
||||||
""
|
set(oneValueArgs
|
||||||
""
|
NO_PRETTY_TYPES # These two take a value, unlike gtest_discover_tests
|
||||||
"NO_PRETTY_TYPES;NO_PRETTY_VALUES;TEST_EXECUTABLE;TEST_WORKING_DIR;TEST_PREFIX;TEST_SUFFIX;TEST_LIST;CTEST_FILE;TEST_DISCOVERY_TIMEOUT;TEST_XML_OUTPUT_DIR;TEST_FILTER"
|
NO_PRETTY_VALUES #
|
||||||
"TEST_EXTRA_ARGS;TEST_PROPERTIES;TEST_EXECUTOR"
|
TEST_EXECUTABLE
|
||||||
|
TEST_WORKING_DIR
|
||||||
|
TEST_PREFIX
|
||||||
|
TEST_SUFFIX
|
||||||
|
TEST_LIST
|
||||||
|
CTEST_FILE
|
||||||
|
TEST_DISCOVERY_TIMEOUT
|
||||||
|
TEST_XML_OUTPUT_DIR
|
||||||
|
TEST_FILTER # This is a multi-value argument in gtest_discover_tests
|
||||||
|
)
|
||||||
|
set(multiValueArgs
|
||||||
|
TEST_EXTRA_ARGS
|
||||||
|
TEST_PROPERTIES
|
||||||
|
TEST_EXECUTOR
|
||||||
|
)
|
||||||
|
cmake_parse_arguments(arg
|
||||||
|
"${options}" "${oneValueArgs}" "${multiValueArgs}"
|
||||||
${ARGN}
|
${ARGN}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(prefix "${_TEST_PREFIX}")
|
set(prefix "${arg_TEST_PREFIX}")
|
||||||
set(suffix "${_TEST_SUFFIX}")
|
set(suffix "${arg_TEST_SUFFIX}")
|
||||||
set(extra_args ${_TEST_EXTRA_ARGS})
|
set(extra_args ${arg_TEST_EXTRA_ARGS})
|
||||||
set(properties ${_TEST_PROPERTIES})
|
set(properties ${arg_TEST_PROPERTIES})
|
||||||
set(script)
|
set(script)
|
||||||
set(suite)
|
set(suite)
|
||||||
set(tests)
|
set(tests)
|
||||||
set(tests_buffer)
|
set(tests_buffer)
|
||||||
|
|
||||||
if(_TEST_FILTER)
|
if(arg_TEST_FILTER)
|
||||||
set(filter "--gtest_filter=${_TEST_FILTER}")
|
set(filter "--gtest_filter=${arg_TEST_FILTER}")
|
||||||
else()
|
else()
|
||||||
set(filter)
|
set(filter)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Run test executable to get list of available tests
|
# Run test executable to get list of available tests
|
||||||
if(NOT EXISTS "${_TEST_EXECUTABLE}")
|
if(NOT EXISTS "${arg_TEST_EXECUTABLE}")
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR
|
||||||
"Specified test executable does not exist.\n"
|
"Specified test executable does not exist.\n"
|
||||||
" Path: '${_TEST_EXECUTABLE}'"
|
" Path: '${arg_TEST_EXECUTABLE}'"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${_TEST_EXECUTOR} "${_TEST_EXECUTABLE}" --gtest_list_tests ${filter}
|
COMMAND ${arg_TEST_EXECUTOR} "${arg_TEST_EXECUTABLE}" --gtest_list_tests ${filter}
|
||||||
WORKING_DIRECTORY "${_TEST_WORKING_DIR}"
|
WORKING_DIRECTORY "${arg_TEST_WORKING_DIR}"
|
||||||
TIMEOUT ${_TEST_DISCOVERY_TIMEOUT}
|
TIMEOUT ${arg_TEST_DISCOVERY_TIMEOUT}
|
||||||
OUTPUT_VARIABLE output
|
OUTPUT_VARIABLE output
|
||||||
RESULT_VARIABLE result
|
RESULT_VARIABLE result
|
||||||
)
|
)
|
||||||
if(NOT ${result} EQUAL 0)
|
if(NOT ${result} EQUAL 0)
|
||||||
string(REPLACE "\n" "\n " output "${output}")
|
string(REPLACE "\n" "\n " output "${output}")
|
||||||
if(_TEST_EXECUTOR)
|
if(arg_TEST_EXECUTOR)
|
||||||
set(path "${_TEST_EXECUTOR} ${_TEST_EXECUTABLE}")
|
set(path "${arg_TEST_EXECUTOR} ${arg_TEST_EXECUTABLE}")
|
||||||
else()
|
else()
|
||||||
set(path "${_TEST_EXECUTABLE}")
|
set(path "${arg_TEST_EXECUTABLE}")
|
||||||
endif()
|
endif()
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR
|
||||||
"Error running test executable.\n"
|
"Error running test executable.\n"
|
||||||
" Path: '${path}'\n"
|
" Path: '${path}'\n"
|
||||||
" Working directory: '${_TEST_WORKING_DIR}'\n"
|
" Working directory: '${arg_TEST_WORKING_DIR}'\n"
|
||||||
" Result: ${result}\n"
|
" Result: ${result}\n"
|
||||||
" Output:\n"
|
" Output:\n"
|
||||||
" ${output}\n"
|
" ${output}\n"
|
||||||
@@ -136,7 +152,7 @@ function(gtest_discover_tests_impl)
|
|||||||
string(REGEX REPLACE "\\.( *#.*)?$" "" suite "${line}")
|
string(REGEX REPLACE "\\.( *#.*)?$" "" suite "${line}")
|
||||||
if(line MATCHES "#")
|
if(line MATCHES "#")
|
||||||
string(REGEX REPLACE "/[0-9].*" "" pretty_suite "${line}")
|
string(REGEX REPLACE "/[0-9].*" "" pretty_suite "${line}")
|
||||||
if(NOT _NO_PRETTY_TYPES)
|
if(NOT arg_NO_PRETTY_TYPES)
|
||||||
string(REGEX REPLACE ".*/[0-9]+[ .#]+TypeParam = (.*)" "\\1" type_parameter "${line}")
|
string(REGEX REPLACE ".*/[0-9]+[ .#]+TypeParam = (.*)" "\\1" type_parameter "${line}")
|
||||||
else()
|
else()
|
||||||
string(REGEX REPLACE ".*/([0-9]+)[ .#]+TypeParam = .*" "\\1" type_parameter "${line}")
|
string(REGEX REPLACE ".*/([0-9]+)[ .#]+TypeParam = .*" "\\1" type_parameter "${line}")
|
||||||
@@ -149,15 +165,15 @@ function(gtest_discover_tests_impl)
|
|||||||
string(REGEX REPLACE "^DISABLED_" "" pretty_suite "${pretty_suite}")
|
string(REGEX REPLACE "^DISABLED_" "" pretty_suite "${pretty_suite}")
|
||||||
else()
|
else()
|
||||||
string(STRIP "${line}" test)
|
string(STRIP "${line}" test)
|
||||||
if(test MATCHES "#" AND NOT _NO_PRETTY_VALUES)
|
if(test MATCHES "#" AND NOT arg_NO_PRETTY_VALUES)
|
||||||
string(REGEX REPLACE "/[0-9]+[ #]+GetParam\\(\\) = " "/" pretty_test "${test}")
|
string(REGEX REPLACE "/[0-9]+[ #]+GetParam\\(\\) = " "/" pretty_test "${test}")
|
||||||
else()
|
else()
|
||||||
string(REGEX REPLACE " +#.*" "" pretty_test "${test}")
|
string(REGEX REPLACE " +#.*" "" pretty_test "${test}")
|
||||||
endif()
|
endif()
|
||||||
string(REGEX REPLACE "^DISABLED_" "" pretty_test "${pretty_test}")
|
string(REGEX REPLACE "^DISABLED_" "" pretty_test "${pretty_test}")
|
||||||
string(REGEX REPLACE " +#.*" "" test "${test}")
|
string(REGEX REPLACE " +#.*" "" test "${test}")
|
||||||
if(NOT "${_TEST_XML_OUTPUT_DIR}" STREQUAL "")
|
if(NOT "${arg_TEST_XML_OUTPUT_DIR}" STREQUAL "")
|
||||||
set(TEST_XML_OUTPUT_PARAM "--gtest_output=xml:${_TEST_XML_OUTPUT_DIR}/${prefix}${suite}.${test}${suffix}.xml")
|
set(TEST_XML_OUTPUT_PARAM "--gtest_output=xml:${arg_TEST_XML_OUTPUT_DIR}/${prefix}${suite}.${test}${suffix}.xml")
|
||||||
else()
|
else()
|
||||||
unset(TEST_XML_OUTPUT_PARAM)
|
unset(TEST_XML_OUTPUT_PARAM)
|
||||||
endif()
|
endif()
|
||||||
@@ -175,8 +191,8 @@ function(gtest_discover_tests_impl)
|
|||||||
# add to script
|
# add to script
|
||||||
add_command(add_test
|
add_command(add_test
|
||||||
"${guarded_testname}"
|
"${guarded_testname}"
|
||||||
${_TEST_EXECUTOR}
|
${arg_TEST_EXECUTOR}
|
||||||
"${_TEST_EXECUTABLE}"
|
"${arg_TEST_EXECUTABLE}"
|
||||||
"--gtest_filter=${suite}.${test}"
|
"--gtest_filter=${suite}.${test}"
|
||||||
"--gtest_also_run_disabled_tests"
|
"--gtest_also_run_disabled_tests"
|
||||||
${TEST_XML_OUTPUT_PARAM}
|
${TEST_XML_OUTPUT_PARAM}
|
||||||
@@ -192,12 +208,13 @@ function(gtest_discover_tests_impl)
|
|||||||
add_command(set_tests_properties
|
add_command(set_tests_properties
|
||||||
"${guarded_testname}"
|
"${guarded_testname}"
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
WORKING_DIRECTORY "${_TEST_WORKING_DIR}"
|
WORKING_DIRECTORY "${arg_TEST_WORKING_DIR}"
|
||||||
SKIP_REGULAR_EXPRESSION "\\[ SKIPPED \\]"
|
SKIP_REGULAR_EXPRESSION "\\[ SKIPPED \\]"
|
||||||
${properties}
|
${properties}
|
||||||
)
|
)
|
||||||
|
|
||||||
# possibly unbalanced square brackets render lists invalid so skip such tests in ${_TEST_LIST}
|
# possibly unbalanced square brackets render lists invalid so skip such
|
||||||
|
# tests in ${arg_TEST_LIST}
|
||||||
if(NOT "${testname}" MATCHES [=[(\[|\])]=])
|
if(NOT "${testname}" MATCHES [=[(\[|\])]=])
|
||||||
# escape ;
|
# escape ;
|
||||||
string(REPLACE [[;]] [[\\;]] testname "${testname}")
|
string(REPLACE [[;]] [[\\;]] testname "${testname}")
|
||||||
@@ -215,7 +232,7 @@ function(gtest_discover_tests_impl)
|
|||||||
# Create a list of all discovered tests, which users may use to e.g. set
|
# Create a list of all discovered tests, which users may use to e.g. set
|
||||||
# properties on the tests
|
# properties on the tests
|
||||||
flush_tests_buffer()
|
flush_tests_buffer()
|
||||||
add_command(set "" ${_TEST_LIST} "${tests}")
|
add_command(set "" ${arg_TEST_LIST} "${tests}")
|
||||||
|
|
||||||
# Write CTest script
|
# Write CTest script
|
||||||
flush_script()
|
flush_script()
|
||||||
|
|||||||
Reference in New Issue
Block a user