diff options
author | Kai Koehne <kai.koehne@digia.com> | 2013-12-03 16:15:49 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-04 13:10:49 +0100 |
commit | 5da094c1aa21d0440a31bf09d51016b8af7de046 (patch) | |
tree | 72a15a94b0ad70793b2018b70442eceef925f719 /src/testlib | |
parent | 1ca1cec64d799db82c5320fa08f9a5340182233e (diff) |
TestLib: Ignore trailing space in QTest::ignoreMessage
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 <Friedemann.Kleint@digia.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestlog.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
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()); } |