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 <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QRegExp>
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
namespace Autotest {
|
namespace Autotest {
|
||||||
@@ -41,17 +40,16 @@ namespace Internal {
|
|||||||
static QString decode(const QString& original)
|
static QString decode(const QString& original)
|
||||||
{
|
{
|
||||||
QString result(original);
|
QString result(original);
|
||||||
static QRegExp regex("&#((x[0-9A-F]+)|([0-9]+));", Qt::CaseInsensitive);
|
static const QRegularExpression regex("&#((x[[:xdigit:]]+)|(\\d+));");
|
||||||
regex.setMinimal(true);
|
|
||||||
|
|
||||||
int pos = 0;
|
QRegularExpressionMatchIterator it = regex.globalMatch(original);
|
||||||
while ((pos = regex.indexIn(original, pos)) != -1) {
|
while (it.hasNext()) {
|
||||||
const QString value = regex.cap(1);
|
const QRegularExpressionMatch match = it.next();
|
||||||
|
const QString value = match.captured(1);
|
||||||
if (value.startsWith('x'))
|
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
|
else
|
||||||
result.replace(regex.cap(0), QChar(value.toInt(nullptr, 10)));
|
result.replace(match.captured(0), QChar(value.toInt(nullptr, 10)));
|
||||||
pos += regex.matchedLength();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -347,39 +345,48 @@ static QStringList extractFunctionInformation(const QString &testClassName,
|
|||||||
|
|
||||||
void QtTestOutputReader::processPlainTextOutput(const QByteArray &outputLineWithNewLine)
|
void QtTestOutputReader::processPlainTextOutput(const QByteArray &outputLineWithNewLine)
|
||||||
{
|
{
|
||||||
static QRegExp start("^[*]{9} Start testing of (.*) [*]{9}$");
|
static const QRegularExpression start("^[*]{9} Start testing of (.*) [*]{9}$");
|
||||||
static QRegExp config("^Config: Using QtTest library (.*), (Qt (\\d+(\\.\\d+){2}) \\(.*\\))$");
|
static const QRegularExpression config("^Config: Using QtTest library (.*), "
|
||||||
static QRegExp summary("^Totals: \\d+ passed, \\d+ failed, \\d+ skipped(, \\d+ blacklisted)?$");
|
"(Qt (\\d+(\\.\\d+){2}) \\(.*\\))$");
|
||||||
static QRegExp finish("^[*]{9} Finished testing of (.*) [*]{9}$");
|
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 "
|
static const QRegularExpression result("^(PASS |FAIL! |XFAIL |XPASS |SKIP |RESULT "
|
||||||
"|BPASS |BFAIL |BXPASS |BXFAIL "
|
"|BPASS |BFAIL |BXPASS |BXFAIL "
|
||||||
"|INFO |QWARN |WARNING|QDEBUG |QSYSTEM): (.*)$");
|
"|INFO |QWARN |WARNING|QDEBUG |QSYSTEM): (.*)$");
|
||||||
|
|
||||||
static QRegExp benchDetails("^\\s+([\\d,.]+ .* per iteration \\(total: [\\d,.]+, iterations: \\d+\\))$");
|
static const QRegularExpression benchDetails("^\\s+([\\d,.]+ .* per iteration "
|
||||||
static QRegExp locationUnix(QT_TEST_FAIL_UNIX_REGEXP);
|
"\\(total: [\\d,.]+, iterations: \\d+\\))$");
|
||||||
static QRegExp locationWin(QT_TEST_FAIL_WIN_REGEXP);
|
static const QRegularExpression locationUnix(QT_TEST_FAIL_UNIX_REGEXP);
|
||||||
|
static const QRegularExpression locationWin(QT_TEST_FAIL_WIN_REGEXP);
|
||||||
|
|
||||||
if (m_futureInterface.isCanceled())
|
if (m_futureInterface.isCanceled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QString line = QString::fromUtf8(chopLineBreak(outputLineWithNewLine));
|
const QString line = QString::fromUtf8(chopLineBreak(outputLineWithNewLine));
|
||||||
|
QRegularExpressionMatch match;
|
||||||
|
|
||||||
if (result.exactMatch(line)) {
|
auto hasMatch = [&match, line](const QRegularExpression ®ex) {
|
||||||
processResultOutput(result.cap(1).toLower().trimmed(), result.cap(2));
|
match = regex.match(line);
|
||||||
} else if (locationUnix.exactMatch(line)) {
|
return match.hasMatch();
|
||||||
processLocationOutput(locationUnix.cap(1));
|
};
|
||||||
} else if (locationWin.exactMatch(line)) {
|
|
||||||
processLocationOutput(locationWin.cap(1));
|
if (hasMatch(result)) {
|
||||||
} else if (benchDetails.exactMatch(line)) {
|
processResultOutput(match.captured(1).toLower().trimmed(), match.captured(2));
|
||||||
m_description = benchDetails.cap(1);
|
} else if (hasMatch(locationUnix)) {
|
||||||
} else if (config.exactMatch(line)) {
|
processLocationOutput(match.captured(1));
|
||||||
handleAndSendConfigMessage(config);
|
} else if (hasMatch(locationWin)) {
|
||||||
} else if (start.exactMatch(line)) {
|
processLocationOutput(match.captured(1));
|
||||||
m_className = start.cap(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());
|
QTC_CHECK(!m_className.isEmpty());
|
||||||
sendStartMessage(false);
|
sendStartMessage(false);
|
||||||
} else if (summary.exactMatch(line) || finish.exactMatch(line)) {
|
} else if (summary.match(line).hasMatch() || finish.match(line).hasMatch()) {
|
||||||
processSummaryFinishOutput();
|
processSummaryFinishOutput();
|
||||||
} else { // we have some plain output, but we cannot say where for sure it belongs to..
|
} else { // we have some plain output, but we cannot say where for sure it belongs to..
|
||||||
if (!m_description.isEmpty())
|
if (!m_description.isEmpty())
|
||||||
@@ -507,19 +514,19 @@ void QtTestOutputReader::sendFinishMessage(bool isFunction)
|
|||||||
reportResult(testResult);
|
reportResult(testResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtTestOutputReader::handleAndSendConfigMessage(const QRegExp &config)
|
void QtTestOutputReader::handleAndSendConfigMessage(const QRegularExpressionMatch &config)
|
||||||
{
|
{
|
||||||
TestResultPtr testResult = createDefaultResult();
|
TestResultPtr testResult = createDefaultResult();
|
||||||
testResult->setResult(Result::MessageInternal);
|
testResult->setResult(Result::MessageInternal);
|
||||||
testResult->setDescription(trQtVersion(config.cap(3)));
|
testResult->setDescription(trQtVersion(config.captured(3)));
|
||||||
reportResult(testResult);
|
reportResult(testResult);
|
||||||
testResult = createDefaultResult();
|
testResult = createDefaultResult();
|
||||||
testResult->setResult(Result::MessageInternal);
|
testResult->setResult(Result::MessageInternal);
|
||||||
testResult->setDescription(trQtBuild(config.cap(2)));
|
testResult->setDescription(trQtBuild(config.captured(2)));
|
||||||
reportResult(testResult);
|
reportResult(testResult);
|
||||||
testResult = createDefaultResult();
|
testResult = createDefaultResult();
|
||||||
testResult->setResult(Result::MessageInternal);
|
testResult->setResult(Result::MessageInternal);
|
||||||
testResult->setDescription(trQtestVersion(config.cap(1)));
|
testResult->setDescription(trQtestVersion(config.captured(1)));
|
||||||
reportResult(testResult);
|
reportResult(testResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -65,7 +65,7 @@ private:
|
|||||||
void sendMessageCurrentTest();
|
void sendMessageCurrentTest();
|
||||||
void sendStartMessage(bool isFunction);
|
void sendStartMessage(bool isFunction);
|
||||||
void sendFinishMessage(bool isFunction);
|
void sendFinishMessage(bool isFunction);
|
||||||
void handleAndSendConfigMessage(const QRegExp &config);
|
void handleAndSendConfigMessage(const QRegularExpressionMatch &config);
|
||||||
|
|
||||||
enum CDATAMode
|
enum CDATAMode
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user