From 75d59c9502364889af2a279c27f545224aff61fa Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 5 Jul 2022 19:27:10 +0200 Subject: Add QTest::currentTestResolved() and use in testlib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The QTRY_* macros and QTestEventLoop have (since 6.3) been exiting their loops early if the test has failed. Where that was appropriate, they should also have been exiting early on skip. [ChangeLog][QtTest] Added QTest::currentTestResolved(), which is true if the test has failed or skipped. The QTRY_*() macros and QTestEventLoop now use this, rather than QTest::currentTestFailed(), to test whether they should stop looping, so that they also do so on a skip. Task-number: QTBUG-104441 Change-Id: Ibf3d5a095b35e6670bc3daf756f05b66f7f3ef9b Reviewed-by: Tor Arne Vestbø Reviewed-by: Mitch Curtis Reviewed-by: Jason McDonald --- src/testlib/qtestcase.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/testlib/qtestcase.cpp') diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index ceee26f36c..22aa3541ff 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -3008,20 +3008,40 @@ const char *QTest::currentDataTag() } /*! - Returns \c true if the current test function failed, otherwise false. + Returns \c true if the current test function has failed, otherwise false. + + \sa QTest::currentTestResolved() */ bool QTest::currentTestFailed() { return QTestResult::currentTestFailed(); } +/*! + \since 6.5 + Returns \c true if the current test function has failed or skipped. + + This applies if the test has failed or exercised a skip. When it is true, + the test function should return early. In particular, the \c{QTRY_*} macros + and \l QTestEventLoop terminate their loops early if executed during the + test function (but not its cleanup()). After a test has called a helper + function that uses this module's macros, it can use this function to test + whether to return early. + + \sa QTest::currentTestFailed() +*/ +bool QTest::currentTestResolved() +{ + return QTestResult::currentTestFailed() || QTestResult::skipCurrentTest(); +} + /*! \internal \since 6.4 Returns \c true during the run of the test-function and its set-up. Used by the \c{QTRY_*} macros and \l QTestEventLoop to check whether to - return when QTest::currentTestFailed() is true. + return when QTest::currentTestResolved() is true. */ bool QTest::runningTest() { -- cgit v1.2.3