From 0bdc7322d9232db4a8b6092d032b251ae2e03c7b Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 18 Mar 2022 15:37:46 +0100 Subject: Tidy up QTapTestLogger::addIncident()'s regex parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It had some repetition that could be refactored out, some long lines and a bool it worked out the hard way, when it had previously determined the answer in passing without recording it. Change-Id: I9e53ed087dfbe8067686b27b6cf9ac32040fbf19 Reviewed-by: Tor Arne Vestbø Reviewed-by: Qt CI Bot --- src/testlib/qtaptestlogger.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/testlib') diff --git a/src/testlib/qtaptestlogger.cpp b/src/testlib/qtaptestlogger.cpp index 1b2a70a11d..2f64752aab 100644 --- a/src/testlib/qtaptestlogger.cpp +++ b/src/testlib/qtaptestlogger.cpp @@ -328,30 +328,31 @@ void QTapTestLogger::addIncident(IncidentTypes type, const char *description, QString descriptionString = QString::fromUtf8(description); QRegularExpressionMatch match = verifyRegex.match(descriptionString); - if (!match.hasMatch()) + const bool isVerify = match.hasMatch(); + if (!isVerify) match = compareRegex.match(descriptionString); if (match.hasMatch()) { - bool isVerify = match.regularExpression() == verifyRegex; QString message = match.captured(QLatin1String("message")); QString expected; QString actual; + const auto parenthesize = [&match](QLatin1String key) -> QString { + return QLatin1String(" (") % match.captured(key) % QLatin1Char(')'); + }; + const QString actualExpression + = parenthesize(QLatin1String("actualexpression")); if (isVerify) { - QString expression = QLatin1String(" (") - % match.captured(QLatin1String("actualexpression")) % QLatin1Char(')') ; - actual = match.captured(QLatin1String("actual")).toLower() % expression; - expected = (actual.startsWith(QLatin1String("true")) - ? QLatin1String("false") - : QLatin1String("true")) % expression; + actual = match.captured(QLatin1String("actual")).toLower() + % actualExpression; + expected = QLatin1String(actual.startsWith(QLatin1String("true ")) + ? "false" : "true") % actualExpression; if (message.isEmpty()) message = QLatin1String("Verification failed"); } else { - expected = match.captured(QLatin1String("expected")) % QLatin1String(" (") - % match.captured(QLatin1String("expectedexpresssion")) - % QLatin1Char(')'); - actual = match.captured(QLatin1String("actual")) % QLatin1String(" (") - % match.captured(QLatin1String("actualexpression")) % QLatin1Char(')'); + expected = match.captured(QLatin1String("expected")) + % parenthesize(QLatin1String("expectedexpresssion")); + actual = match.captured(QLatin1String("actual")) % actualExpression; } QTestCharBuffer diagnosticsYamlish; -- cgit v1.2.3