diff options
Diffstat (limited to 'src/testlib/qtestlog.cpp')
-rw-r--r-- | src/testlib/qtestlog.cpp | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index f7b75d5502..929ccb370b 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -67,10 +67,10 @@ static void saveCoverageTool(const char * appname, bool testfailed, bool install #endif } -static QElapsedTimer elapsedFunctionTime; -static QElapsedTimer elapsedTotalTime; +Q_CONSTINIT static QElapsedTimer elapsedFunctionTime; +Q_CONSTINIT static QElapsedTimer elapsedTotalTime; -#define FOREACH_TEST_LOGGER for (const auto &logger : qAsConst(*QTest::loggers())) +#define FOREACH_TEST_LOGGER for (const auto &logger : std::as_const(*QTest::loggers())) namespace QTest { @@ -116,7 +116,7 @@ namespace QTest { // (the space was added automatically by ~QDebug() until Qt 5.3, // so autotests still might expect it) if (expected.endsWith(u' ')) - return actual == QStringView{expected}.left(expected.length() - 1); + return actual == QStringView{expected}.left(expected.size() - 1); return false; } @@ -164,10 +164,8 @@ namespace QTest { // remove the item from the list if (last) last->next = list->next; - else if (list->next) - ignoreResultList = list->next; else - ignoreResultList = nullptr; + ignoreResultList = list->next; delete list; return true; @@ -181,7 +179,7 @@ namespace QTest { static bool handleFailOnWarning(const QMessageLogContext &context, const QString &message) { - // failOnWarnings can be called multiple times per test function, so let + // failOnWarning can be called multiple times per test function, so let // each call cause a failure if required. for (const auto &pattern : failOnWarningList) { if (pattern.metaType() == QMetaType::fromType<QString>()) { @@ -320,7 +318,6 @@ void QTestLog::clearIgnoreMessages() QTest::IgnoreResultList::clearList(QTest::ignoreResultList); } - void QTestLog::clearFailOnWarnings() { QTest::failOnWarningList.clear(); @@ -328,6 +325,8 @@ void QTestLog::clearFailOnWarnings() void QTestLog::clearCurrentTestState() { + clearIgnoreMessages(); + clearFailOnWarnings(); QTest::currentTestState = QTest::Unresolved; } @@ -473,10 +472,10 @@ void QTestLog::addSkip(const char *msg, const char *file, int line) logger->addIncident(QAbstractTestLogger::Skip, msg, file, line); } -void QTestLog::addBenchmarkResult(const QBenchmarkResult &result) +void QTestLog::addBenchmarkResults(const QList<QBenchmarkResult> &results) { FOREACH_TEST_LOGGER - logger->addBenchmarkResult(result); + logger->addBenchmarkResults(results); } void QTestLog::startLogging() @@ -561,6 +560,21 @@ bool QTestLog::hasLoggers() return !QTest::loggers()->empty(); } +/*! + \internal + + Returns true if all loggers support repeated test runs +*/ +bool QTestLog::isRepeatSupported() +{ + FOREACH_TEST_LOGGER { + if (!logger->isRepeatSupported()) + return false; + } + + return true; +} + bool QTestLog::loggerUsingStdout() { FOREACH_TEST_LOGGER { @@ -615,6 +629,11 @@ void QTestLog::ignoreMessage(QtMsgType type, const QRegularExpression &expressio } #endif // QT_CONFIG(regularexpression) +void QTestLog::failOnWarning() +{ + QTest::failOnWarningList.push_back({}); +} + void QTestLog::failOnWarning(const char *msg) { QTest::failOnWarningList.push_back(QString::fromUtf8(msg)); |