forked from qt-creator/qt-creator
Autotest: Convert to QRegularExpression
The regex in decode() was simplified as follows: * [[:xdigit:]] matches case-insensitive, therefore this option can be removed * The non-greedy behavior is not needed, as [[:xdigit:]] and [0-9] cannot consume greedy, they stop at the first character not in their set Change-Id: I6cada7d875a67f4048e14a747223f77d4dc394e6 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
f18214b407
commit
a2009c144e
@@ -32,7 +32,6 @@
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace Autotest {
|
||||
@@ -41,17 +40,16 @@ namespace Internal {
|
||||
static QString decode(const QString& original)
|
||||
{
|
||||
QString result(original);
|
||||
static QRegExp regex("&#((x[0-9A-F]+)|([0-9]+));", Qt::CaseInsensitive);
|
||||
regex.setMinimal(true);
|
||||
static const QRegularExpression regex("&#((x[[:xdigit:]]+)|(\\d+));");
|
||||
|
||||
int pos = 0;
|
||||
while ((pos = regex.indexIn(original, pos)) != -1) {
|
||||
const QString value = regex.cap(1);
|
||||
QRegularExpressionMatchIterator it = regex.globalMatch(original);
|
||||
while (it.hasNext()) {
|
||||
const QRegularExpressionMatch match = it.next();
|
||||
const QString value = match.captured(1);
|
||||
if (value.startsWith('x'))
|
||||
result.replace(regex.cap(0), QChar(value.midRef(1).toInt(nullptr, 16)));
|
||||
result.replace(match.captured(0), QChar(value.midRef(1).toInt(nullptr, 16)));
|
||||
else
|
||||
result.replace(regex.cap(0), QChar(value.toInt(nullptr, 10)));
|
||||
pos += regex.matchedLength();
|
||||
result.replace(match.captured(0), QChar(value.toInt(nullptr, 10)));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -347,39 +345,48 @@ static QStringList extractFunctionInformation(const QString &testClassName,
|
||||
|
||||
void QtTestOutputReader::processPlainTextOutput(const QByteArray &outputLineWithNewLine)
|
||||
{
|
||||
static QRegExp start("^[*]{9} Start testing of (.*) [*]{9}$");
|
||||
static QRegExp config("^Config: Using QtTest library (.*), (Qt (\\d+(\\.\\d+){2}) \\(.*\\))$");
|
||||
static QRegExp summary("^Totals: \\d+ passed, \\d+ failed, \\d+ skipped(, \\d+ blacklisted)?$");
|
||||
static QRegExp finish("^[*]{9} Finished testing of (.*) [*]{9}$");
|
||||
static const QRegularExpression start("^[*]{9} Start testing of (.*) [*]{9}$");
|
||||
static const QRegularExpression config("^Config: Using QtTest library (.*), "
|
||||
"(Qt (\\d+(\\.\\d+){2}) \\(.*\\))$");
|
||||
static const QRegularExpression summary("^Totals: \\d+ passed, \\d+ failed, "
|
||||
"\\d+ skipped(, \\d+ blacklisted)?$");
|
||||
static const QRegularExpression finish("^[*]{9} Finished testing of (.*) [*]{9}$");
|
||||
|
||||
static QRegExp result("^(PASS |FAIL! |XFAIL |XPASS |SKIP |RESULT "
|
||||
"|BPASS |BFAIL |BXPASS |BXFAIL "
|
||||
"|INFO |QWARN |WARNING|QDEBUG |QSYSTEM): (.*)$");
|
||||
static const QRegularExpression result("^(PASS |FAIL! |XFAIL |XPASS |SKIP |RESULT "
|
||||
"|BPASS |BFAIL |BXPASS |BXFAIL "
|
||||
"|INFO |QWARN |WARNING|QDEBUG |QSYSTEM): (.*)$");
|
||||
|
||||
static QRegExp benchDetails("^\\s+([\\d,.]+ .* per iteration \\(total: [\\d,.]+, iterations: \\d+\\))$");
|
||||
static QRegExp locationUnix(QT_TEST_FAIL_UNIX_REGEXP);
|
||||
static QRegExp locationWin(QT_TEST_FAIL_WIN_REGEXP);
|
||||
static const QRegularExpression benchDetails("^\\s+([\\d,.]+ .* per iteration "
|
||||
"\\(total: [\\d,.]+, iterations: \\d+\\))$");
|
||||
static const QRegularExpression locationUnix(QT_TEST_FAIL_UNIX_REGEXP);
|
||||
static const QRegularExpression locationWin(QT_TEST_FAIL_WIN_REGEXP);
|
||||
|
||||
if (m_futureInterface.isCanceled())
|
||||
return;
|
||||
|
||||
const QString line = QString::fromUtf8(chopLineBreak(outputLineWithNewLine));
|
||||
QRegularExpressionMatch match;
|
||||
|
||||
if (result.exactMatch(line)) {
|
||||
processResultOutput(result.cap(1).toLower().trimmed(), result.cap(2));
|
||||
} else if (locationUnix.exactMatch(line)) {
|
||||
processLocationOutput(locationUnix.cap(1));
|
||||
} else if (locationWin.exactMatch(line)) {
|
||||
processLocationOutput(locationWin.cap(1));
|
||||
} else if (benchDetails.exactMatch(line)) {
|
||||
m_description = benchDetails.cap(1);
|
||||
} else if (config.exactMatch(line)) {
|
||||
handleAndSendConfigMessage(config);
|
||||
} else if (start.exactMatch(line)) {
|
||||
m_className = start.cap(1);
|
||||
auto hasMatch = [&match, line](const QRegularExpression ®ex) {
|
||||
match = regex.match(line);
|
||||
return match.hasMatch();
|
||||
};
|
||||
|
||||
if (hasMatch(result)) {
|
||||
processResultOutput(match.captured(1).toLower().trimmed(), match.captured(2));
|
||||
} else if (hasMatch(locationUnix)) {
|
||||
processLocationOutput(match.captured(1));
|
||||
} else if (hasMatch(locationWin)) {
|
||||
processLocationOutput(match.captured(1));
|
||||
} else if (hasMatch(benchDetails)) {
|
||||
m_description = match.captured(1);
|
||||
} else if (hasMatch(config)) {
|
||||
handleAndSendConfigMessage(match);
|
||||
} else if (hasMatch(start)) {
|
||||
m_className = match.captured(1);
|
||||
QTC_CHECK(!m_className.isEmpty());
|
||||
sendStartMessage(false);
|
||||
} else if (summary.exactMatch(line) || finish.exactMatch(line)) {
|
||||
} else if (summary.match(line).hasMatch() || finish.match(line).hasMatch()) {
|
||||
processSummaryFinishOutput();
|
||||
} else { // we have some plain output, but we cannot say where for sure it belongs to..
|
||||
if (!m_description.isEmpty())
|
||||
@@ -507,19 +514,19 @@ void QtTestOutputReader::sendFinishMessage(bool isFunction)
|
||||
reportResult(testResult);
|
||||
}
|
||||
|
||||
void QtTestOutputReader::handleAndSendConfigMessage(const QRegExp &config)
|
||||
void QtTestOutputReader::handleAndSendConfigMessage(const QRegularExpressionMatch &config)
|
||||
{
|
||||
TestResultPtr testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageInternal);
|
||||
testResult->setDescription(trQtVersion(config.cap(3)));
|
||||
testResult->setDescription(trQtVersion(config.captured(3)));
|
||||
reportResult(testResult);
|
||||
testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageInternal);
|
||||
testResult->setDescription(trQtBuild(config.cap(2)));
|
||||
testResult->setDescription(trQtBuild(config.captured(2)));
|
||||
reportResult(testResult);
|
||||
testResult = createDefaultResult();
|
||||
testResult->setResult(Result::MessageInternal);
|
||||
testResult->setDescription(trQtestVersion(config.cap(1)));
|
||||
testResult->setDescription(trQtestVersion(config.captured(1)));
|
||||
reportResult(testResult);
|
||||
}
|
||||
|
||||
|
@@ -65,7 +65,7 @@ private:
|
||||
void sendMessageCurrentTest();
|
||||
void sendStartMessage(bool isFunction);
|
||||
void sendFinishMessage(bool isFunction);
|
||||
void handleAndSendConfigMessage(const QRegExp &config);
|
||||
void handleAndSendConfigMessage(const QRegularExpressionMatch &config);
|
||||
|
||||
enum CDATAMode
|
||||
{
|
||||
|
Reference in New Issue
Block a user