AutoTest: Allow limiting scan inside project settings

Enables to limit the scanning for tests and respectively any
further action to a list of user defined patterns.
If limitation is enabled and any of the filter patterns does
match the file will be processed.
If no filter pattern matches the file will be ignored.

Change-Id: I6a6de8f4137485e83b750997fb3c948dc6e79c68
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2024-04-26 13:45:26 +02:00
parent 0543085a64
commit 1fc135822f
4 changed files with 136 additions and 0 deletions

View File

@@ -4,7 +4,9 @@
#include "testcodeparser.h"
#include "autotestconstants.h"
#include "autotestplugin.h"
#include "autotesttr.h"
#include "testprojectsettings.h"
#include "testsettings.h"
#include "testtreemodel.h"
@@ -336,6 +338,38 @@ void TestCodeParser::scanForTests(const QSet<FilePath> &filePaths,
emit requestRemoval(files);
}
const TestProjectSettings *settings = projectSettings(project);
if (settings->limitToFilters()) {
qCDebug(LOG) << "Applying project path filters - currently" << files.size() << "files";
const QStringList filters = settings->pathFilters();
if (!filters.isEmpty()) {
// we cannot rely on QRegularExpression::fromWildcard() as we want handle paths
const QList<QRegularExpression> regexes
= Utils::transform(filters, [] (const QString &filter) {
return QRegularExpression(wildcardPatternFromString(filter));
});
files = Utils::filtered(files, [&regexes](const FilePath &fn) {
for (const QRegularExpression &regex : regexes) {
if (!regex.isValid()) {
qCDebug(LOG) << "Skipping invalid pattern? Pattern:" << regex.pattern();
continue;
}
if (regex.match(fn.path()).hasMatch())
return true;
}
return false;
});
}
qCDebug(LOG) << "After applying filters" << files.size() << "files";
if (files.isEmpty()) {
qCDebug(LOG) << "No filter matched a file - canceling scan immediately";
onFinished(true);
return;
}
}
QTC_ASSERT(!(isFullParse && files.isEmpty()), onFinished(true); return);
// use only a single parser or all current active?