AutoTest: Unify handling of run modes

Move used enums more central to avoid duplicating
information and unify their usages.

Change-Id: I33e9bdc11f7da16ecabf03991b5a5f550a53bdad
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Christian Stenger
2017-09-05 13:57:22 +02:00
parent f885785564
commit 8288eadac6
13 changed files with 54 additions and 55 deletions

View File

@@ -45,4 +45,14 @@ const char FRAMEWORK_PREFIX[] = "AutoTest.Framework.";
const char SETTINGSPAGE_PREFIX[] = "A.AutoTest."; const char SETTINGSPAGE_PREFIX[] = "A.AutoTest.";
const char SETTINGSGROUP[] = "Autotest"; const char SETTINGSGROUP[] = "Autotest";
} // namespace Constants } // namespace Constants
namespace Internal {
enum class TestRunMode
{
Run,
RunWithoutDeploy,
Debug,
DebugWithoutDeploy
};
} // namespace Internal
} // namespace Autotest } // namespace Autotest

View File

@@ -170,7 +170,7 @@ void AutotestPlugin::onRunAllTriggered()
TestRunner *runner = TestRunner::instance(); TestRunner *runner = TestRunner::instance();
TestTreeModel *model = TestTreeModel::instance(); TestTreeModel *model = TestTreeModel::instance();
runner->setSelectedTests(model->getAllTestCases()); runner->setSelectedTests(model->getAllTestCases());
runner->prepareToRunTests(TestRunner::Run); runner->prepareToRunTests(TestRunMode::Run);
} }
void AutotestPlugin::onRunSelectedTriggered() void AutotestPlugin::onRunSelectedTriggered()
@@ -178,7 +178,7 @@ void AutotestPlugin::onRunSelectedTriggered()
TestRunner *runner = TestRunner::instance(); TestRunner *runner = TestRunner::instance();
TestTreeModel *model = TestTreeModel::instance(); TestTreeModel *model = TestTreeModel::instance();
runner->setSelectedTests(model->getSelectedTests()); runner->setSelectedTests(model->getSelectedTests());
runner->prepareToRunTests(TestRunner::Run); runner->prepareToRunTests(TestRunMode::Run);
} }
void AutotestPlugin::updateMenuItemsEnabledState() void AutotestPlugin::updateMenuItemsEnabledState()

View File

@@ -62,7 +62,7 @@ QStringList GTestConfiguration::argumentsForTestRunner() const
if (gSettings->throwOnFailure) if (gSettings->throwOnFailure)
arguments << "--gtest_throw_on_failure"; arguments << "--gtest_throw_on_failure";
if (runMode() == DebuggableTestConfiguration::Debug) { if (isDebugRunMode()) {
if (gSettings->breakOnFailure) if (gSettings->breakOnFailure)
arguments << "--gtest_break_on_failure"; arguments << "--gtest_break_on_failure";
} }

View File

@@ -115,7 +115,7 @@ TestConfiguration *GTestTreeItem::debugConfiguration() const
{ {
GTestConfiguration *config = static_cast<GTestConfiguration *>(testConfiguration()); GTestConfiguration *config = static_cast<GTestConfiguration *>(testConfiguration());
if (config) if (config)
config->setRunMode(DebuggableTestConfiguration::Debug); config->setRunMode(TestRunMode::Debug);
return config; return config;
} }

View File

@@ -73,7 +73,7 @@ QStringList QtTestConfiguration::argumentsForTestRunner() const
if (qtSettings->logSignalsSlots) if (qtSettings->logSignalsSlots)
arguments << "-vs"; arguments << "-vs";
if (runMode() == DebuggableTestConfiguration::Debug) { if (isDebugRunMode()) {
if (qtSettings->noCrashHandler) if (qtSettings->noCrashHandler)
arguments << "-nocrashhandler"; arguments << "-nocrashhandler";
} }

View File

@@ -142,7 +142,7 @@ TestConfiguration *QtTestTreeItem::debugConfiguration() const
{ {
QtTestConfiguration *config = static_cast<QtTestConfiguration *>(testConfiguration()); QtTestConfiguration *config = static_cast<QtTestConfiguration *>(testConfiguration());
if (config) if (config)
config->setRunMode(DebuggableTestConfiguration::Debug); config->setRunMode(TestRunMode::Debug);
return config; return config;
} }

View File

@@ -26,7 +26,6 @@
#include "testconfiguration.h" #include "testconfiguration.h"
#include "testoutputreader.h" #include "testoutputreader.h"
#include "testrunconfiguration.h" #include "testrunconfiguration.h"
#include "testrunner.h"
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <cpptools/projectinfo.h> #include <cpptools/projectinfo.h>
@@ -73,7 +72,7 @@ static QString ensureExeEnding(const QString& file)
return Utils::HostOsInfo::withExecutableSuffix(file); return Utils::HostOsInfo::withExecutableSuffix(file);
} }
void TestConfiguration::completeTestInformation(int runMode) void TestConfiguration::completeTestInformation(TestRunMode runMode)
{ {
QTC_ASSERT(!m_projectFile.isEmpty(), return); QTC_ASSERT(!m_projectFile.isEmpty(), return);
QTC_ASSERT(!m_buildTargets.isEmpty(), return); QTC_ASSERT(!m_buildTargets.isEmpty(), return);
@@ -158,7 +157,7 @@ void TestConfiguration::completeTestInformation(int runMode)
m_runnable.executable = currentExecutable; m_runnable.executable = currentExecutable;
m_displayName = runConfig->displayName(); m_displayName = runConfig->displayName();
m_project = project; m_project = project;
if (runMode == TestRunner::Debug) if (runMode == TestRunMode::Debug || runMode == TestRunMode::DebugWithoutDeploy)
m_runConfig = new TestRunConfiguration(runConfig->target(), this); m_runConfig = new TestRunConfiguration(runConfig->target(), this);
break; break;
} }
@@ -182,7 +181,7 @@ void TestConfiguration::completeTestInformation(int runMode)
m_project = project; m_project = project;
m_guessedConfiguration = true; m_guessedConfiguration = true;
m_guessedFrom = rc->displayName(); m_guessedFrom = rc->displayName();
if (runMode == TestRunner::Debug) if (runMode == TestRunMode::Debug)
m_runConfig = new TestRunConfiguration(rc->target(), this); m_runConfig = new TestRunConfiguration(rc->target(), this);
} }
} else { } else {
@@ -291,5 +290,10 @@ QString TestConfiguration::workingDirectory() const
return executable.isEmpty() ? executable : QFileInfo(executable).absolutePath(); return executable.isEmpty() ? executable : QFileInfo(executable).absolutePath();
} }
bool DebuggableTestConfiguration::isDebugRunMode() const
{
return m_runMode == TestRunMode::Debug || m_runMode == TestRunMode::DebugWithoutDeploy;
}
} // namespace Internal } // namespace Internal
} // namespace Autotest } // namespace Autotest

View File

