diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qtestcase.cpp | 25 | ||||
-rw-r--r-- | src/testlib/qtestcase.h | 1 | ||||
-rw-r--r-- | src/testlib/qtestlog.cpp | 5 | ||||
-rw-r--r-- | src/testlib/qtestlog_p.h | 1 |
4 files changed, 31 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 2ab55cac36..5648fedd63 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2202,6 +2202,19 @@ void QTest::ignoreMessage(QtMsgType type, const QRegularExpression &messagePatte #endif // QT_CONFIG(regularexpression) /*! + \since 6.8 + \overload failOnWarning() + + Appends a test failure to the test log if any warning is output. + + \sa failOnWarning() +*/ +void QTest::failOnWarning() +{ + return QTestLog::failOnWarning(); +} + +/*! \since 6.3 \overload failOnWarning() @@ -2247,7 +2260,17 @@ void QTest::failOnWarning(const char *message) \code void FileTest::init() { - QTest::failOnWarning(QRegularExpression(".?")); + QTest::failOnWarning( + QRegularExpression("QFile::.*: File(.*) already open")); + } + \endcode + + For the common case of failing on \e any warning pass no parameter: + + \code + void FileTest::init() + { + QTest::failOnWarning(); } \endcode diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 0ae1a787e2..a855ace6a9 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -435,6 +435,7 @@ namespace QTest #if QT_CONFIG(regularexpression) Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const QRegularExpression &messagePattern); #endif + Q_TESTLIB_EXPORT void failOnWarning(); Q_TESTLIB_EXPORT void failOnWarning(const char *message); #if QT_CONFIG(regularexpression) Q_TESTLIB_EXPORT void failOnWarning(const QRegularExpression &messagePattern); diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 4b6df54e91..929ccb370b 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -629,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)); diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h index f9bbfa158d..ab5fb593d4 100644 --- a/src/testlib/qtestlog_p.h +++ b/src/testlib/qtestlog_p.h @@ -71,6 +71,7 @@ public: #ifndef QT_NO_REGULAREXPRESSION static void ignoreMessage(QtMsgType type, const QRegularExpression &expression); #endif + static void failOnWarning(); static void failOnWarning(const char *msg); #ifndef QT_NO_REGULAREXPRESSION static void failOnWarning(const QRegularExpression &expression); |