AutoTest: Extract helper function for re-use

Change-Id: I38993e28090ff68803bfc417d1590e1b2eb97bbe
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2024-04-26 14:14:55 +02:00
parent 7832f47408
commit ca0c3bc55c
3 changed files with 19 additions and 17 deletions

View File

@@ -472,6 +472,21 @@ void popupResultsPane()
dd->m_resultsPane->popup(Core::IOutputPane::NoModeSwitch); dd->m_resultsPane->popup(Core::IOutputPane::NoModeSwitch);
} }
QString wildcardPatternFromString(const QString &original)
{
QString pattern = original;
pattern.replace('\\', "\\\\");
pattern.replace('.', "\\.");
pattern.replace('^', "\\^").replace('$', "\\$");
pattern.replace('(', "\\(").replace(')', "\\)");
pattern.replace('[', "\\[").replace(']', "\\]");
pattern.replace('{', "\\{").replace('}', "\\}");
pattern.replace('+', "\\+");
pattern.replace('*', ".*");
pattern.replace('?', '.');
return pattern;
}
bool ChoicePair::matches(const ProjectExplorer::RunConfiguration *rc) const bool ChoicePair::matches(const ProjectExplorer::RunConfiguration *rc) const
{ {
return rc && rc->displayName() == displayName && rc->runnable().command.executable() == executable; return rc && rc->displayName() == displayName && rc->runnable().command.executable() == executable;

View File

@@ -33,6 +33,6 @@ void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choic
ChoicePair cachedChoiceFor(const QString &buildTargetKey); ChoicePair cachedChoiceFor(const QString &buildTargetKey);
void clearChoiceCache(); void clearChoiceCache();
void popupResultsPane(); void popupResultsPane();
QString wildcardPatternFromString(const QString &original);
} // Autotest::Internal } // Autotest::Internal

View File

@@ -8,6 +8,7 @@
#include "gtestframework.h" #include "gtestframework.h"
#include "gtestparser.h" #include "gtestparser.h"
#include "../autotesttr.h" #include "../autotesttr.h"
#include "../autotestplugin.h"
#include <cppeditor/cppmodelmanager.h> #include <cppeditor/cppmodelmanager.h>
@@ -56,20 +57,6 @@ TestTreeItem *GTestTreeItem::copyWithoutChildren()
return copied; 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) static bool matchesFilter(const QString &filter, const QString &fullTestName)
{ {
QStringList positive; QStringList positive;
@@ -87,12 +74,12 @@ static bool matchesFilter(const QString &filter, const QString &fullTestName)
testName.append('.'); testName.append('.');
for (const QString &curr : negative) { for (const QString &curr : negative) {
QRegularExpression regex(wildCardPattern(curr)); QRegularExpression regex(wildcardPatternFromString(curr));
if (regex.match(testName).hasMatch()) if (regex.match(testName).hasMatch())
return false; return false;
} }
for (const QString &curr : positive) { for (const QString &curr : positive) {
QRegularExpression regex(wildCardPattern(curr)); QRegularExpression regex(wildcardPatternFromString(curr));
if (regex.match(testName).hasMatch()) if (regex.match(testName).hasMatch())
return true; return true;
} }