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 | 0462dba7665450bdd0dc07e6a7e6ebe2805994a9 (patch) | |
tree | 1a35e16a62f3e59040719e5440ddae89efdeaab1 /src/testlib/qtestcase.h | |
parent | abab3c5dadd7fb80c2807f061e4d6aa7724c78c8 (diff) |
Skip early return from test loops during cleanup()
The QTRY_* macros and QTestEventLoop exit early if the test has
resolved; however, in the cleanup phase of a test, even if the test
has failed, these loops should continue as normal.
[ChangeLog][QtTest] During the cleanup() phase of a test, the QTRY_*
macros and QTestEventLoop now ignore the test resolution, in contrast
to when they are used from the test itself, which (since 6.3.0) exits
the loops early if the test has failed.
Pick-to: 6.4 6.3
Fixes: QTBUG-104441
Change-Id: I2673161967cbbc57815155af698a9338ab98a686
Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'src/testlib/qtestcase.h')
-rw-r--r-- | src/testlib/qtestcase.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 3d268135a4..6affbf1507 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -148,9 +148,10 @@ inline void useVerifyThrowsException() {} /* Ideally we would adapt qWaitFor(), or a variant on it, to implement roughly * 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::currentTestFailed() go beyond - * qWaitFor(). (We no longer care about the bug in MSVC < 2017 that precluded - * using qWaitFor() in the implementation here, see QTBUG-59096.) + * on failure and the check for (QTest::runningTest() && + * QTest::currentTestFailed()) go beyond qWaitFor(). (We no longer care about + * the bug in MSVC < 2017 that precluded using qWaitFor() in the implementation + * here, see QTBUG-59096.) */ // NB: not do {...} while (0) wrapped, as qt_test_i is accessed after it @@ -159,14 +160,14 @@ inline void useVerifyThrowsException() {} QTest::qWait(0); \ } \ int qt_test_i = 0; \ - for (; qt_test_i < timeoutValue && !QTest::currentTestFailed() \ + for (; qt_test_i < timeoutValue && !(QTest::runningTest() && QTest::currentTestFailed()) \ && !(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::currentTestFailed() && !(expr)) { \ + if (!(QTest::runningTest() && QTest::currentTestFailed()) && !(expr)) { \ QTRY_LOOP_IMPL(expr, 2 * (timeoutValue), step) \ if ((expr)) { \ QFAIL(qPrintable(QTest::Internal::formatTryTimeoutDebugMessage(\ @@ -419,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 runningTest(); // Internal, for use by macros and QTestEventLoop. Q_TESTLIB_EXPORT Qt::Key asciiToKey(char ascii); Q_TESTLIB_EXPORT char keyToAscii(Qt::Key key); |