summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-07-05 19:27:10 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2022-09-22 17:34:51 +0200
commit0462dba7665450bdd0dc07e6a7e6ebe2805994a9 (patch)
tree1a35e16a62f3e59040719e5440ddae89efdeaab1 /src/testlib/qtestcase.cpp
parentabab3c5dadd7fb80c2807f061e4d6aa7724c78c8 (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.cpp')
-rw-r--r--src/testlib/qtestcase.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 99be5afaef..2c9f2d4049 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -468,6 +468,7 @@ class WatchDog;
static QObject *currentTestObject = nullptr;
static QString mainSourcePath;
+static bool inTestFunction = false;
#if defined(Q_OS_MACOS)
static IOPMAssertionID macPowerSavingDisabled = 0;
@@ -1120,6 +1121,7 @@ void TestMethods::invokeTestOnData(int index) const
/* Benchmarking: for each accumulation iteration*/
bool invokeOk;
do {
+ QTest::inTestFunction = true;
if (m_initMethod.isValid())
m_initMethod.invoke(QTest::currentTestObject, Qt::DirectConnection);
@@ -1141,6 +1143,7 @@ void TestMethods::invokeTestOnData(int index) const
invokeOk = false;
}
+ QTest::inTestFunction = false;
QTestResult::finishedCurrentTestData();
if (!initQuit) {
@@ -3012,6 +3015,17 @@ bool QTest::currentTestFailed()
return QTestResult::currentTestFailed();
}
+/*
+ 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.
+*/
+bool QTest::runningTest()
+{
+ return QTest::inTestFunction;
+}
+
/*! \internal
*/
QObject *QTest::testObject()