TestRunner: Merge 2 public methods into one

Merge setSelectedTests() and prepareToRunTests() into runTests().

Change-Id: I908c41483f05eeaec186f362391941a797d66e6a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Jarek Kobus
2023-01-13 12:30:42 +01:00
parent c9f5098c07
commit fdebf0343d
4 changed files with 21 additions and 36 deletions

View File

@@ -343,14 +343,12 @@ ExtensionSystem::IPlugin::ShutdownFlag AutotestPlugin::aboutToShutdown()
void AutotestPluginPrivate::onRunAllTriggered(TestRunMode mode) void AutotestPluginPrivate::onRunAllTriggered(TestRunMode mode)
{ {
m_testRunner.setSelectedTests(m_testTreeModel.getAllTestCases()); m_testRunner.runTests(mode, m_testTreeModel.getAllTestCases());
m_testRunner.prepareToRunTests(mode);
} }
void AutotestPluginPrivate::onRunSelectedTriggered(TestRunMode mode) void AutotestPluginPrivate::onRunSelectedTriggered(TestRunMode mode)
{ {
m_testRunner.setSelectedTests(m_testTreeModel.getSelectedTests()); m_testRunner.runTests(mode, m_testTreeModel.getSelectedTests());
m_testRunner.prepareToRunTests(mode);
} }
void AutotestPluginPrivate::onRunFailedTriggered() void AutotestPluginPrivate::onRunFailedTriggered()
@@ -358,8 +356,7 @@ void AutotestPluginPrivate::onRunFailedTriggered()
const QList<ITestConfiguration *> failed = m_testTreeModel.getFailedTests(); const QList<ITestConfiguration *> failed = m_testTreeModel.getFailedTests();
if (failed.isEmpty()) // the framework might not be able to provide them if (failed.isEmpty()) // the framework might not be able to provide them
return; return;
m_testRunner.setSelectedTests(failed); m_testRunner.runTests(TestRunMode::Run, failed);
m_testRunner.prepareToRunTests(TestRunMode::Run);
} }
void AutotestPluginPrivate::onRunFileTriggered() void AutotestPluginPrivate::onRunFileTriggered()
@@ -376,8 +373,7 @@ void AutotestPluginPrivate::onRunFileTriggered()
if (tests.isEmpty()) if (tests.isEmpty())
return; return;
m_testRunner.setSelectedTests(tests); m_testRunner.runTests(TestRunMode::Run, tests);
m_testRunner.prepareToRunTests(TestRunMode::Run);
} }
static QList<ITestConfiguration *> testItemsToTestConfigurations(const QList<ITestTreeItem *> &items, static QList<ITestConfiguration *> testItemsToTestConfigurations(const QList<ITestTreeItem *> &items,
@@ -442,8 +438,7 @@ void AutotestPluginPrivate::onRunUnderCursorTriggered(TestRunMode mode)
return; return;
} }
m_testRunner.setSelectedTests(testsToRun); m_testRunner.runTests(mode, testsToRun);
m_testRunner.prepareToRunTests(mode);
} }
void AutotestPlugin::updateMenuItemsEnabledState() void AutotestPlugin::updateMenuItemsEnabledState()

View File

@@ -465,15 +465,13 @@ void TestResultsPane::onItemActivated(const QModelIndex &index)
void TestResultsPane::onRunAllTriggered() void TestResultsPane::onRunAllTriggered()
{ {
TestRunner *runner = TestRunner::instance(); TestRunner *runner = TestRunner::instance();
runner->setSelectedTests(TestTreeModel::instance()->getAllTestCases()); runner->runTests(TestRunMode::Run, TestTreeModel::instance()->getAllTestCases());
runner->prepareToRunTests(TestRunMode::Run);
} }
void TestResultsPane::onRunSelectedTriggered() void TestResultsPane::onRunSelectedTriggered()
{ {
TestRunner *runner = TestRunner::instance(); TestRunner *runner = TestRunner::instance();
runner->setSelectedTests(TestTreeModel::instance()->getSelectedTests()); runner->runTests(TestRunMode::Run, TestTreeModel::instance()->getSelectedTests());
runner->prepareToRunTests(TestRunMode::Run);
} }
void TestResultsPane::initializeFilterMenu() void TestResultsPane::initializeFilterMenu()

View File

@@ -93,23 +93,13 @@ TestRunner::~TestRunner()
s_instance = nullptr; s_instance = nullptr;
} }
void TestRunner::setSelectedTests(const QList<ITestConfiguration *> &selected)
{
QTC_ASSERT(!m_executingTests, return);
qDeleteAll(m_selectedTests);
m_selectedTests.clear();
m_selectedTests.append(selected);
}
void TestRunner::runTest(TestRunMode mode, const ITestTreeItem *item) void TestRunner::runTest(TestRunMode mode, const ITestTreeItem *item)
{ {
QTC_ASSERT(!m_executingTests, return); QTC_ASSERT(!m_executingTests, return);
ITestConfiguration *configuration = item->asConfiguration(mode); ITestConfiguration *configuration = item->asConfiguration(mode);
if (configuration) { if (configuration)
setSelectedTests({configuration}); runTests(mode, {configuration});
prepareToRunTests(mode);
}
} }
static QString processInformation(const QtcProcess *proc) static QString processInformation(const QtcProcess *proc)
@@ -346,9 +336,13 @@ void TestRunner::resetInternalPointers()
m_currentConfig = nullptr; m_currentConfig = nullptr;
} }
void TestRunner::prepareToRunTests(TestRunMode mode) void TestRunner::runTests(TestRunMode mode, const QList<ITestConfiguration *> &selectedTests)
{ {
QTC_ASSERT(!m_executingTests, return); QTC_ASSERT(!m_executingTests, return);
qDeleteAll(m_selectedTests);
m_selectedTests.clear();
m_selectedTests.append(selectedTests);
m_skipTargetsCheck = false; m_skipTargetsCheck = false;
m_runMode = mode; m_runMode = mode;
const ProjectExplorerSettings projectExplorerSettings const ProjectExplorerSettings projectExplorerSettings
@@ -504,7 +498,7 @@ void TestRunner::onBuildSystemUpdated()
} }
} }
void TestRunner::runTests() void TestRunner::runTestsHelper()
{ {
QList<ITestConfiguration *> toBeRemoved; QList<ITestConfiguration *> toBeRemoved;
bool projectChanged = false; bool projectChanged = false;
@@ -716,7 +710,7 @@ void TestRunner::runOrDebugTests()
case TestRunMode::Run: case TestRunMode::Run:
case TestRunMode::RunWithoutDeploy: case TestRunMode::RunWithoutDeploy:
case TestRunMode::RunAfterBuild: case TestRunMode::RunAfterBuild:
runTests(); runTestsHelper();
return; return;
case TestRunMode::Debug: case TestRunMode::Debug:
case TestRunMode::DebugWithoutDeploy: case TestRunMode::DebugWithoutDeploy:
@@ -789,9 +783,9 @@ void TestRunner::onBuildQueueFinished(bool success)
if (!testTreeModel->hasTests()) if (!testTreeModel->hasTests())
return; return;
setSelectedTests(mode == RunAfterBuildMode::All ? testTreeModel->getAllTestCases() const QList<ITestConfiguration *> tests = mode == RunAfterBuildMode::All
: testTreeModel->getSelectedTests()); ? testTreeModel->getAllTestCases() : testTreeModel->getSelectedTests();
prepareToRunTests(TestRunMode::RunAfterBuild); runTests(TestRunMode::RunAfterBuild, tests);
} }
void TestRunner::onFinished() void TestRunner::onFinished()

View File

@@ -42,12 +42,10 @@ public:
static TestRunner* instance(); static TestRunner* instance();
void setSelectedTests(const QList<ITestConfiguration *> &selected); void runTests(TestRunMode mode, const QList<ITestConfiguration *> &selectedTests);
void runTest(TestRunMode mode, const ITestTreeItem *item); void runTest(TestRunMode mode, const ITestTreeItem *item);
bool isTestRunning() const { return m_executingTests; } bool isTestRunning() const { return m_executingTests; }
void prepareToRunTests(TestRunMode mode);
signals: signals:
void testRunStarted(); void testRunStarted();
void testRunFinished(); void testRunFinished();
@@ -71,7 +69,7 @@ private:
void onProcessDone(); void onProcessDone();
void resetInternalPointers(); void resetInternalPointers();
void runTests(); void runTestsHelper();
void debugTests(); void debugTests();
void runOrDebugTests(); void runOrDebugTests();
void reportResult(ResultType type, const QString &description); void reportResult(ResultType type, const QString &description);