From ea86ff5eb0aa63d61729366184c00d9612dcfa97 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 15 Jun 2017 10:43:44 +0200 Subject: [PATCH] AutoTest: Avoid triggering run tests while building Disable respective actions while a build is running to avoid strange side-effects or race conditions. Change-Id: Ifc8d1c9fc9fd4d705cabd148b145708e23029dba Reviewed-by: David Schulz --- src/plugins/autotest/autotestplugin.cpp | 14 +++++++++++--- src/plugins/autotest/autotestplugin.h | 2 +- src/plugins/autotest/testnavigationwidget.cpp | 6 +++--- src/plugins/autotest/testresultspane.cpp | 15 +++++++++++++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp index 571af4ba08d..3d00400ccdc 100644 --- a/src/plugins/autotest/autotestplugin.cpp +++ b/src/plugins/autotest/autotestplugin.cpp @@ -46,8 +46,8 @@ #include #include #include - #include +#include #include #include @@ -102,6 +102,7 @@ void AutotestPlugin::initializeMenuEntries() command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+A"))); connect(action, &QAction::triggered, this, &AutotestPlugin::onRunAllTriggered); + action->setEnabled(false); menu->addAction(command); action = new QAction(tr("&Run Selected Tests"), this); @@ -109,6 +110,7 @@ void AutotestPlugin::initializeMenuEntries() command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+R"))); connect(action, &QAction::triggered, this, &AutotestPlugin::onRunSelectedTriggered); + action->setEnabled(false); menu->addAction(command); action = new QAction(tr("Re&scan Tests"), this); @@ -121,7 +123,12 @@ void AutotestPlugin::initializeMenuEntries() ActionContainer *toolsMenu = ActionManager::actionContainer(Core::Constants::M_TOOLS); toolsMenu->addMenu(menu); - connect(toolsMenu->menu(), &QMenu::aboutToShow, + using namespace ProjectExplorer; + connect(BuildManager::instance(), &BuildManager::buildStateChanged, + this, &AutotestPlugin::updateMenuItemsEnabledState); + connect(BuildManager::instance(), &BuildManager::buildQueueFinished, + this, &AutotestPlugin::updateMenuItemsEnabledState); + connect(TestTreeModel::instance(), &TestTreeModel::testTreeModelChanged, this, &AutotestPlugin::updateMenuItemsEnabledState); } @@ -176,7 +183,8 @@ void AutotestPlugin::onRunSelectedTriggered() void AutotestPlugin::updateMenuItemsEnabledState() { - const bool enabled = !TestRunner::instance()->isTestRunning() + const bool enabled = !ProjectExplorer::BuildManager::isBuilding() + && !TestRunner::instance()->isTestRunning() && TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle; const bool hasTests = TestTreeModel::instance()->hasTests(); diff --git a/src/plugins/autotest/autotestplugin.h b/src/plugins/autotest/autotestplugin.h index 8164efb21f6..7c3f0712d48 100644 --- a/src/plugins/autotest/autotestplugin.h +++ b/src/plugins/autotest/autotestplugin.h @@ -60,7 +60,7 @@ private: void updateMenuItemsEnabledState(); QList createTestObjects() const override; const QSharedPointer m_settings; - TestFrameworkManager *m_frameworkManager = 0; + TestFrameworkManager *m_frameworkManager = nullptr; }; } // namespace Internal diff --git a/src/plugins/autotest/testnavigationwidget.cpp b/src/plugins/autotest/testnavigationwidget.cpp index 6323e0d9f01..5e34c666e00 100644 --- a/src/plugins/autotest/testnavigationwidget.cpp +++ b/src/plugins/autotest/testnavigationwidget.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -113,7 +114,8 @@ TestNavigationWidget::~TestNavigationWidget() void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event) { - const bool enabled = !TestRunner::instance()->isTestRunning() + const bool enabled = !ProjectExplorer::BuildManager::isBuilding() + && !TestRunner::instance()->isTestRunning() && m_model->parser()->state() == TestCodeParser::Idle; const bool hasTests = m_model->hasTests(); @@ -170,8 +172,6 @@ void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event) connect(selectAll, &QAction::triggered, m_view, &TestTreeView::selectAll); connect(deselectAll, &QAction::triggered, m_view, &TestTreeView::deselectAll); - runAll->setEnabled(enabled && hasTests); - runSelected->setEnabled(enabled && hasTests); selectAll->setEnabled(enabled && hasTests); deselectAll->setEnabled(enabled && hasTests); rescan->setEnabled(enabled); diff --git a/src/plugins/autotest/testresultspane.cpp b/src/plugins/autotest/testresultspane.cpp index 48402bbb05a..2077f33ff00 100644 --- a/src/plugins/autotest/testresultspane.cpp +++ b/src/plugins/autotest/testresultspane.cpp @@ -33,12 +33,14 @@ #include "testtreemodel.h" #include "testcodeparser.h" +#include #include #include #include #include #include +#include #include #include @@ -482,7 +484,9 @@ void TestResultsPane::onTestRunStarted() m_testRunning = true; m_stopTestRun->setEnabled(true); m_runAll->setEnabled(false); + Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(false); m_runSelected->setEnabled(false); + Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(false); m_summaryWidget->setVisible(false); } @@ -490,8 +494,14 @@ void TestResultsPane::onTestRunFinished() { m_testRunning = false; m_stopTestRun->setEnabled(false); - m_runAll->setEnabled(true); - m_runSelected->setEnabled(true); + + const bool runEnabled = !ProjectExplorer::BuildManager::isBuilding() + && TestTreeModel::instance()->hasTests() + && TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle; + m_runAll->setEnabled(runEnabled); // TODO unify Run* actions + Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(runEnabled); + m_runSelected->setEnabled(runEnabled); + Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(runEnabled); updateSummaryLabel(); m_summaryWidget->setVisible(true); m_model->removeCurrentTestMessage(); @@ -512,6 +522,7 @@ void TestResultsPane::updateRunActions() QString whyNot; TestTreeModel *model = TestTreeModel::instance(); const bool enable = !m_testRunning && !model->parser()->isParsing() && model->hasTests() + && !ProjectExplorer::BuildManager::isBuilding() && ProjectExplorer::ProjectExplorerPlugin::canRunStartupProject( ProjectExplorer::Constants::NORMAL_RUN_MODE, &whyNot); m_runAll->setEnabled(enable);