AutoTest: Extract function to get active frameworks

For later re-use.

Change-Id: I87cf6db4de861b626e4669351df3f5119952328f
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2023-02-06 14:29:24 +01:00
parent 96185ca4f1
commit 9277bb5111
3 changed files with 22 additions and 16 deletions

View File

@@ -438,6 +438,24 @@ void AutotestPluginPrivate::onRunUnderCursorTriggered(TestRunMode mode)
m_testRunner.runTests(mode, testsToRun); m_testRunner.runTests(mode, testsToRun);
} }
TestFrameworks AutotestPlugin::activeTestFrameworks()
{
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
TestFrameworks sorted;
if (!project || projectSettings(project)->useGlobalSettings()) {
sorted = Utils::filtered(TestFrameworkManager::registeredFrameworks(),
&ITestFramework::active);
} else { // we've got custom project settings
const TestProjectSettings *settings = projectSettings(project);
const QHash<ITestFramework *, bool> active = settings->activeFrameworks();
sorted = Utils::filtered(TestFrameworkManager::registeredFrameworks(),
[active](ITestFramework *framework) {
return active.value(framework, false);
});
}
return sorted;
}
void AutotestPlugin::updateMenuItemsEnabledState() void AutotestPlugin::updateMenuItemsEnabledState()
{ {
const ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); const ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();

View File

@@ -3,7 +3,7 @@
#pragma once #pragma once
#include "autotest_global.h" #include "itestframework.h"
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
@@ -45,6 +45,7 @@ public:
static TestSettings *settings(); static TestSettings *settings();
static TestProjectSettings *projectSettings(ProjectExplorer::Project *project); static TestProjectSettings *projectSettings(ProjectExplorer::Project *project);
static TestFrameworks activeTestFrameworks();
static void updateMenuItemsEnabledState(); static void updateMenuItemsEnabledState();
static void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice); static void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice);
static ChoicePair cachedChoiceFor(const QString &buildTargetKey); static ChoicePair cachedChoiceFor(const QString &buildTargetKey);

View File

@@ -299,21 +299,8 @@ QList<ITestTreeItem *> TestTreeModel::testItemsByName(const QString &testName)
void TestTreeModel::synchronizeTestFrameworks() void TestTreeModel::synchronizeTestFrameworks()
{ {
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); const TestFrameworks sorted = AutotestPlugin::activeTestFrameworks();
TestFrameworks sorted; qCDebug(LOG) << "Active frameworks sorted by priority" << sorted;
if (!project || AutotestPlugin::projectSettings(project)->useGlobalSettings()) {
sorted = Utils::filtered(TestFrameworkManager::registeredFrameworks(),
&ITestFramework::active);
qCDebug(LOG) << "Active frameworks sorted by priority" << sorted;
} else { // we've got custom project settings
const TestProjectSettings *settings = AutotestPlugin::projectSettings(project);
const QHash<ITestFramework *, bool> active = settings->activeFrameworks();
sorted = Utils::filtered(TestFrameworkManager::registeredFrameworks(),
[active](ITestFramework *framework) {
return active.value(framework, false);
});
}
const auto sortedParsers = Utils::transform(sorted, &ITestFramework::testParser); const auto sortedParsers = Utils::transform(sorted, &ITestFramework::testParser);
// pre-check to avoid further processing when frameworks are unchanged // pre-check to avoid further processing when frameworks are unchanged
TreeItem *invisibleRoot = rootItem(); TreeItem *invisibleRoot = rootItem();