From 72367a94a750355eb748793ce8c365373a332c9c Mon Sep 17 00:00:00 2001 From: David Faure Date: Tue, 5 Mar 2013 23:12:54 +0100 Subject: tst_qlogging: fix test when QT_MESSAGE_PATTERN is already set Change-Id: I608ac9920e04eb636c8d2e9cee38c6f0cd189f1f Reviewed-by: Olivier Goffart Reviewed-by: Kai Koehne --- tests/auto/corelib/global/qlogging/tst_qlogging.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'tests/auto/corelib/global') diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index 6f07538c8d..04ce504189 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -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); -- cgit v1.2.3