tst_qlogging: fix test when QT_MESSAGE_PATTERN is already set
Change-Id: I608ac9920e04eb636c8d2e9cee38c6f0cd189f1f Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
parent
ae94bf2b7a
commit
72367a94a7
@ -68,6 +68,7 @@ private slots:
|
||||
|
||||
private:
|
||||
QString m_appDir;
|
||||
QStringList m_baseEnvironment;
|
||||
};
|
||||
|
||||
static QtMsgType s_type;
|
||||
@ -99,6 +100,14 @@ void tst_qmessagehandler::initTestCase()
|
||||
m_appDir = QFINDTESTDATA("app");
|
||||
QVERIFY2(!m_appDir.isEmpty(), qPrintable(
|
||||
QString::fromLatin1("Couldn't find helper app dir starting from %1.").arg(QDir::currentPath())));
|
||||
|
||||
m_baseEnvironment = QProcess::systemEnvironment();
|
||||
for (int i = 0; i < m_baseEnvironment.count(); ++i) {
|
||||
if (m_baseEnvironment.at(i).startsWith("QT_MESSAGE_PATTERN=")) {
|
||||
m_baseEnvironment.removeAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tst_qmessagehandler::cleanup()
|
||||
@ -638,7 +647,7 @@ void tst_qmessagehandler::qMessagePattern()
|
||||
//
|
||||
// test QT_MESSAGE_PATTERN
|
||||
//
|
||||
QStringList environment = QProcess::systemEnvironment();
|
||||
QStringList environment = m_baseEnvironment;
|
||||
// %{file} is tricky because of shadow builds
|
||||
environment.prepend("QT_MESSAGE_PATTERN=\"%{type} %{appname} %{line} %{function} %{message}\"");
|
||||
process.setEnvironment(environment);
|
||||
@ -660,7 +669,7 @@ void tst_qmessagehandler::qMessagePattern()
|
||||
QVERIFY(output.contains("critical tst_qlogging 58 main qCritical"));
|
||||
QVERIFY(output.contains("debug tst_qlogging 62 main qDebug2"));
|
||||
|
||||
environment = QProcess::systemEnvironment();
|
||||
environment = m_baseEnvironment;
|
||||
environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{message}\"");
|
||||
process.setEnvironment(environment);
|
||||
|
||||
@ -708,7 +717,7 @@ void tst_qmessagehandler::qMessagePatternIf()
|
||||
QProcess process;
|
||||
const QString appExe = m_appDir + "/app";
|
||||
|
||||
QStringList environment = QProcess::systemEnvironment();
|
||||
QStringList environment = m_baseEnvironment;
|
||||
environment.prepend("QT_MESSAGE_PATTERN=\"[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{message}\"");
|
||||
process.setEnvironment(environment);
|
||||
process.start(appExe);
|
||||
@ -732,7 +741,7 @@ void tst_qmessagehandler::qMessagePatternIf()
|
||||
//
|
||||
// Tests some errors
|
||||
//
|
||||
environment = QProcess::systemEnvironment();
|
||||
environment = m_baseEnvironment;
|
||||
environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{endif} %{if-warning}\"");
|
||||
process.setEnvironment(environment);
|
||||
|
||||
@ -749,7 +758,7 @@ void tst_qmessagehandler::qMessagePatternIf()
|
||||
QVERIFY(output.contains("QT_MESSAGE_PATTERN: missing %{endif}"));
|
||||
|
||||
|
||||
environment = QProcess::systemEnvironment();
|
||||
environment = m_baseEnvironment;
|
||||
environment.prepend("QT_MESSAGE_PATTERN=\"A %{if-debug}DEBUG%{if-warning}WARNING%{endif} %{message} \"");
|
||||
process.setEnvironment(environment);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user