diff options
author | Christian Stenger <christian.stenger@qt.io> | 2019-05-24 10:12:43 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2019-05-27 13:10:22 +0000 |
commit | a2fa8ce2e871a8fa0e9827992fe3ecb728b13bac (patch) | |
tree | cbe8015f0bda007f0f0a41fd0b15299c038d1ad9 /src/plugins/autotest | |
parent | 07b1d2aa5611494348ac27c2c7f517702de70794 (diff) |
AutoTest: Replace QRegExp by QRegularExpression
Change-Id: I0e7de5482786105d21765fdf7c1180c16414bc01
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r-- | src/plugins/autotest/gtest/gtestoutputreader.cpp | 74 | ||||
-rw-r--r-- | src/plugins/autotest/gtest/gtestresult.cpp | 4 | ||||
-rw-r--r-- | src/plugins/autotest/gtest/gtesttreeitem.cpp | 24 |
3 files changed, 62 insertions, 40 deletions
diff --git a/src/plugins/autotest/gtest/gtestoutputreader.cpp b/src/plugins/autotest/gtest/gtestoutputreader.cpp index e1cdf085a4a..f64155ed421 100644 --- a/src/plugins/autotest/gtest/gtestoutputreader.cpp +++ b/src/plugins/autotest/gtest/gtestoutputreader.cpp @@ -31,7 +31,7 @@ #include <QDir> #include <QFileInfo> -#include <QRegExp> +#include <QRegularExpression> namespace Autotest { namespace Internal { @@ -63,24 +63,31 @@ GTestOutputReader::GTestOutputReader(const QFutureInterface<TestResultPtr> &futu void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLine) { - static QRegExp newTestStarts("^\\[-{10}\\] \\d+ tests? from (.*)$"); - static QRegExp testEnds("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$"); - static QRegExp newTestSetStarts("^\\[ RUN \\] (.*)$"); - static QRegExp testSetSuccess("^\\[ OK \\] (.*) \\((.*)\\)$"); - static QRegExp testSetFail("^\\[ FAILED \\] (.*) \\((\\d+ ms)\\)$"); - static QRegExp disabledTests("^ YOU HAVE (\\d+) DISABLED TESTS?$"); - static QRegExp failureLocation("^(.*):(\\d+): Failure$"); - static QRegExp errorLocation("^(.*)\\((\\d+)\\): error:.*$"); - static QRegExp iterations("^Repeating all tests \\(iteration (\\d+)\\) \\. \\. \\.$"); + static const QRegularExpression newTestStarts("^\\[-{10}\\] \\d+ tests? from (.*)$"); + static const QRegularExpression testEnds("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$"); + static const QRegularExpression newTestSetStarts("^\\[ RUN \\] (.*)$"); + static const QRegularExpression testSetSuccess("^\\[ OK \\] (.*) \\((.*)\\)$"); + static const QRegularExpression testSetFail("^\\[ FAILED \\] (.*) \\((\\d+ ms)\\)$"); + static const QRegularExpression disabledTests("^ YOU HAVE (\\d+) DISABLED TESTS?$"); + static const QRegularExpression failureLocation("^(.*):(\\d+): Failure$"); + static const QRegularExpression errorLocation("^(.*)\\((\\d+)\\): error:.*$"); + static const QRegularExpression iterations("^Repeating all tests " + "\\(iteration (\\d+)\\) \\. \\. \\.$"); const QString line = QString::fromLatin1(chopLineBreak(outputLineWithNewLine)); if (line.trimmed().isEmpty()) return; + struct ExactMatch : public QRegularExpressionMatch + { + ExactMatch(const QRegularExpressionMatch &other) : QRegularExpressionMatch(other) {} + operator bool() const { return hasMatch(); } + }; + if (!line.startsWith('[')) { m_description.append(line).append('\n'); - if (iterations.exactMatch(line)) { - m_iteration = iterations.cap(1).toInt(); + if (ExactMatch match = iterations.match(line)) { + m_iteration = match.captured(1).toInt(); m_description.clear(); } else if (line.startsWith(QStringLiteral("Note:"))) { m_description = line; @@ -91,22 +98,22 @@ void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLin testResult->setDescription(m_description); reportResult(testResult); m_description.clear(); - } else if (disabledTests.exactMatch(line)) { - m_disabled = disabledTests.cap(1).toInt(); + } else if (ExactMatch match = disabledTests.match(line)) { + m_disabled = match.captured(1).toInt(); m_description.clear(); } return; } - if (testEnds.exactMatch(line)) { + if (ExactMatch match = testEnds.match(line)) { TestResultPtr testResult = createDefaultResult(); testResult->setResult(ResultType::TestEnd); - testResult->setDescription(tr("Test execution took %1").arg(testEnds.cap(2))); + testResult->setDescription(tr("Test execution took %1").arg(match.captured(2))); reportResult(testResult); m_currentTestSuite.clear(); m_currentTestCase.clear(); - } else if (newTestStarts.exactMatch(line)) { - setCurrentTestSuite(newTestStarts.cap(1)); + } else if (ExactMatch match = newTestStarts.match(line)) { + setCurrentTestSuite(match.captured(1)); TestResultPtr testResult = createDefaultResult(); testResult->setResult(ResultType::TestStart); if (m_iteration > 1) { @@ -116,15 +123,15 @@ void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLin testResult->setDescription(tr("Executing test suite %1").arg(m_currentTestSuite)); } reportResult(testResult); - } else if (newTestSetStarts.exactMatch(line)) { - setCurrentTestCase(newTestSetStarts.cap(1)); + } else if (ExactMatch match = newTestSetStarts.match(line)) { + setCurrentTestCase(match.captured(1)); TestResultPtr testResult = TestResultPtr(new GTestResult(QString(), m_projectFile, QString())); testResult->setResult(ResultType::MessageCurrentTest); testResult->setDescription(tr("Entering test case %1").arg(m_currentTestCase)); reportResult(testResult); m_description.clear(); - } else if (testSetSuccess.exactMatch(line)) { + } else if (ExactMatch match = testSetSuccess.match(line)) { TestResultPtr testResult = createDefaultResult(); testResult->setResult(ResultType::Pass); testResult->setDescription(m_description); @@ -132,24 +139,23 @@ void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLin m_description.clear(); testResult = createDefaultResult(); testResult->setResult(ResultType::MessageInternal); - testResult->setDescription(tr("Execution took %1.").arg(testSetSuccess.cap(2))); + testResult->setDescription(tr("Execution took %1.").arg(match.captured(2))); reportResult(testResult); m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1); - } else if (testSetFail.exactMatch(line)) { + } else if (ExactMatch match = testSetFail.match(line)) { TestResultPtr testResult = createDefaultResult(); testResult->setResult(ResultType::Fail); m_description.chop(1); QStringList resultDescription; for (const QString &output : m_description.split('\n')) { - QRegExp *match = nullptr; - if (failureLocation.exactMatch(output)) - match = &failureLocation; - else if (errorLocation.exactMatch(output)) - match = &errorLocation; - if (!match) { - resultDescription << output; - continue; + QRegularExpressionMatch innerMatch = failureLocation.match(output); + if (!innerMatch.hasMatch()) { + innerMatch = errorLocation.match(output); + if (!innerMatch.hasMatch()) { + resultDescription << output; + continue; + } } testResult->setDescription(resultDescription.join('\n')); reportResult(testResult); @@ -157,8 +163,8 @@ void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLin testResult = createDefaultResult(); testResult->setResult(ResultType::MessageLocation); - testResult->setLine(match->cap(2).toInt()); - QString file = constructSourceFilePath(m_buildDir, match->cap(1)); + testResult->setLine(innerMatch.captured(2).toInt()); + QString file = constructSourceFilePath(m_buildDir, innerMatch.captured(1)); if (!file.isEmpty()) testResult->setFileName(file); resultDescription << output; @@ -168,7 +174,7 @@ void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLin m_description.clear(); testResult = createDefaultResult(); testResult->setResult(ResultType::MessageInternal); - testResult->setDescription(tr("Execution took %1.").arg(testSetFail.cap(2))); + testResult->setDescription(tr("Execution took %1.").arg(match.captured(2))); reportResult(testResult); m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1); } diff --git a/src/plugins/autotest/gtest/gtestresult.cpp b/src/plugins/autotest/gtest/gtestresult.cpp index 8893bd363a7..b2f3aae67be 100644 --- a/src/plugins/autotest/gtest/gtestresult.cpp +++ b/src/plugins/autotest/gtest/gtestresult.cpp @@ -30,6 +30,8 @@ #include <coreplugin/id.h> +#include <QRegularExpression> + namespace Autotest { namespace Internal { @@ -76,7 +78,7 @@ bool GTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermedi static QString normalizeName(const QString &name) { - static QRegExp parameterIndex("/\\d+"); + static QRegularExpression parameterIndex("/\\d+"); QString nameWithoutParameterIndices = name; nameWithoutParameterIndices.remove(parameterIndex); diff --git a/src/plugins/autotest/gtest/gtesttreeitem.cpp b/src/plugins/autotest/gtest/gtesttreeitem.cpp index 37aeb4d4070..f558039bf75 100644 --- a/src/plugins/autotest/gtest/gtesttreeitem.cpp +++ b/src/plugins/autotest/gtest/gtesttreeitem.cpp @@ -37,7 +37,7 @@ #include <utils/qtcassert.h> #include <utils/theme/theme.h> -#include <QRegExp> +#include <QRegularExpression> namespace Autotest { namespace Internal { @@ -71,6 +71,20 @@ TestTreeItem *GTestTreeItem::copyWithoutChildren() return copied; } +static QString wildCardPattern(const QString &original) +{ + QString pattern = original; + pattern.replace('.', "\\."); + pattern.replace('$', "\\$"); + pattern.replace('(', "\\(").replace(')', "\\)"); + pattern.replace('[', "\\[").replace(']', "\\]"); + pattern.replace('{', "\\{").replace('}', "\\}"); + pattern.replace('+', "\\+"); + pattern.replace('*', ".*"); + pattern.replace('?', '.'); + return pattern; +} + static bool matchesFilter(const QString &filter, const QString &fullTestName) { QStringList positive; @@ -88,13 +102,13 @@ static bool matchesFilter(const QString &filter, const QString &fullTestName) testName.append('.'); for (const QString &curr : negative) { - QRegExp regex(curr, Qt::CaseSensitive, QRegExp::Wildcard); - if (regex.exactMatch(testName)) + QRegularExpression regex(wildCardPattern(curr)); + if (regex.match(testName).hasMatch()) return false; } for (const QString &curr : positive) { - QRegExp regex(curr, Qt::CaseSensitive, QRegExp::Wildcard); - if (regex.exactMatch(testName)) + QRegularExpression regex(wildCardPattern(curr)); + if (regex.match(testName).hasMatch()) return true; } return positive.isEmpty(); |