From 943ae8bb701a8187d295b747ba82025c55ca9add Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 12 Nov 2013 15:03:54 +0100 Subject: Add overload of QTest::ignoreMessage() taking a QRegularExpression. Make it possible to match messages by a pattern. Change-Id: I713312e86db5471755459f1ecc43e8f1ac7a95fb Reviewed-by: Jason McDonald --- tests/auto/testlib/selftests/expected_warnings.lightxml | 14 ++++++++++++++ tests/auto/testlib/selftests/expected_warnings.txt | 6 +++++- tests/auto/testlib/selftests/expected_warnings.xml | 14 ++++++++++++++ tests/auto/testlib/selftests/expected_warnings.xunitxml | 11 ++++++++++- tests/auto/testlib/selftests/warnings/tst_warnings.cpp | 17 +++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) (limited to 'tests/auto/testlib') diff --git a/tests/auto/testlib/selftests/expected_warnings.lightxml b/tests/auto/testlib/selftests/expected_warnings.lightxml index ad786832ca..2ad9e97449 100644 --- a/tests/auto/testlib/selftests/expected_warnings.lightxml +++ b/tests/auto/testlib/selftests/expected_warnings.lightxml @@ -24,6 +24,12 @@ + + + + + + @@ -37,6 +43,14 @@ + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_warnings.txt b/tests/auto/testlib/selftests/expected_warnings.txt index d8064651b0..e73de980cb 100644 --- a/tests/auto/testlib/selftests/expected_warnings.txt +++ b/tests/auto/testlib/selftests/expected_warnings.txt @@ -7,10 +7,14 @@ QDEBUG : tst_Warnings::testWarnings() Debug QDEBUG : tst_Warnings::testWarnings() Debug QDEBUG : tst_Warnings::testWarnings() Baba QDEBUG : tst_Warnings::testWarnings() Baba +QDEBUG : tst_Warnings::testWarnings() Bubublabla +QWARN : tst_Warnings::testWarnings() Babablabla 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::testMissingWarningsRegularExpression() Did not receive any message matching: "Warning\s\d" +FAIL! : tst_Warnings::testMissingWarningsRegularExpression() 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 @@ -18,5 +22,5 @@ INFO : tst_Warnings::testMissingWarningsWithData(second row) Did not receive m 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, 3 failed, 0 skipped +Totals: 3 passed, 4 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 8ad236b52a..14a45ca4fd 100644 --- a/tests/auto/testlib/selftests/expected_warnings.xml +++ b/tests/auto/testlib/selftests/expected_warnings.xml @@ -26,6 +26,12 @@ + + + + + + @@ -39,6 +45,14 @@ + + + + + + + + diff --git a/tests/auto/testlib/selftests/expected_warnings.xunitxml b/tests/auto/testlib/selftests/expected_warnings.xunitxml index 3e3b9ce18e..7be47174c6 100644 --- a/tests/auto/testlib/selftests/expected_warnings.xunitxml +++ b/tests/auto/testlib/selftests/expected_warnings.xunitxml @@ -1,5 +1,5 @@ - + @@ -12,12 +12,18 @@ + + + + + + @@ -34,8 +40,11 @@ + + + diff --git a/tests/auto/testlib/selftests/warnings/tst_warnings.cpp b/tests/auto/testlib/selftests/warnings/tst_warnings.cpp index 20f53fdc91..ff4357f11f 100644 --- a/tests/auto/testlib/selftests/warnings/tst_warnings.cpp +++ b/tests/auto/testlib/selftests/warnings/tst_warnings.cpp @@ -41,6 +41,7 @@ #include +#include #include class tst_Warnings: public QObject @@ -49,6 +50,7 @@ class tst_Warnings: public QObject private slots: void testWarnings(); void testMissingWarnings(); + void testMissingWarningsRegularExpression(); void testMissingWarningsWithData_data(); void testMissingWarningsWithData(); }; @@ -73,6 +75,13 @@ void tst_Warnings::testWarnings() qDebug("Baba"); qDebug("Bubu"); qDebug("Baba"); + + QTest::ignoreMessage(QtDebugMsg, QRegularExpression("^Bubu.*")); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Baba.*")); + qDebug("Bubublabla"); + qWarning("Babablabla"); + qDebug("Bubublabla"); + qWarning("Babablabla"); } void tst_Warnings::testMissingWarnings() @@ -84,6 +93,14 @@ void tst_Warnings::testMissingWarnings() qWarning("Warning2"); } +void tst_Warnings::testMissingWarningsRegularExpression() +{ + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Warning\\d\\d")); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Warning\\s\\d")); + + qWarning("Warning11"); +} + void tst_Warnings::testMissingWarningsWithData_data() { QTest::addColumn("dummy"); -- cgit v1.2.3