forked from qt-creator/qt-creator
AutoTest: Improve QRegularExpression usages
Use static const if possible to avoid re-initializations. Change-Id: Ibee9e320dccb90cd928737b809db3b56369961ec Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -62,7 +62,7 @@ static QString caseFromContent(const QString &content)
|
||||
}
|
||||
|
||||
QString result = content.mid(index + 5);
|
||||
static QRegularExpression functionName("\"(.+)\":.*");
|
||||
static const QRegularExpression functionName("\"(.+)\":.*");
|
||||
const QRegularExpressionMatch matcher = functionName.match(result);
|
||||
if (!matcher.hasMatch()) {
|
||||
qCDebug(orLog) << "got no match";
|
||||
@@ -173,29 +173,29 @@ void BoostTestOutputReader::handleMessageMatch(const QRegularExpressionMatch &ma
|
||||
|
||||
void BoostTestOutputReader::processOutputLine(const QByteArray &outputLine)
|
||||
{
|
||||
static QRegularExpression newTestStart("^Running (\\d+) test cases?\\.\\.\\.$");
|
||||
static QRegularExpression dependency("^Including test case (.+) as a dependency of "
|
||||
static const QRegularExpression newTestStart("^Running (\\d+) test cases?\\.\\.\\.$");
|
||||
static const QRegularExpression dependency("^Including test case (.+) as a dependency of "
|
||||
"test case (.+)$");
|
||||
static QRegularExpression messages("^(.+)\\((\\d+)\\): (info: (.+)|error: (.+)|"
|
||||
static const QRegularExpression messages("^(.+)\\((\\d+)\\): (info: (.+)|error: (.+)|"
|
||||
"fatal error: (.+)|last checkpoint: (.+)"
|
||||
"|Entering test (case|suite) \"(.+)\""
|
||||
"|Leaving test (case|suite) \"(.+)\"; testing time: (\\d+.+)"
|
||||
"|Test case \"(.+)\" is skipped because .+$)$");
|
||||
static QRegularExpression moduleMssg("^(Entering test module \"(.+)\"|"
|
||||
static const QRegularExpression moduleMssg("^(Entering test module \"(.+)\"|"
|
||||
"Leaving test module \"(.+)\"; testing time: (\\d+.+))$");
|
||||
static QRegularExpression noAssertion("^Test case (.*) did not check any assertions$");
|
||||
static const QRegularExpression noAssertion("^Test case (.*) did not check any assertions$");
|
||||
|
||||
static QRegularExpression summaryPreamble("^\\s*Test (module|suite|case) \"(.*)\" has "
|
||||
static const QRegularExpression summaryPreamble("^\\s*Test (module|suite|case) \"(.*)\" has "
|
||||
"(failed|passed)( with:)?$");
|
||||
static QRegularExpression summarySkip("^\\s+Test case \"(.*)\" was skipped$");
|
||||
static QRegularExpression summaryDetail("^\\s+(\\d+) test cases? out of (\\d+) "
|
||||
static const QRegularExpression summarySkip("^\\s+Test case \"(.*)\" was skipped$");
|
||||
static const QRegularExpression summaryDetail("^\\s+(\\d+) test cases? out of (\\d+) "
|
||||
"(failed|passed|skipped)$");
|
||||
static QRegularExpression summaryAssertion("^\\s+(\\d+) assertions? out of (\\d+) "
|
||||
static const QRegularExpression summaryAssertion("^\\s+(\\d+) assertions? out of (\\d+) "
|
||||
"(failed|passed)$");
|
||||
|
||||
static QRegularExpression finish("^\\*{3} (\\d+) failure(s are| is) detected in the "
|
||||
static const QRegularExpression finish("^\\*{3} (\\d+) failure(s are| is) detected in the "
|
||||
"test module \"(.*)\"$");
|
||||
QString noErrors("*** No errors detected");
|
||||
const QString noErrors("*** No errors detected");
|
||||
|
||||
const QString line = removeCommandlineColors(QString::fromUtf8(outputLine));
|
||||
if (line.trimmed().isEmpty())
|
||||
|
@@ -41,7 +41,7 @@ static QStringList parseTags(const QString &tagsString)
|
||||
{
|
||||
QStringList tagsList;
|
||||
|
||||
const QRegularExpression tagRegEx("\\[(.*?)\\]",QRegularExpression::CaseInsensitiveOption);
|
||||
static const QRegularExpression tagRegEx("\\[(.*?)\\]", QRegularExpression::CaseInsensitiveOption);
|
||||
int pos = 0;
|
||||
QRegularExpressionMatch it = tagRegEx.match(tagsString, pos);
|
||||
while (it.hasMatch()) {
|
||||
|
@@ -104,7 +104,7 @@ bool CatchTestParser::processDocument(QPromise<TestParseResultPtr> &promise,
|
||||
const QByteArray &fileContent = getFileContent(fileName);
|
||||
|
||||
if (!hasCatchNames(doc)) {
|
||||
const QRegularExpression regex("\\b(CATCH_)?"
|
||||
static const QRegularExpression regex("\\b(CATCH_)?"
|
||||
"(SCENARIO|(TEMPLATE_(PRODUCT_)?)?TEST_CASE(_METHOD)?|"
|
||||
"TEMPLATE_TEST_CASE(_METHOD)?_SIG|"
|
||||
"TEMPLATE_PRODUCT_TEST_CASE(_METHOD)?_SIG|"
|
||||
|
@@ -80,7 +80,7 @@ bool GTestParser::processDocument(QPromise<TestParseResultPtr> &promise,
|
||||
|
||||
const QByteArray &fileContent = getFileContent(fileName);
|
||||
if (!hasGTestNames(doc)) {
|
||||
const QRegularExpression regex("\\b(TEST(_[FP])?|TYPED_TEST(_P)?|(GTEST_TEST))");
|
||||
static const QRegularExpression regex("\\b(TEST(_[FP])?|TYPED_TEST(_P)?|(GTEST_TEST))");
|
||||
if (!regex.match(QString::fromUtf8(fileContent)).hasMatch())
|
||||
return false;
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ static ResultHooks::OutputStringHook outputStringHook(const QString &testCaseNam
|
||||
|
||||
static QString normalizeName(const QString &name)
|
||||
{
|
||||
static QRegularExpression parameterIndex("/\\d+");
|
||||
static const QRegularExpression parameterIndex("/\\d+");
|
||||
|
||||
QString nameWithoutParameterIndices = name;
|
||||
nameWithoutParameterIndices.remove(parameterIndex);
|
||||
|
@@ -62,7 +62,7 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
|
||||
testSuiteName = QString::fromUtf8(parameter1.spell());
|
||||
testCaseName = QString::fromUtf8(parameter2.spell());
|
||||
// test (suite) name needs to be a alpha numerical literal ( _ and $ allowed)
|
||||
const QRegularExpression alnum("^[[:alnum:]_$]+$");
|
||||
static const QRegularExpression alnum("^[[:alnum:]_$]+$");
|
||||
// test suite must not start with a number, test case may
|
||||
if (!alnum.match(testSuiteName).hasMatch()
|
||||
|| (!testSuiteName.isEmpty() && testSuiteName.at(0).isNumber())) {
|
||||
|
@@ -112,7 +112,7 @@ TestCases QtTestParser::testCases(const CppEditor::CppModelManager *modelManager
|
||||
return astVisitor.testCases();
|
||||
|
||||
TestCases result;
|
||||
const QRegularExpression regex("\\b(QTEST_(APPLESS_|GUILESS_)?MAIN)"
|
||||
static const QRegularExpression regex("\\b(QTEST_(APPLESS_|GUILESS_)?MAIN)"
|
||||
"\\s*\\(\\s*([[:alnum:]]+)\\s*\\)");
|
||||
QRegularExpressionMatchIterator it = regex.globalMatch(QString::fromUtf8(document->utf8Source()));
|
||||
while (it.hasNext()) {
|
||||
|
@@ -146,7 +146,7 @@ QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) cons
|
||||
}
|
||||
|
||||
if (pchIncludes) {
|
||||
const QRegularExpression regex("\\bQUICK_TEST_(MAIN|OPENGL_MAIN|MAIN_WITH_SETUP)");
|
||||
static const QRegularExpression regex("\\bQUICK_TEST_(MAIN|OPENGL_MAIN|MAIN_WITH_SETUP)");
|
||||
const QRegularExpressionMatch match = regex.match(QString::fromUtf8(fileContent));
|
||||
if (match.hasMatch())
|
||||
return match.captured(); // we do not care for the name, just return something non-empty
|
||||
|
Reference in New Issue
Block a user