diff options
author | Christian Stenger <christian.stenger@qt.io> | 2019-08-08 09:57:42 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2019-09-02 07:08:38 +0000 |
commit | 51382a846d284f3b4239f4678bde060969a6b507 (patch) | |
tree | 81a55f7b0c47591e72c7b9821acb0d7e2d4db521 /src/plugins/autotest | |
parent | 43e27f76b3ac96ae4d13e5410be28831ffdbb059 (diff) | |
download | qt-creator-51382a846d284f3b4239f4678bde060969a6b507.tar.gz |
AutoTest: Add automatic run after build
Add an option to automatically run tests if the build
succeeded and the current project has tests.
Change-Id: I1fe028be84279b9b488f78590565c6d4b0449e34
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r-- | src/plugins/autotest/autotestconstants.h | 4 | ||||
-rw-r--r-- | src/plugins/autotest/testrunner.cpp | 34 | ||||
-rw-r--r-- | src/plugins/autotest/testrunner.h | 3 | ||||
-rw-r--r-- | src/plugins/autotest/testsettings.cpp | 3 | ||||
-rw-r--r-- | src/plugins/autotest/testsettings.h | 1 | ||||
-rw-r--r-- | src/plugins/autotest/testsettingspage.cpp | 2 | ||||
-rw-r--r-- | src/plugins/autotest/testsettingspage.ui | 10 | ||||
-rw-r--r-- | src/plugins/autotest/testtreeitem.cpp | 2 |
8 files changed, 54 insertions, 5 deletions
diff --git a/src/plugins/autotest/autotestconstants.h b/src/plugins/autotest/autotestconstants.h index 9d4ea135b3..0f589b56aa 100644 --- a/src/plugins/autotest/autotestconstants.h +++ b/src/plugins/autotest/autotestconstants.h @@ -53,10 +53,12 @@ const char SK_USE_GLOBAL[] = "AutoTest.UseGlobal"; namespace Internal { enum class TestRunMode { + None, Run, RunWithoutDeploy, Debug, - DebugWithoutDeploy + DebugWithoutDeploy, + RunAfterBuild }; } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/testrunner.cpp b/src/plugins/autotest/testrunner.cpp index 2260a4c289..6f03d9e764 100644 --- a/src/plugins/autotest/testrunner.cpp +++ b/src/plugins/autotest/testrunner.cpp @@ -32,6 +32,7 @@ #include "testsettings.h" #include "testoutputreader.h" #include "testtreeitem.h" +#include "testtreemodel.h" #include <coreplugin/icore.h> #include <coreplugin/progressmanager/futureprogress.h> @@ -95,6 +96,9 @@ TestRunner::TestRunner(QObject *parent) : cancelCurrent(UserCanceled); reportResult(ResultType::MessageFatal, tr("Test run canceled by user.")); }); + connect(ProjectExplorer::BuildManager::instance(), + &ProjectExplorer::BuildManager::buildQueueFinished, + this, &TestRunner::onBuildQueueFinished); } TestRunner::~TestRunner() @@ -308,7 +312,8 @@ void TestRunner::prepareToRunTests(TestRunMode mode) m_runMode = mode; ProjectExplorer::Internal::ProjectExplorerSettings projectExplorerSettings = ProjectExplorer::ProjectExplorerPlugin::projectExplorerSettings(); - if (projectExplorerSettings.buildBeforeDeploy && !projectExplorerSettings.saveBeforeBuild) { + if (mode != TestRunMode::RunAfterBuild && + projectExplorerSettings.buildBeforeDeploy && !projectExplorerSettings.saveBeforeBuild) { if (!ProjectExplorer::ProjectExplorerPlugin::saveModifiedFiles()) return; } @@ -340,7 +345,7 @@ void TestRunner::prepareToRunTests(TestRunMode mode) [this]() { cancelCurrent(KitChanged); }); if (!projectExplorerSettings.buildBeforeDeploy || mode == TestRunMode::DebugWithoutDeploy - || mode == TestRunMode::RunWithoutDeploy) { + || mode == TestRunMode::RunWithoutDeploy || mode == TestRunMode::RunAfterBuild) { runOrDebugTests(); return; } @@ -626,15 +631,18 @@ void TestRunner::runOrDebugTests() switch (m_runMode) { case TestRunMode::Run: case TestRunMode::RunWithoutDeploy: + case TestRunMode::RunAfterBuild: runTests(); return; case TestRunMode::Debug: case TestRunMode::DebugWithoutDeploy: debugTests(); return; + default: + break; } + QTC_ASSERT(false, qDebug() << "Unexpected run mode" << int(m_runMode)); // unexpected run mode onFinished(); - QTC_ASSERT(false, return); // unexpected run mode } void TestRunner::buildProject(ProjectExplorer::Project *project) @@ -667,6 +675,25 @@ void TestRunner::buildFinished(bool success) } } +void TestRunner::onBuildQueueFinished(bool success) +{ + if (m_executingTests || !m_selectedTests.isEmpty()) // paranoia! + return; + + if (!success || m_runMode != TestRunMode::None) + return; + + if (!AutotestPlugin::settings()->runAfterBuild) + return; + + auto testTreeModel = TestTreeModel::instance(); + if (!testTreeModel->hasTests()) + return; + + setSelectedTests(testTreeModel->getAllTestCases()); + prepareToRunTests(TestRunMode::RunAfterBuild); +} + void TestRunner::onFinished() { // if we've been canceled and we still have test configurations queued just throw them away @@ -676,6 +703,7 @@ void TestRunner::onFinished() disconnect(m_stopDebugConnect); disconnect(m_targetConnect); m_fakeFutureInterface = nullptr; + m_runMode = TestRunMode::None; m_executingTests = false; emit testRunFinished(); } diff --git a/src/plugins/autotest/testrunner.h b/src/plugins/autotest/testrunner.h index 5628a6d29e..185bfa0db5 100644 --- a/src/plugins/autotest/testrunner.h +++ b/src/plugins/autotest/testrunner.h @@ -76,6 +76,7 @@ signals: private: void buildProject(ProjectExplorer::Project *project); void buildFinished(bool success); + void onBuildQueueFinished(bool success); void onFinished(); int precheckTestConfigurations(); @@ -98,7 +99,7 @@ private: TestConfiguration *m_currentConfig = nullptr; QProcess *m_currentProcess = nullptr; TestOutputReader *m_currentOutputReader = nullptr; - TestRunMode m_runMode = TestRunMode::Run; + TestRunMode m_runMode = TestRunMode::None; // temporarily used if building before running is necessary QMetaObject::Connection m_buildConnect; diff --git a/src/plugins/autotest/testsettings.cpp b/src/plugins/autotest/testsettings.cpp index ddb4f49e81..48a447ff2c 100644 --- a/src/plugins/autotest/testsettings.cpp +++ b/src/plugins/autotest/testsettings.cpp @@ -44,6 +44,7 @@ static const char displayApplicationKey[] = "DisplayApp"; static const char popupOnStartKey[] = "PopupOnStart"; static const char popupOnFinishKey[] = "PopupOnFinish"; static const char popupOnFailKey[] = "PopupOnFail"; +static const char runAfterBuildKey[] = "RunAfterBuild"; static const char groupSuffix[] = ".group"; constexpr int defaultTimeout = 60000; @@ -66,6 +67,7 @@ void TestSettings::toSettings(QSettings *s) const s->setValue(popupOnStartKey, popupOnStart); s->setValue(popupOnFinishKey, popupOnFinish); s->setValue(popupOnFailKey, popupOnFail); + s->setValue(runAfterBuildKey, runAfterBuild); // store frameworks and their current active and grouping state for (const Core::Id &id : frameworks.keys()) { s->setValue(QLatin1String(id.name()), frameworks.value(id)); @@ -87,6 +89,7 @@ void TestSettings::fromSettings(QSettings *s) popupOnStart = s->value(popupOnStartKey, true).toBool(); popupOnFinish = s->value(popupOnFinishKey, true).toBool(); popupOnFail = s->value(popupOnFailKey, false).toBool(); + runAfterBuild = s->value(runAfterBuildKey, false).toBool(); // try to get settings for registered frameworks TestFrameworkManager *frameworkManager = TestFrameworkManager::instance(); const QList<Core::Id> ®istered = frameworkManager->registeredFrameworkIds(); diff --git a/src/plugins/autotest/testsettings.h b/src/plugins/autotest/testsettings.h index 92c4ef9933..58a5492ad0 100644 --- a/src/plugins/autotest/testsettings.h +++ b/src/plugins/autotest/testsettings.h @@ -52,6 +52,7 @@ struct TestSettings bool popupOnStart = true; bool popupOnFinish = true; bool popupOnFail = false; + bool runAfterBuild = false; QHash<Core::Id, bool> frameworks; QHash<Core::Id, bool> frameworksGrouping; }; diff --git a/src/plugins/autotest/testsettingspage.cpp b/src/plugins/autotest/testsettingspage.cpp index 505c30b754..6cf848b1b0 100644 --- a/src/plugins/autotest/testsettingspage.cpp +++ b/src/plugins/autotest/testsettingspage.cpp @@ -69,6 +69,7 @@ void TestSettingsWidget::setSettings(const TestSettings &settings) m_ui.openResultsOnStartCB->setChecked(settings.popupOnStart); m_ui.openResultsOnFinishCB->setChecked(settings.popupOnFinish); m_ui.openResultsOnFailCB->setChecked(settings.popupOnFail); + m_ui.runAfterBuildCB->setChecked(settings.runAfterBuild); populateFrameworksListWidget(settings.frameworks); } @@ -85,6 +86,7 @@ TestSettings TestSettingsWidget::settings() const result.popupOnStart = m_ui.openResultsOnStartCB->isChecked(); result.popupOnFinish = m_ui.openResultsOnFinishCB->isChecked(); result.popupOnFail = m_ui.openResultsOnFailCB->isChecked(); + result.runAfterBuild = m_ui.runAfterBuildCB->isChecked(); frameworkSettings(result); return result; } diff --git a/src/plugins/autotest/testsettingspage.ui b/src/plugins/autotest/testsettingspage.ui index cb65055bc3..68689a35cf 100644 --- a/src/plugins/autotest/testsettingspage.ui +++ b/src/plugins/autotest/testsettingspage.ui @@ -145,6 +145,16 @@ Warning: this is an experimental feature and might lead to failing to execute th </widget> </item> <item> + <widget class="QCheckBox" name="runAfterBuildCB"> + <property name="toolTip"> + <string>Runs all tests automatically if a build succeeded.</string> + </property> + <property name="text"> + <string>Automatically run after build</string> + </property> + </widget> + </item> + <item> <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0"> <property name="spacing"> <number>6</number> diff --git a/src/plugins/autotest/testtreeitem.cpp b/src/plugins/autotest/testtreeitem.cpp index bc3c4f16be..3559ae2035 100644 --- a/src/plugins/autotest/testtreeitem.cpp +++ b/src/plugins/autotest/testtreeitem.cpp @@ -245,6 +245,8 @@ TestConfiguration *TestTreeItem::asConfiguration(TestRunMode mode) const case TestRunMode::Debug: case TestRunMode::DebugWithoutDeploy: return debugConfiguration(); + default: + break; } return nullptr; } |