AutoTest: Allow run after build per project

It might make more sense to be able to enable this
per project instead of globally.

Task-number: QTCREATORBUG-16704
Change-Id: I2e29d3af62c428bcbb534b72b5eb13f1fbd83973
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2019-08-08 10:58:15 +02:00
parent 51382a846d
commit d12f90047a
5 changed files with 32 additions and 1 deletions

View File

@@ -29,6 +29,7 @@
#include "testprojectsettings.h"
#include <QBoxLayout>
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QTreeWidget>
@@ -60,6 +61,9 @@ ProjectTestSettingsWidget::ProjectTestSettingsWidget(ProjectExplorer::Project *p
m_activeFrameworks->setRootIsDecorated(false);
groupBoxLayout->addWidget(new QLabel(tr("Active frameworks:")));
groupBoxLayout->addWidget(m_activeFrameworks);
m_runAfterBuild = new QCheckBox(tr("Automatically run after build"));
m_runAfterBuild->setChecked(m_projectSettings->runAfterBuild());
groupBoxLayout->addWidget(m_runAfterBuild);
generalWidget->setLayout(groupBoxLayout);
auto horizontalLayout = new QHBoxLayout;
@@ -85,6 +89,8 @@ ProjectTestSettingsWidget::ProjectTestSettingsWidget(ProjectExplorer::Project *p
});
connect(m_activeFrameworks, &QTreeWidget::itemChanged,
this, &ProjectTestSettingsWidget::onActiveFrameworkChanged);
connect(m_runAfterBuild, &QCheckBox::toggled,
m_projectSettings, &TestProjectSettings::setRunAfterBuild);
}
void ProjectTestSettingsWidget::populateFrameworks(const QMap<Core::Id, bool> &frameworks)

View File

@@ -28,6 +28,7 @@
#include <QWidget>
QT_BEGIN_NAMESPACE
class QCheckBox;
class QComboBox;
class QTreeWidget;
class QTreeWidgetItem;
@@ -53,6 +54,7 @@ private:
TestProjectSettings *m_projectSettings;
QComboBox *m_useGlobalSettings = nullptr;
QTreeWidget *m_activeFrameworks = nullptr;
QCheckBox *m_runAfterBuild = nullptr;
};
} // namespace Internal

View File

@@ -34,6 +34,7 @@ namespace Autotest {
namespace Internal {
static const char SK_ACTIVE_FRAMEWORKS[] = "AutoTest.ActiveFrameworks";
static const char SK_RUN_AFTER_BUILD[] = "AutoTest.RunAfterBuild";
TestProjectSettings::TestProjectSettings(ProjectExplorer::Project *project)
: m_project(project)
@@ -87,6 +88,9 @@ void TestProjectSettings::load()
for (const Core::Id &id : registered)
m_activeTestFrameworks.insert(id, frameworkManager->isActive(id));
}
const QVariant runAfterBuild = m_project->namedSettings(SK_RUN_AFTER_BUILD);
m_runAfterBuild = runAfterBuild.isValid() ? runAfterBuild.toBool() : false;
}
void TestProjectSettings::save()
@@ -97,6 +101,7 @@ void TestProjectSettings::save()
for (auto it = m_activeTestFrameworks.cbegin(); it != end; ++it)
activeFrameworks.insert(it.key().toString(), it.value());
m_project->setNamedSettings(SK_ACTIVE_FRAMEWORKS, activeFrameworks);
m_project->setNamedSettings(SK_RUN_AFTER_BUILD, m_runAfterBuild);
}
} // namespace Internal

View File

@@ -39,6 +39,8 @@ public:
void setUseGlobalSettings(bool useGlobal);
bool useGlobalSettings() const { return m_useGlobalSettings; }
void setRunAfterBuild(bool enabled) {m_runAfterBuild = enabled; }
bool runAfterBuild() const { return m_runAfterBuild; }
void setActiveFrameworks(const QMap<Core::Id, bool> enabledFrameworks)
{ m_activeTestFrameworks = enabledFrameworks; }
QMap<Core::Id, bool> activeFrameworks() const { return m_activeTestFrameworks; }
@@ -49,6 +51,7 @@ private:
ProjectExplorer::Project *m_project;
bool m_useGlobalSettings = true;
bool m_runAfterBuild = false;
QMap<Core::Id, bool> m_activeTestFrameworks;
};

View File

@@ -27,6 +27,7 @@
#include "autotestconstants.h"
#include "autotestplugin.h"
#include "testprojectsettings.h"
#include "testresultspane.h"
#include "testrunconfiguration.h"
#include "testsettings.h"
@@ -675,6 +676,20 @@ void TestRunner::buildFinished(bool success)
}
}
static bool runAfterBuild()
{
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
if (!project)
return false;
if (!project->namedSettings(Constants::SK_USE_GLOBAL).isValid())
return AutotestPlugin::settings()->runAfterBuild;
TestProjectSettings *projectSettings = AutotestPlugin::projectSettings(project);
return projectSettings->useGlobalSettings() ? AutotestPlugin::settings()->runAfterBuild
: projectSettings->runAfterBuild();
}
void TestRunner::onBuildQueueFinished(bool success)
{
if (m_executingTests || !m_selectedTests.isEmpty()) // paranoia!
@@ -683,7 +698,7 @@ void TestRunner::onBuildQueueFinished(bool success)
if (!success || m_runMode != TestRunMode::None)
return;
if (!AutotestPlugin::settings()->runAfterBuild)
if (!runAfterBuild())
return;
auto testTreeModel = TestTreeModel::instance();