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