summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2013-02-05 13:20:31 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-27 22:29:43 +0100
commit123ce761c058acc0222792e96c9aba22d06e619c (patch)
tree44f1b1fc6f3c51f6fbe86dd3cc56420a110d9881 /tests/auto/corelib/global/qlogging/tst_qlogging.cpp
parent70bb34ccd5983133118655cd73683750d4f53de7 (diff)
QT_MESSAGE_OUTPUT: add support for condition depending on the type
The motivation is to enable coloration the way KDE currently does. It can now be achieved with a QT_MESSAGE_OUTPUT set to "%{appname}(%{category}) \033[31m%{if-debug}\033[34m%{endif}%{function}\033[0m: %{message}" I was thinking about supporting directly color using something like %{begin-category-color} that would be smart and detect if we are running on a terminal, but it would be less flexible in the way the colors van be configured. Changelog: QT_MESSAGE_OUTPUT can contain conditionals based on the type of the message Change-Id: Icd8de04734a94a3afcbf542a5b78b290a1914960 Reviewed-by: David Faure (KDE) <faure@kde.org>
Diffstat (limited to 'tests/auto/corelib/global/qlogging/tst_qlogging.cpp')
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qlogging.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
index fc96d656a0..6f07538c8d 100644
--- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
@@ -64,6 +64,7 @@ private slots:
#endif
void qMessagePattern();
+ void qMessagePatternIf();
private:
QString m_appDir;
@@ -702,5 +703,68 @@ void tst_qmessagehandler::qMessagePattern()
QCOMPARE(QString::fromLatin1(output), QString::fromLatin1(expected));
}
+void tst_qmessagehandler::qMessagePatternIf()
+{
+ QProcess process;
+ const QString appExe = m_appDir + "/app";
+
+ QStringList environment = QProcess::systemEnvironment();
+ 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);
+ QVERIFY2(process.waitForStarted(), qPrintable(
+ QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
+ process.waitForFinished();
+
+ QByteArray output = process.readAllStandardError();
+ // qDebug() << output;
+ QVERIFY(!output.isEmpty());
+ QVERIFY(!output.contains("QT_MESSAGE_PATTERN"));
+
+ QVERIFY(output.contains("[D] static constructor"));
+ // we can't be sure whether the QT_MESSAGE_PATTERN is already destructed
+ QVERIFY(output.contains("static destructor"));
+ QVERIFY(output.contains("[D] qDebug"));
+ QVERIFY(output.contains("[W] qWarning"));
+ QVERIFY(output.contains("[C] qCritical"));
+ QVERIFY(output.contains("[D] qDebug2"));
+
+ //
+ // Tests some errors
+ //
+ environment = QProcess::systemEnvironment();
+ environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{endif} %{if-warning}\"");
+ process.setEnvironment(environment);
+
+ process.start(appExe);
+ QVERIFY2(process.waitForStarted(), qPrintable(
+ QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
+ process.waitForFinished();
+
+ output = process.readAllStandardError();
+ // qDebug() << output;
+ QVERIFY(!output.isEmpty());
+ QVERIFY(output.contains("QT_MESSAGE_PATTERN: Unknown placeholder %{unknown}"));
+ QVERIFY(output.contains("QT_MESSAGE_PATTERN: %{endif} without an %{if-*}"));
+ QVERIFY(output.contains("QT_MESSAGE_PATTERN: missing %{endif}"));
+
+
+ environment = QProcess::systemEnvironment();
+ environment.prepend("QT_MESSAGE_PATTERN=\"A %{if-debug}DEBUG%{if-warning}WARNING%{endif} %{message} \"");
+ process.setEnvironment(environment);
+
+ process.start(appExe);
+ QVERIFY2(process.waitForStarted(), qPrintable(
+ QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
+ process.waitForFinished();
+
+ output = process.readAllStandardError();
+ // qDebug() << output;
+ QVERIFY(!output.isEmpty());
+ QVERIFY(output.contains("QT_MESSAGE_PATTERN: %{if-*} cannot be nested"));
+ QVERIFY(output.contains("A DEBUG qDebug"));
+ QVERIFY(output.contains("A qWarning"));
+}
+
QTEST_MAIN(tst_qmessagehandler)
#include "tst_qlogging.moc"