Port androidtestrunner to QRegularExpression

Change-Id: If135b29996b7036d65472a1b5fa4817cd7907aba
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Lars Knoll 2020-03-18 11:36:50 +01:00
parent e835a6853b
commit 23b14237f8

View File

@ -30,7 +30,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDir> #include <QDir>
#include <QHash> #include <QHash>
#include <QRegExp> #include <QRegularExpression>
#include <QSystemSemaphore> #include <QSystemSemaphore>
#include <QXmlStreamReader> #include <QXmlStreamReader>
@ -177,7 +177,7 @@ static QString shellQuoteWin(const QString &arg)
// Quotes are escaped and their preceding backslashes are doubled. // Quotes are escaped and their preceding backslashes are doubled.
// It's impossible to escape anything inside a quoted string on cmd // It's impossible to escape anything inside a quoted string on cmd
// level, so the outer quoting must be "suspended". // level, so the outer quoting must be "suspended".
ret.replace(QRegExp(QStringLiteral("(\\\\*)\"")), QStringLiteral("\"\\1\\1\\^\"\"")); ret.replace(QRegularExpression(QStringLiteral("(\\\\*)\"")), QStringLiteral("\"\\1\\1\\^\"\""));
// The argument must not end with a \ since this would be interpreted // The argument must not end with a \ since this would be interpreted
// as escaping the quote -- rather put the \ behind the quote: e.g. // as escaping the quote -- rather put the \ behind the quote: e.g.
// rather use "foo"\ than "foo\" // rather use "foo"\ than "foo\"
@ -334,8 +334,8 @@ static void setOutputFile(QString file, QString format)
static bool parseTestArgs() static bool parseTestArgs()
{ {
QRegExp newLoggingFormat{QStringLiteral("(.*),(txt|csv|xunitxml|xml|lightxml|teamcity|tap)")}; QRegularExpression oldFormats{QStringLiteral("^-(txt|csv|xunitxml|xml|lightxml|teamcity|tap)$")};
QRegExp oldFormats{QStringLiteral("-(txt|csv|xunitxml|xml|lightxml|teamcity|tap)")}; QRegularExpression newLoggingFormat{QStringLiteral("^(.*),(txt|csv|xunitxml|xml|lightxml|teamcity|tap)$")};
QString file; QString file;
QString logType; QString logType;
@ -347,18 +347,22 @@ static bool parseTestArgs()
return false; // missing file argument return false; // missing file argument
const auto &filePath = g_options.testArgsList[++i]; const auto &filePath = g_options.testArgsList[++i];
if (!newLoggingFormat.exactMatch(filePath)) { const auto match = newLoggingFormat.match(filePath);
if (!match.hasMatch()) {
file = filePath; file = filePath;
} else { } else {
const auto capturedTexts = newLoggingFormat.capturedTexts(); const auto capturedTexts = match.capturedTexts();
setOutputFile(capturedTexts.at(1), capturedTexts.at(2)); setOutputFile(capturedTexts.at(1), capturedTexts.at(2));
} }
} else if (oldFormats.exactMatch(arg)) { } else {
logType = oldFormats.capturedTexts().at(1); auto match = oldFormats.match(arg);
if (match.hasMatch()) {
logType = match.capturedTexts().at(1);
} else { } else {
unhandledArgs += QStringLiteral(" %1").arg(arg); unhandledArgs += QStringLiteral(" %1").arg(arg);
} }
} }
}
if (g_options.outFiles.isEmpty() || !file.isEmpty() || !logType.isEmpty()) if (g_options.outFiles.isEmpty() || !file.isEmpty() || !logType.isEmpty())
setOutputFile(file, logType); setOutputFile(file, logType);