Add *_check build targets for auto cmake tests

Similar `*_check` targets are created in `qt_internal_add_test`.
This change extends that implementation to auto cmake tests.

Note: These generated targets do not have additional dependencies, on
the build targets, unlike those generated by `qt_internal_add_test`.
You would need to (re-)run the build first separately and then run the
`*_check` target.

Fixes: QTBUG-98640
Change-Id: I387f09570b6a4a345756133870c2eb9ef1cf3cf8
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit 8f2f4ad4688df4963982c489c80b84e115cda29d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 566db56dd3c3d1ed6697f2774054533aa2329d91)
This commit is contained in:
Cristian Le 2025-01-16 16:17:28 +01:00
parent 2457a59435
commit 55a1ef3ee3
3 changed files with 42 additions and 12 deletions

View File

@ -109,3 +109,35 @@ endfunction()
function(_qt_internal_test_batch_target_name out)
set(${out} "test_batch" PARENT_SCOPE)
endfunction()
# Create a *_check target of the ctest execution for alternative execution
# Arguments:
# : CTEST_TEST_NAME: (default: ${testname})
# name of the ctest test used
function(_qt_internal_make_check_target testname)
set(options "")
set(singleOpts CTEST_TEST_NAME)
set(multiOpts "")
cmake_parse_arguments(PARSE_ARGV 0 arg
"${options}" "${singleOpts}" "${multiOpts}"
)
if(NOT arg_CTEST_TEST_NAME)
set(arg_CTEST_TEST_NAME ${testname})
endif()
set(test_config_options "")
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
set(test_config_options -C $<CONFIG>)
endif()
# Note: By default the working directory here is CMAKE_CURRENT_BINARY_DIR, which will
# work as long as this is called anywhere up or down the path where the equivalent
# `add_test` is called (not down a different branch path).
add_custom_target(${testname}_check
VERBATIM
COMMENT "Running ctest -V -R \"^${arg_CTEST_TEST_NAME}$\" ${test_config_options}"
COMMAND
"${CMAKE_CTEST_COMMAND}" -V -R "^${arg_CTEST_TEST_NAME}$" ${test_config_options}
)
endfunction()

View File

@ -765,18 +765,10 @@ function(qt_internal_add_test name)
)
endif()
# Add a ${target}/check makefile target, to more easily test one test.
set(test_config_options "")
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
set(test_config_options -C $<CONFIG>)
endif()
add_custom_target("${testname}_check"
VERBATIM
COMMENT "Running ${CMAKE_CTEST_COMMAND} -V -R \"^${name}$\" ${test_config_options}"
COMMAND "${CMAKE_CTEST_COMMAND}" -V -R "^${name}$" ${test_config_options}
)
# Add a ${target}_check makefile target, to more easily test one test.
# TODO: Note in batch mode testname tests would execute all batched tests defined in name
_qt_internal_make_check_target(${testname} CTEST_TEST_NAME ${name})
# Add appropriate dependencies to the targets as needed
if(TARGET "${name}")
add_dependencies("${testname}_check" "${name}")
if(ANDROID)

View File

@ -457,6 +457,7 @@ macro(_qt_internal_test_expect_pass _dir)
)
endif()
set_tests_properties(${testname} PROPERTIES ENVIRONMENT "ASAN_OPTIONS=detect_leaks=0")
_qt_internal_make_check_target(${testname})
if(_ARGS_BINARY)
set(run_env_args "")
@ -663,6 +664,9 @@ list(APPEND CMAKE_PREFIX_PATH \"${__expect_fail_prefixes}\")
--build-project "${_dir}"
--build-options ${option_list}
)
_qt_internal_make_check_target(${testname})
unset(__expect_fail_prefixes)
endmacro()
@ -776,4 +780,6 @@ function(_qt_internal_test_module_includes)
--build-project module_includes
--build-options ${option_list}
)
_qt_internal_make_check_target(module_includes)
endfunction()