From 5da094c1aa21d0440a31bf09d51016b8af7de046 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 3 Dec 2013 16:15:49 +0100 Subject: [PATCH] TestLib: Ignore trailing space in QTest::ignoreMessage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When comparing expected with actual debug messages, allow the expected ones to contain a trailing space. This is needed to not break all autotests in a follow up patch, which will prevent ~QDebug() from generating a trailing space by default. Task-number: QTBUG-15256 Change-Id: I7f67393ddfbfe37fde1ca5ef45e4ad7f4b5324b4 Reviewed-by: Friedemann Kleint Reviewed-by: Jędrzej Nowacki Reviewed-by: Jason McDonald --- src/testlib/qtestlog.cpp | 16 +++++++++++++++- .../testlib/selftests/warnings/tst_warnings.cpp | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 0e67335222..b2efa1ac9c 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -111,11 +111,25 @@ namespace QTest { last->next = item; } + static bool stringsMatch(const QString &expected, const QString &actual) + { + if (expected == actual) + return true; + + // ignore an optional whitespace at the end of str + // (the space was added automatically by ~QDebug() until Qt 5.3, + // so autotests still might expect it) + if (expected.endsWith(QLatin1Char(' '))) + return actual == expected.leftRef(expected.length() - 1); + + return false; + } + inline bool matches(QtMsgType tp, const QString &message) const { return tp == type && (pattern.type() == QVariant::String ? - pattern.toString() == message : + stringsMatch(pattern.toString(), message) : pattern.toRegularExpression().match(message).hasMatch()); } diff --git a/tests/auto/testlib/selftests/warnings/tst_warnings.cpp b/tests/auto/testlib/selftests/warnings/tst_warnings.cpp index ff4357f11f..4e3620caab 100644 --- a/tests/auto/testlib/selftests/warnings/tst_warnings.cpp +++ b/tests/auto/testlib/selftests/warnings/tst_warnings.cpp @@ -82,6 +82,10 @@ void tst_Warnings::testWarnings() qWarning("Babablabla"); qDebug("Bubublabla"); qWarning("Babablabla"); + + // accept redundant space at end to keep compatibility with Qt < 5.2 + QTest::ignoreMessage(QtDebugMsg, "Bubu "); + qDebug() << "Bubu"; } void tst_Warnings::testMissingWarnings()