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>bb10
parent
1ca1cec64d
commit
5da094c1aa
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue