From 5297a0a2af7dd774a28921a44b3664f5636536c4 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 16 Mar 2021 16:41:47 +0100 Subject: Rework the failure macros in the Qt CTest kit The _qt_internal_test_expect_fail macro fails when the test fails during the configuration step. Rename this macro to _qt_internal_test_expect_build_fail and add the _qt_internal_test_expect_fail macro that expects inverted test result. Change-Id: I4635e99152f7a32f5c48202e84fec59800453d34 Reviewed-by: Alexandru Croitor (cherry picked from commit fec5b8e81c976b8b0cdf45b459f7d481222e86d7) --- src/corelib/Qt6CTestMacros.cmake | 14 +++++++++++++- tests/auto/cmake/CMakeLists.txt | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake index 50cc40939a..9062985ac0 100644 --- a/src/corelib/Qt6CTestMacros.cmake +++ b/src/corelib/Qt6CTestMacros.cmake @@ -113,6 +113,7 @@ function(_qt_internal_set_up_test_run_environment testname) endfunction() +# Checks if the test project can be built successfully. macro(_qt_internal_test_expect_pass _dir) cmake_parse_arguments(_ARGS "" "BINARY" "" ${ARGN}) string(REPLACE "(" "_" testname "${_dir}") @@ -137,7 +138,18 @@ macro(_qt_internal_test_expect_pass _dir) endif() endmacro() -macro(_qt_internal_test_expect_fail _dir) +# Checks if the build of the test project fails. +# This test passes if the test project fails either at the +# configuring or build steps. +macro(_qt_internal_test_expect_fail) + _qt_internal_test_expect_pass(${ARGV}) + set_tests_properties(${testname} PROPERTIES WILL_FAIL TRUE) +endmacro() + +# Checks if the build of the test project fails. +# This test passes only if the test project fails at the build step, +# but not at the configuring step. +macro(_qt_internal_test_expect_build_fail _dir) string(REPLACE "(" "_" testname "${_dir}") string(REPLACE ")" "_" testname "${testname}") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}") diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 996fb979cf..317541f984 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -102,8 +102,8 @@ if (NOT NO_WIDGETS) _qt_internal_test_expect_pass(test_dependent_modules) _qt_internal_test_expect_pass("test(needsquoting)dirname") endif() -_qt_internal_test_expect_fail(test_add_resource_options) -_qt_internal_test_expect_fail(test_wrap_cpp_options) +_qt_internal_test_expect_build_fail(test_add_resource_options) +_qt_internal_test_expect_build_fail(test_wrap_cpp_options) _qt_internal_test_expect_pass(test_platform_defs_include) _qt_internal_test_expect_pass(test_qtmainwin_library) @@ -146,7 +146,7 @@ _qt_internal_test_expect_pass(test_testlib_definitions) _qt_internal_test_expect_pass(test_json_plugin_includes) if(NOT NO_GUI) - _qt_internal_test_expect_fail(test_testlib_no_link_gui) + _qt_internal_test_expect_build_fail(test_testlib_no_link_gui) endif() execute_process(COMMAND ${CMAKE_COMMAND} -E copy @@ -155,7 +155,7 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E copy ) if (NOT NO_WIDGETS) - _qt_internal_test_expect_fail(test_testlib_no_link_widgets) + _qt_internal_test_expect_build_fail(test_testlib_no_link_widgets) execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/test_testlib_definitions/main.cpp" "${CMAKE_CURRENT_BINARY_DIR}/failbuild/test_testlib_no_link_widgets/test_testlib_no_link_widgets/" -- cgit v1.2.3