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>
This commit is contained in:
parent
1fa0e86995
commit
75d59c9502
@ -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()
|
bool QTest::currentTestFailed()
|
||||||
{
|
{
|
||||||
return QTestResult::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
|
\internal
|
||||||
\since 6.4
|
\since 6.4
|
||||||
Returns \c true during the run of the test-function and its set-up.
|
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
|
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()
|
bool QTest::runningTest()
|
||||||
{
|
{
|
||||||
|
@ -149,7 +149,7 @@ inline void useVerifyThrowsException() {}
|
|||||||
* what the following provides as QTRY_LOOP_IMPL(); however, for now, the
|
* 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)
|
* reporting of how much to increase the timeout to (if within a factor of two)
|
||||||
* on failure and the check for (QTest::runningTest() &&
|
* 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
|
* the bug in MSVC < 2017 that precluded using qWaitFor() in the implementation
|
||||||
* here, see QTBUG-59096.)
|
* here, see QTBUG-59096.)
|
||||||
*/
|
*/
|
||||||
@ -160,14 +160,14 @@ inline void useVerifyThrowsException() {}
|
|||||||
QTest::qWait(0); \
|
QTest::qWait(0); \
|
||||||
} \
|
} \
|
||||||
int qt_test_i = 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) { \
|
&& !(expr); qt_test_i += step) { \
|
||||||
QTest::qWait(step); \
|
QTest::qWait(step); \
|
||||||
}
|
}
|
||||||
// Ends in a for-block, so doesn't want a following semicolon.
|
// Ends in a for-block, so doesn't want a following semicolon.
|
||||||
|
|
||||||
#define QTRY_TIMEOUT_DEBUG_IMPL(expr, timeoutValue, step) \
|
#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) \
|
QTRY_LOOP_IMPL(expr, 2 * (timeoutValue), step) \
|
||||||
if ((expr)) { \
|
if ((expr)) { \
|
||||||
QFAIL(qPrintable(QTest::Internal::formatTryTimeoutDebugMessage(\
|
QFAIL(qPrintable(QTest::Internal::formatTryTimeoutDebugMessage(\
|
||||||
@ -420,6 +420,7 @@ namespace QTest
|
|||||||
Q_TESTLIB_EXPORT const char *currentTestFunction();
|
Q_TESTLIB_EXPORT const char *currentTestFunction();
|
||||||
Q_TESTLIB_EXPORT const char *currentDataTag();
|
Q_TESTLIB_EXPORT const char *currentDataTag();
|
||||||
Q_TESTLIB_EXPORT bool currentTestFailed();
|
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 bool runningTest(); // Internal, for use by macros and QTestEventLoop.
|
||||||
|
|
||||||
Q_TESTLIB_EXPORT Qt::Key asciiToKey(char ascii);
|
Q_TESTLIB_EXPORT Qt::Key asciiToKey(char ascii);
|
||||||
|
@ -60,7 +60,7 @@ inline void QTestEventLoop::enterLoopMSecs(int ms)
|
|||||||
Q_ASSERT(!loop);
|
Q_ASSERT(!loop);
|
||||||
_timeout = false;
|
_timeout = false;
|
||||||
|
|
||||||
if (QTest::runningTest() && QTest::currentTestFailed())
|
if (QTest::runningTest() && QTest::currentTestResolved())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QEventLoop l;
|
QEventLoop l;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user