From c5187da4abf823fdb7d07f780f24c3235b9c2c49 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 24 Feb 2022 15:14:48 +0100 Subject: [PATCH] ProjectExplorer: Respect leading whitespace in custom output parsers Leading spaces are often relevant and must not be trimmed. Task-number: QTCREATORBUG-26892 Change-Id: Ie5c119a2c4df22f2c7bae2c9abaf5362d51c8c4e Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: Christian Stenger --- src/plugins/projectexplorer/customparser.cpp | 51 +++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/plugins/projectexplorer/customparser.cpp b/src/plugins/projectexplorer/customparser.cpp index 8703b2c7c97..b3006f4ba04 100644 --- a/src/plugins/projectexplorer/customparser.cpp +++ b/src/plugins/projectexplorer/customparser.cpp @@ -271,7 +271,7 @@ OutputLineParser::Result CustomParser::parseLine( CustomParserExpression::CustomParserChannel channel ) { - const QString line = rawLine.trimmed(); + const QString line = rightTrimmed(rawLine); const Result res = hasMatch(line, channel, m_error, Task::Error); if (res.status != Status::NotHandled) return res; @@ -629,6 +629,55 @@ void ProjectExplorerPlugin::testCustomOutputParsers_data() << QString() << QString() << Tasks({CompileTask(Task::Error, unitTestMessage, unitTestFileName, unitTestLineNumber)}) << QString(); + + const QString leadingSpacesPattern = "^ MESSAGE:(.+)"; + const QString leadingSpacesMessage = " MESSAGE:Error"; + const QString noLeadingSpacesMessage = "MESSAGE:Error"; + QTest::newRow("leading spaces: match") + << leadingSpacesMessage + << QString() + << OutputParserTester::STDOUT + << CustomParserExpression::ParseBothChannels + << CustomParserExpression::ParseBothChannels + << leadingSpacesPattern << 2 << 3 << 1 + << QString() << 1 << 2 << 3 + << QString() << QString() + << Tasks({CompileTask(Task::Error, "Error", {}, -1)}) + << QString(); + QTest::newRow("leading spaces: no match") + << noLeadingSpacesMessage + << QString() + << OutputParserTester::STDOUT + << CustomParserExpression::ParseBothChannels + << CustomParserExpression::ParseBothChannels + << leadingSpacesPattern << 2 << 3 << 1 + << QString() << 1 << 2 << 3 + << (noLeadingSpacesMessage + '\n') << QString() + << Tasks() + << QString(); + const QString noLeadingSpacesPattern = "^MESSAGE:(.+)"; + QTest::newRow("no leading spaces: match") + << noLeadingSpacesMessage + << QString() + << OutputParserTester::STDOUT + << CustomParserExpression::ParseBothChannels + << CustomParserExpression::ParseBothChannels + << noLeadingSpacesPattern << 2 << 3 << 1 + << QString() << 1 << 2 << 3 + << QString() << QString() + << Tasks({CompileTask(Task::Error, "Error", {}, -1)}) + << QString(); + QTest::newRow("no leading spaces: no match") + << leadingSpacesMessage + << QString() + << OutputParserTester::STDOUT + << CustomParserExpression::ParseBothChannels + << CustomParserExpression::ParseBothChannels + << noLeadingSpacesPattern << 3 << 2 << 1 + << QString() << 1 << 2 << 3 + << (leadingSpacesMessage + '\n') << QString() + << Tasks() + << QString(); } void ProjectExplorerPlugin::testCustomOutputParsers()