diff options
author | Sergey Morozov <dev@gres.biz> | 2018-05-05 22:28:55 +0300 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2018-05-15 14:41:53 +0000 |
commit | 57edd22d11669ab9c36cb9a652643a5d5b1856ba (patch) | |
tree | 9443649c36a762a8e3405fecb41ee336e9c5d51a /src/plugins/autotest/autotestplugin.cpp | |
parent | 887a0538cdae7bb45f4d054f5c0a6d8c7b73162b (diff) |
AutoTest: Add action to run all tests from current file
Run specific test functions since one test case can be implemented in multiple files.
Task-number: QTCREATORBUG-20329
Change-Id: I07f435c264f18e9608caa5b7ee20dff2d33ee9c0
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/autotest/autotestplugin.cpp')
-rw-r--r-- | src/plugins/autotest/autotestplugin.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp index d7bb68cdec..e3b48316c7 100644 --- a/src/plugins/autotest/autotestplugin.cpp +++ b/src/plugins/autotest/autotestplugin.cpp @@ -127,6 +127,18 @@ void AutotestPlugin::initializeMenuEntries() action->setEnabled(false); menu->addAction(command); + action = new QAction(tr("Run Tests for Current &File"), this); + Utils::Icon runFileIcon = Utils::Icons::RUN_SMALL_TOOLBAR; + for (const Utils::IconMaskAndColor &maskAndColor : Icons::RUN_FILE_OVERLAY) + runFileIcon.append(maskAndColor); + action->setIcon(runFileIcon.icon()); + action->setToolTip(tr("Run Tests for Current File")); + command = ActionManager::registerAction(action, Constants::ACTION_RUN_FILE_ID); + command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+F"))); + connect(action, &QAction::triggered, this, &AutotestPlugin::onRunFileTriggered); + action->setEnabled(false); + menu->addAction(command); + action = new QAction(tr("Re&scan Tests"), this); command = ActionManager::registerAction(action, Constants::ACTION_SCAN_ID); command->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+T,Alt+S"))); @@ -219,6 +231,26 @@ void AutotestPlugin::onRunSelectedTriggered() runner->prepareToRunTests(TestRunMode::Run); } +void AutotestPlugin::onRunFileTriggered() +{ + const IDocument *document = EditorManager::currentDocument(); + if (!document) + return; + + const Utils::FileName &fileName = document->filePath(); + if (fileName.isEmpty()) + return; + + TestTreeModel *model = TestTreeModel::instance(); + const QList<TestConfiguration *> tests = model->getTestsForFile(fileName); + if (tests.isEmpty()) + return; + + TestRunner *runner = TestRunner::instance(); + runner->setSelectedTests(tests); + runner->prepareToRunTests(TestRunMode::Run); +} + void AutotestPlugin::onRunUnderCursorTriggered(TestRunMode mode) { QTextCursor cursor = Utils::Text::wordStartCursor( @@ -263,6 +295,7 @@ void AutotestPlugin::updateMenuItemsEnabledState() ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(canRun); ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(canRun); + ActionManager::command(Constants::ACTION_RUN_FILE_ID)->action()->setEnabled(canRun); ActionManager::command(Constants::ACTION_SCAN_ID)->action()->setEnabled(canScan); ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT); |