From ed93b197b589f09636d43fcd4fda32b432ff2b3a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 11 Jul 2022 12:16:13 +0200 Subject: [PATCH] Move the early-failure checks in QTRY_IMPL() These checks should not be included in the #expr reported when the test fails. They're an internal implementation detail of the loop. Split a long line while I was about it. Change-Id: Iaea0478967d01cd72ef5a5e9a6501d4be2324b18 Reviewed-by: Ivan Solovev Reviewed-by: Mitch Curtis (cherry picked from commit 4048efc80c3085b7174b746bec1fa8406c56ed42) Reviewed-by: Qt Cherry-pick Bot --- src/testlib/qtestcase.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index d8ad48d2c0a..3103cdc41c0 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -159,23 +159,25 @@ inline void useVerifyThrowsException() {} QTest::qWait(0); \ } \ int qt_test_i = 0; \ - for (; qt_test_i < timeoutValue && !(expr); qt_test_i += step) { \ + for (; qt_test_i < timeoutValue && !QTest::currentTestFailed() \ + && !(expr); qt_test_i += step) { \ QTest::qWait(step); \ } -#define QTRY_TIMEOUT_DEBUG_IMPL(expr, timeoutValue, step)\ - if (!(expr)) { \ +#define QTRY_TIMEOUT_DEBUG_IMPL(expr, timeoutValue, step) \ + if (!QTest::currentTestFailed() && !(expr)) { \ QTRY_LOOP_IMPL((expr), 2 * (timeoutValue), step); \ if (expr) { \ - QFAIL(qPrintable(QTest::Internal::formatTryTimeoutDebugMessage(u8"" #expr, timeoutValue, timeoutValue + qt_test_i))); \ + QFAIL(qPrintable(QTest::Internal::formatTryTimeoutDebugMessage(\ + u8"" #expr, timeoutValue, timeoutValue + qt_test_i))); \ } \ } #define QTRY_IMPL(expr, timeout)\ const int qt_test_step = timeout < 350 ? timeout / 7 + 1 : 50; \ const int qt_test_timeoutValue = timeout; \ - { QTRY_LOOP_IMPL(QTest::currentTestFailed() || (expr), qt_test_timeoutValue, qt_test_step); } \ - QTRY_TIMEOUT_DEBUG_IMPL(QTest::currentTestFailed() || (expr), qt_test_timeoutValue, qt_test_step) + { QTRY_LOOP_IMPL((expr), qt_test_timeoutValue, qt_test_step); } \ + QTRY_TIMEOUT_DEBUG_IMPL((expr), qt_test_timeoutValue, qt_test_step) // Will try to wait for the expression to become true while allowing event processing #define QTRY_VERIFY_WITH_TIMEOUT(expr, timeout) \