diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 1d66101a0fc..29dfbc144e3 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -302,7 +302,6 @@ void QTestLog::leaveTestFunction() if (printAvailableTags) return; - QTest::IgnoreResultList::clearList(QTest::ignoreResultList); QTest::TestLoggers::leaveTestFunction(); } @@ -318,6 +317,11 @@ void QTestLog::printUnhandledIgnoreMessages() } } +void QTestLog::clearIgnoreMessages() +{ + QTest::IgnoreResultList::clearList(QTest::ignoreResultList); +} + void QTestLog::addPass(const char *msg) { if (printAvailableTags) diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h index e45d9c9626d..1fe52367ec7 100644 --- a/src/testlib/qtestlog_p.h +++ b/src/testlib/qtestlog_p.h @@ -77,6 +77,7 @@ public: static void ignoreMessage(QtMsgType type, const char *msg); static int unhandledIgnoreMessages(); static void printUnhandledIgnoreMessages(); + static void clearIgnoreMessages(); static void warn(const char *msg, const char *file, int line); static void info(const char *msg, const char *file, int line); diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index c3634eb01ee..c49c7aefe36 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -132,15 +132,16 @@ void QTestResult::finishedCurrentTestData() if (QTest::expectFailMode) addFailure("QEXPECT_FAIL was called without any subsequent verification statements", 0, 0); clearExpectFail(); + + if (!QTest::dataFailed && QTestLog::unhandledIgnoreMessages()) { + QTestLog::printUnhandledIgnoreMessages(); + addFailure("Not all expected messages were received", 0, 0); + } + QTestLog::clearIgnoreMessages(); } void QTestResult::finishedCurrentTestFunction() { - if (!QTest::failed && QTestLog::unhandledIgnoreMessages()) { - QTestLog::printUnhandledIgnoreMessages(); - addFailure("Not all expected messages were received", 0, 0); - } - if (!QTest::failed && !QTest::skipCurrentTest) { QTestLog::addPass(""); } diff --git a/tests/auto/testlib/selftests/expected_warnings.lightxml b/tests/auto/testlib/selftests/expected_warnings.lightxml index 116156ed8ad..ad786832ca4 100644 --- a/tests/auto/testlib/selftests/expected_warnings.lightxml +++ b/tests/auto/testlib/selftests/expected_warnings.lightxml @@ -37,6 +37,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_warnings.txt b/tests/auto/testlib/selftests/expected_warnings.txt index 6f7d0f491bd..6196ec0261b 100644 --- a/tests/auto/testlib/selftests/expected_warnings.txt +++ b/tests/auto/testlib/selftests/expected_warnings.txt @@ -11,6 +11,12 @@ PASS : tst_Warnings::testWarnings() INFO : tst_Warnings::testMissingWarnings() Did not receive message: "Warning0" INFO : tst_Warnings::testMissingWarnings() Did not receive message: "Warning1" FAIL! : tst_Warnings::testMissingWarnings() Not all expected messages were received +INFO : tst_Warnings::testMissingWarningsWithData(first row) Did not receive message: "Warning0" +INFO : tst_Warnings::testMissingWarningsWithData(first row) Did not receive message: "Warning1" +FAIL! : tst_Warnings::testMissingWarningsWithData(first row) Not all expected messages were received +INFO : tst_Warnings::testMissingWarningsWithData(second row) Did not receive message: "Warning0" +INFO : tst_Warnings::testMissingWarningsWithData(second row) Did not receive message: "Warning1" +FAIL! : tst_Warnings::testMissingWarningsWithData(second row) Not all expected messages were received PASS : tst_Warnings::cleanupTestCase() -Totals: 3 passed, 1 failed, 0 skipped +Totals: 3 passed, 3 failed, 0 skipped ********* Finished testing of tst_Warnings ********* diff --git a/tests/auto/testlib/selftests/expected_warnings.xml b/tests/auto/testlib/selftests/expected_warnings.xml index 13e6c1df793..12cff7c13db 100644 --- a/tests/auto/testlib/selftests/expected_warnings.xml +++ b/tests/auto/testlib/selftests/expected_warnings.xml @@ -39,6 +39,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_warnings.xunitxml b/tests/auto/testlib/selftests/expected_warnings.xunitxml index a96393d6488..3e3b9ce18ea 100644 --- a/tests/auto/testlib/selftests/expected_warnings.xunitxml +++ b/tests/auto/testlib/selftests/expected_warnings.xunitxml @@ -1,5 +1,5 @@ - + @@ -18,6 +18,14 @@ + + + + + + + + @@ -27,6 +35,10 @@ + + + + diff --git a/tests/auto/testlib/selftests/warnings/tst_warnings.cpp b/tests/auto/testlib/selftests/warnings/tst_warnings.cpp index 933d0cc6cec..e53869e18ec 100644 --- a/tests/auto/testlib/selftests/warnings/tst_warnings.cpp +++ b/tests/auto/testlib/selftests/warnings/tst_warnings.cpp @@ -49,6 +49,8 @@ class tst_Warnings: public QObject private slots: void testWarnings(); void testMissingWarnings(); + void testMissingWarningsWithData_data(); + void testMissingWarningsWithData(); }; void tst_Warnings::testWarnings() @@ -82,6 +84,23 @@ void tst_Warnings::testMissingWarnings() qWarning("Warning2"); } +void tst_Warnings::testMissingWarningsWithData_data() +{ + QTest::addColumn("dummy"); + + QTest::newRow("first row") << 0; + QTest::newRow("second row") << 1; +} + +void tst_Warnings::testMissingWarningsWithData() +{ + QTest::ignoreMessage(QtWarningMsg, "Warning0"); + QTest::ignoreMessage(QtWarningMsg, "Warning1"); + QTest::ignoreMessage(QtWarningMsg, "Warning2"); + + qWarning("Warning2"); +} + QTEST_MAIN(tst_Warnings) #include "tst_warnings.moc"