diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-07-05 19:27:10 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-09-22 17:34:51 +0200 |
commit | 75d59c9502364889af2a279c27f545224aff61fa (patch) | |
tree | a99df4ce072ed3ced6a12b1933636a4a81d90859 /src/testlib | |
parent | 1fa0e86995bfdf9c0507fcd097fce712554a769e (diff) |
Add QTest::currentTestResolved() and use in testlib
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ø <tor.arne.vestbo@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestcase.cpp | 24 | ||||
-rw-r--r-- | src/testlib/qtestcase.h | 7 | ||||
-rw-r--r-- | src/testlib/qtesteventloop.h | 2 |
3 files changed, 27 insertions, 6 deletions
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,7 +3008,9 @@ 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() { @@ -3016,12 +3018,30 @@ bool QTest::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() { diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 6affbf1507..54978e34e7 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -149,7 +149,7 @@ inline void useVerifyThrowsException() {} * what the following provides as QTRY_LOOP_IMPL(); however, for now, the * reporting of how much to increase the timeout to (if within a factor of two) * on failure and the check for (QTest::runningTest() && - * QTest::currentTestFailed()) go beyond qWaitFor(). (We no longer care about + * QTest::currentTestResolved()) go beyond qWaitFor(). (We no longer care about * the bug in MSVC < 2017 that precluded using qWaitFor() in the implementation * here, see QTBUG-59096.) */ @@ -160,14 +160,14 @@ inline void useVerifyThrowsException() {} QTest::qWait(0); \ } \ int qt_test_i = 0; \ - for (; qt_test_i < timeoutValue && !(QTest::runningTest() && QTest::currentTestFailed()) \ + for (; qt_test_i < timeoutValue && !(QTest::runningTest() && QTest::currentTestResolved()) \ && !(expr); qt_test_i += step) { \ QTest::qWait(step); \ } // Ends in a for-block, so doesn't want a following semicolon. #define QTRY_TIMEOUT_DEBUG_IMPL(expr, timeoutValue, step) \ - if (!(QTest::runningTest() && QTest::currentTestFailed()) && !(expr)) { \ + if (!(QTest::runningTest() && QTest::currentTestResolved()) && !(expr)) { \ QTRY_LOOP_IMPL(expr, 2 * (timeoutValue), step) \ if ((expr)) { \ QFAIL(qPrintable(QTest::Internal::formatTryTimeoutDebugMessage(\ @@ -420,6 +420,7 @@ namespace QTest Q_TESTLIB_EXPORT const char *currentTestFunction(); Q_TESTLIB_EXPORT const char *currentDataTag(); Q_TESTLIB_EXPORT bool currentTestFailed(); + Q_TESTLIB_EXPORT bool currentTestResolved(); Q_TESTLIB_EXPORT bool runningTest(); // Internal, for use by macros and QTestEventLoop. Q_TESTLIB_EXPORT Qt::Key asciiToKey(char ascii); diff --git a/src/testlib/qtesteventloop.h b/src/testlib/qtesteventloop.h index 2ac8bdecdf..2860882ca1 100644 --- a/src/testlib/qtesteventloop.h +++ b/src/testlib/qtesteventloop.h @@ -60,7 +60,7 @@ inline void QTestEventLoop::enterLoopMSecs(int ms) Q_ASSERT(!loop); _timeout = false; - if (QTest::runningTest() && QTest::currentTestFailed()) + if (QTest::runningTest() && QTest::currentTestResolved()) return; QEventLoop l; |