From e769cf026e328ed7fff660c204ce6e55b80114e3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 10 Jan 2024 14:28:01 +0100 Subject: QTest: add opt-in changing QCOMPARE etc to exit with throw, not return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add exception classes and use them to change the control flow for QTEST_{FAIL,SKIP}_ACTION from return'ing from just the immediate function to the full way to the QTestLib infrastructure, here we filter them out. There are three modes: - If QT_NO_EXCEPTION, then we return - If QTEST_THROW_ON_... is also defined, #error out - Otherwise, if QTEST_THROW_ON_... is defined, always throw - Otherwise, the decision is made at runtime (with defaults read from QTEST_THROW_ON_... environment variables). Three selftests depend on the old behavior, as they explicitly check that multiple FAIL SKIP etc emerge, which the new framework, of course, prevents. Locally disable throwing at the test function level. Add initial docs and enable exceptions in all of the selftest subprograms to facilitate switching between the two runtime-selectable modes. [ChangeLog][QtTest] Added QTEST_THROW_ON_FAIL and QTEST_THROW_ON_SKIP C++ macros and environment variables that, when defined, change how QCOMPARE/QVERIFY/QSKIP etc exit the test function on failure. Instead of a return, exiting only the immediately-surrounding function, they throw a special exception instead, thereby exiting from subfunctions of the test function, all the way to QtTestLib. Fixes: QTBUG-66320 Change-Id: I96c38d2a1dcdd9de84942cf448a8bbf3ab6d3679 Reviewed-by: Tor Arne Vestbø Reviewed-by: Qt CI Bot --- tests/auto/testlib/selftests/subtest/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto/testlib/selftests/subtest/CMakeLists.txt') diff --git a/tests/auto/testlib/selftests/subtest/CMakeLists.txt b/tests/auto/testlib/selftests/subtest/CMakeLists.txt index f43383c86a..3dad026cf3 100644 --- a/tests/auto/testlib/selftests/subtest/CMakeLists.txt +++ b/tests/auto/testlib/selftests/subtest/CMakeLists.txt @@ -7,6 +7,7 @@ qt_internal_add_executable(subtest NO_INSTALL + EXCEPTIONS OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} SOURCES tst_subtest.cpp -- cgit v1.2.3