@@ -50,13 +50,12 @@ class TestRunConfiguration;
using TestResultPtr = QSharedPointer<TestResult>; using TestResultPtr = QSharedPointer<TestResult>;
class TestConfiguration class TestConfiguration
{ {
public: public:
explicit TestConfiguration(); explicit TestConfiguration();
virtual ~TestConfiguration(); virtual ~TestConfiguration();
void completeTestInformation(int runMode); void completeTestInformation(TestRunMode runMode);
void setTestCases(const QStringList &testCases); void setTestCases(const QStringList &testCases);
void setTestCaseCount(int count); void setTestCaseCount(int count);
@@ -104,21 +103,15 @@ private:
class DebuggableTestConfiguration : public TestConfiguration class DebuggableTestConfiguration : public TestConfiguration
{ {
public: public:
enum RunMode explicit DebuggableTestConfiguration(TestRunMode runMode = TestRunMode::Run)
{ : m_runMode(runMode) {}
Run,
Debug
};
explicit DebuggableTestConfiguration(RunMode runMode = Run) : m_runMode(runMode) {}
~DebuggableTestConfiguration() {} ~DebuggableTestConfiguration() {}
void setRunMode(RunMode mode) { m_runMode = mode; } void setRunMode(TestRunMode mode) { m_runMode = mode; }
RunMode runMode() const { return m_runMode; } TestRunMode runMode() const { return m_runMode; }
bool isDebugRunMode() const;
private: private:
RunMode m_runMode; TestRunMode m_runMode;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -136,13 +136,13 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
runThisTest->setEnabled(enabled); runThisTest->setEnabled(enabled);
connect(runThisTest, &QAction::triggered, connect(runThisTest, &QAction::triggered,
this, [this] () { this, [this] () {
onRunThisTestTriggered(TestRunner::Run); onRunThisTestTriggered(TestRunMode::Run);
}); });
runWithoutDeploy = new QAction(tr("Run Without Deployment"), &menu); runWithoutDeploy = new QAction(tr("Run Without Deployment"), &menu);
runWithoutDeploy->setEnabled(enabled); runWithoutDeploy->setEnabled(enabled);
connect(runWithoutDeploy, &QAction::triggered, connect(runWithoutDeploy, &QAction::triggered,
this, [this] () { this, [this] () {
onRunThisTestTriggered(TestRunner::RunWithoutDeploy); onRunThisTestTriggered(TestRunMode::RunWithoutDeploy);
}); });
} }
if (item->canProvideDebugConfiguration()) { if (item->canProvideDebugConfiguration()) {
@@ -150,13 +150,13 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
debugThisTest->setEnabled(enabled); debugThisTest->setEnabled(enabled);
connect(debugThisTest, &QAction::triggered, connect(debugThisTest, &QAction::triggered,
this, [this] () { this, [this] () {
onRunThisTestTriggered(TestRunner::Debug); onRunThisTestTriggered(TestRunMode::Debug);
}); });
debugWithoutDeploy = new QAction(tr("Debug Without Deployment"), &menu); debugWithoutDeploy = new QAction(tr("Debug Without Deployment"), &menu);
debugWithoutDeploy->setEnabled(enabled); debugWithoutDeploy->setEnabled(enabled);
connect(debugWithoutDeploy, &QAction::triggered, connect(debugWithoutDeploy, &QAction::triggered,
this, [this] () { this, [this] () {
onRunThisTestTriggered(TestRunner::DebugWithoutDeploy); onRunThisTestTriggered(TestRunMode::DebugWithoutDeploy);
}); });
} }
} }
@@ -291,7 +291,7 @@ void TestNavigationWidget::initializeFilterMenu()
m_filterMenu->addAction(action); m_filterMenu->addAction(action);
} }
void TestNavigationWidget::onRunThisTestTriggered(TestRunner::Mode runMode) void TestNavigationWidget::onRunThisTestTriggered(TestRunMode runMode)
{ {
const QModelIndexList selected = m_view->selectionModel()->selectedIndexes(); const QModelIndexList selected = m_view->selectionModel()->selectedIndexes();
if (selected.isEmpty()) if (selected.isEmpty())
@@ -303,12 +303,12 @@ void TestNavigationWidget::onRunThisTestTriggered(TestRunner::Mode runMode)
TestTreeItem *item = static_cast<TestTreeItem *>(sourceIndex.internalPointer()); TestTreeItem *item = static_cast<TestTreeItem *>(sourceIndex.internalPointer());
TestConfiguration *configuration; TestConfiguration *configuration;
switch (runMode) { switch (runMode) {
case TestRunner::Run: case TestRunMode::Run:
case TestRunner::RunWithoutDeploy: case TestRunMode::RunWithoutDeploy:
configuration = item->testConfiguration(); configuration = item->testConfiguration();
break; break;
case TestRunner::Debug: case TestRunMode::Debug:
case TestRunner::DebugWithoutDeploy: case TestRunMode::DebugWithoutDeploy:
configuration = item->debugConfiguration(); configuration = item->debugConfiguration();
break; break;
default: default:

View File

@@ -72,7 +72,7 @@ private:
void onParsingStarted(); void onParsingStarted();
void onParsingFinished(); void onParsingFinished();
void initializeFilterMenu(); void initializeFilterMenu();
void onRunThisTestTriggered(TestRunner::Mode runMode); void onRunThisTestTriggered(TestRunMode runMode);
TestTreeModel *m_model; TestTreeModel *m_model;
TestTreeSortFilterModel *m_sortFilterModel; TestTreeSortFilterModel *m_sortFilterModel;

View File

@@ -423,14 +423,14 @@ void TestResultsPane::onRunAllTriggered()
{ {
TestRunner *runner = TestRunner::instance(); TestRunner *runner = TestRunner::instance();
runner->setSelectedTests(TestTreeModel::instance()->getAllTestCases()); runner->setSelectedTests(TestTreeModel::instance()->getAllTestCases());
runner->prepareToRunTests(TestRunner::Run); runner->prepareToRunTests(TestRunMode::Run);
} }
void TestResultsPane::onRunSelectedTriggered() void TestResultsPane::onRunSelectedTriggered()
{ {
TestRunner *runner = TestRunner::instance(); TestRunner *runner = TestRunner::instance();
runner->setSelectedTests(TestTreeModel::instance()->getSelectedTests()); runner->setSelectedTests(TestTreeModel::instance()->getSelectedTests());
runner->prepareToRunTests(TestRunner::Run); runner->prepareToRunTests(TestRunMode::Run);
} }
void TestResultsPane::initializeFilterMenu() void TestResultsPane::initializeFilterMenu()

View File

@@ -127,7 +127,7 @@ static void performTestRun(QFutureInterface<TestResultPtr> &futureInterface,
QEventLoop eventLoop; QEventLoop eventLoop;
int testCaseCount = 0; int testCaseCount = 0;
for (TestConfiguration *config : selectedTests) { for (TestConfiguration *config : selectedTests) {
config->completeTestInformation(TestRunner::Run); config->completeTestInformation(TestRunMode::Run);
if (config->project()) { if (config->project()) {
testCaseCount += config->testCaseCount(); testCaseCount += config->testCaseCount();
if (!omitRunConfigWarnings && config->isGuessed()) { if (!omitRunConfigWarnings && config->isGuessed()) {
@@ -224,7 +224,7 @@ static void performTestRun(QFutureInterface<TestResultPtr> &futureInterface,
futureInterface.setProgressValue(testCaseCount); futureInterface.setProgressValue(testCaseCount);
} }
void TestRunner::prepareToRunTests(Mode mode) void TestRunner::prepareToRunTests(TestRunMode mode)
{ {
m_runMode = mode; m_runMode = mode;
ProjectExplorer::Internal::ProjectExplorerSettings projectExplorerSettings = ProjectExplorer::Internal::ProjectExplorerSettings projectExplorerSettings =
@@ -257,8 +257,8 @@ void TestRunner::prepareToRunTests(Mode mode)
return; return;
} }
if (!projectExplorerSettings.buildBeforeDeploy || mode == TestRunner::DebugWithoutDeploy if (!projectExplorerSettings.buildBeforeDeploy || mode == TestRunMode::DebugWithoutDeploy
|| mode == TestRunner::RunWithoutDeploy) { || mode == TestRunMode::RunWithoutDeploy) {
runOrDebugTests(); runOrDebugTests();
} else if (project->hasActiveBuildSettings()) { } else if (project->hasActiveBuildSettings()) {
buildProject(project); buildProject(project);
@@ -311,7 +311,7 @@ void TestRunner::debugTests()
QTC_ASSERT(m_selectedTests.size() == 1, onFinished();return); QTC_ASSERT(m_selectedTests.size() == 1, onFinished();return);
TestConfiguration *config = m_selectedTests.first(); TestConfiguration *config = m_selectedTests.first();
config->completeTestInformation(Debug); config->completeTestInformation(TestRunMode::Debug);
if (!config->runConfiguration()) { if (!config->runConfiguration()) {
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal, emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
TestRunner::tr("Failed to get run configuration.")))); TestRunner::tr("Failed to get run configuration."))));
@@ -387,12 +387,12 @@ void TestRunner::debugTests()
void TestRunner::runOrDebugTests() void TestRunner::runOrDebugTests()
{ {
switch (m_runMode) { switch (m_runMode) {
case Run: case TestRunMode::Run:
case RunWithoutDeploy: case TestRunMode::RunWithoutDeploy:
runTests(); runTests();
break; break;
case Debug: case TestRunMode::Debug:
case DebugWithoutDeploy: case TestRunMode::DebugWithoutDeploy:
debugTests(); debugTests();
break; break;
default: default:

View File

@@ -44,21 +44,13 @@ class TestRunner : public QObject
Q_OBJECT Q_OBJECT
public: public:
enum Mode
{
Run,
RunWithoutDeploy,
Debug,
DebugWithoutDeploy
};
static TestRunner* instance(); static TestRunner* instance();
~TestRunner(); ~TestRunner();
void setSelectedTests(const QList<TestConfiguration *> &selected); void setSelectedTests(const QList<TestConfiguration *> &selected);
bool isTestRunning() const { return m_executingTests; } bool isTestRunning() const { return m_executingTests; }
void prepareToRunTests(Mode mode); void prepareToRunTests(TestRunMode mode);
signals: signals:
void testRunStarted(); void testRunStarted();
@@ -79,7 +71,7 @@ private:
QFutureWatcher<TestResultPtr> m_futureWatcher; QFutureWatcher<TestResultPtr> m_futureWatcher;
QList<TestConfiguration *> m_selectedTests; QList<TestConfiguration *> m_selectedTests;
bool m_executingTests; bool m_executingTests;
Mode m_runMode = Run; TestRunMode m_runMode = TestRunMode::Run;
// temporarily used if building before running is necessary // temporarily used if building before running is necessary
QMetaObject::Connection m_buildConnect; QMetaObject::Connection m_buildConnect;