2014-10-07 12:30:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-10-07 12:30:54 +02:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-22 10:37:55 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "autotestplugin.h"
|
2020-10-09 13:07:55 +02:00
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
#include "autotestconstants.h"
|
2017-12-04 10:11:19 +01:00
|
|
|
#include "autotesticons.h"
|
2019-08-05 15:47:10 +02:00
|
|
|
#include "projectsettingswidget.h"
|
2015-02-16 13:17:53 +01:00
|
|
|
#include "testcodeparser.h"
|
2016-06-01 16:22:50 +02:00
|
|
|
#include "testframeworkmanager.h"
|
2020-10-09 13:07:55 +02:00
|
|
|
#include "testnavigationwidget.h"
|
2019-08-05 15:47:10 +02:00
|
|
|
#include "testprojectsettings.h"
|
2020-10-09 13:07:55 +02:00
|
|
|
#include "testresultspane.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
#include "testrunner.h"
|
2014-12-04 14:05:19 +01:00
|
|
|
#include "testsettings.h"
|
|
|
|
|
#include "testsettingspage.h"
|
2015-02-13 15:44:18 +01:00
|
|
|
#include "testtreeitem.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
#include "testtreemodel.h"
|
2020-10-09 13:07:55 +02:00
|
|
|
#include "testtreeview.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2018-12-07 10:00:23 +01:00
|
|
|
#include "boost/boosttestframework.h"
|
2019-01-02 16:11:44 +01:00
|
|
|
#include "catch/catchframework.h"
|
2020-10-19 14:47:45 +02:00
|
|
|
#include "ctest/ctesttool.h"
|
2020-10-09 13:07:55 +02:00
|
|
|
#include "gtest/gtestframework.h"
|
|
|
|
|
#include "qtest/qttestframework.h"
|
|
|
|
|
#include "quick/quicktestframework.h"
|
2016-06-01 16:22:50 +02:00
|
|
|
|
2017-12-04 10:11:19 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2020-10-09 13:07:55 +02:00
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2018-02-16 17:57:37 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
|
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
2014-10-28 13:02:34 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2017-06-15 10:43:44 +02:00
|
|
|
#include <projectexplorer/buildmanager.h>
|
2020-10-09 13:07:55 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2017-12-04 10:11:19 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2018-02-16 17:57:37 +01:00
|
|
|
#include <projectexplorer/projectexplorericons.h>
|
2019-08-05 15:47:10 +02:00
|
|
|
#include <projectexplorer/projectpanelfactory.h>
|
2020-10-09 13:07:55 +02:00
|
|
|
#include <projectexplorer/runcontrol.h>
|
2018-04-06 09:24:48 +02:00
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2018-10-11 12:45:13 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
2020-10-09 13:07:55 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2018-02-16 17:57:37 +01:00
|
|
|
#include <utils/textutils.h>
|
2017-12-04 10:11:19 +01:00
|
|
|
#include <utils/utilsicons.h>
|
2014-10-28 13:02:34 +01:00
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <QAction>
|
2018-02-16 17:57:37 +01:00
|
|
|
#include <QList>
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <QMainWindow>
|
2020-10-09 13:07:55 +02:00
|
|
|
#include <QMap>
|
2014-10-07 12:30:54 +02:00
|
|
|
#include <QMenu>
|
2020-10-09 13:07:55 +02:00
|
|
|
#include <QMessageBox>
|
2018-02-16 17:57:37 +01:00
|
|
|
#include <QTextCursor>
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2015-02-10 14:20:43 +01:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
#include "autotestunittests.h"
|
2021-04-28 15:59:18 +02:00
|
|
|
#include "loadprojectscenario.h"
|
2015-02-10 14:20:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
2015-03-30 07:47:07 +02:00
|
|
|
using namespace Core;
|
2014-10-07 12:30:54 +02:00
|
|
|
|
2019-08-19 09:33:14 +02:00
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class AutotestPluginPrivate : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2020-03-05 08:35:01 +01:00
|
|
|
AutotestPluginPrivate();
|
2019-08-19 09:33:14 +02:00
|
|
|
~AutotestPluginPrivate() override;
|
|
|
|
|
|
2021-01-26 16:41:28 +01:00
|
|
|
TestNavigationWidgetFactory m_navigationWidgetFactory;
|
2019-08-19 09:33:14 +02:00
|
|
|
TestResultsPane *m_resultsPane = nullptr;
|
|
|
|
|
QMap<QString, ChoicePair> m_runconfigCache;
|
|
|
|
|
|
|
|
|
|
void initializeMenuEntries();
|
|
|
|
|
void onRunAllTriggered();
|
|
|
|
|
void onRunSelectedTriggered();
|
2020-09-11 09:44:21 +02:00
|
|
|
void onRunFailedTriggered();
|
2019-08-19 09:33:14 +02:00
|
|
|
void onRunFileTriggered();
|
|
|
|
|
void onRunUnderCursorTriggered(TestRunMode mode);
|
2020-02-28 12:27:13 +01:00
|
|
|
|
|
|
|
|
TestSettings m_settings;
|
|
|
|
|
TestSettingsPage m_testSettingPage{&m_settings};
|
2020-03-16 12:59:23 +01:00
|
|
|
|
|
|
|
|
TestCodeParser m_testCodeParser;
|
|
|
|
|
TestTreeModel m_testTreeModel{&m_testCodeParser};
|
2020-03-26 09:21:25 +01:00
|
|
|
TestRunner m_testRunner;
|
|
|
|
|
TestFrameworkManager m_frameworkManager;
|
2021-04-28 15:59:18 +02:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
LoadProjectScenario m_loadProjectScenario{&m_testTreeModel};
|
|
|
|
|
#endif
|
2019-08-19 09:33:14 +02:00
|
|
|
};
|
|
|
|
|
|
2020-02-28 12:27:13 +01:00
|
|
|
static AutotestPluginPrivate *dd = nullptr;
|
2019-08-05 15:47:10 +02:00
|
|
|
static QHash<ProjectExplorer::Project *, TestProjectSettings *> s_projectSettings;
|
2014-12-04 14:05:19 +01:00
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
AutotestPlugin::AutotestPlugin()
|
|
|
|
|
{
|
2015-01-08 12:51:01 +01:00
|
|
|
// needed to be used in QueuedConnection connects
|
|
|
|
|
qRegisterMetaType<TestResult>();
|
2015-09-07 14:44:45 +02:00
|
|
|
qRegisterMetaType<TestTreeItem *>();
|
2015-02-13 15:44:18 +01:00
|
|
|
qRegisterMetaType<TestCodeLocationAndType>();
|
2020-08-17 17:41:42 +02:00
|
|
|
// warm up meta type system to be able to read Qt::CheckState with persistent settings
|
|
|
|
|
qRegisterMetaType<Qt::CheckState>();
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutotestPlugin::~AutotestPlugin()
|
2019-08-19 09:33:14 +02:00
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
delete dd;
|
2020-03-16 12:59:23 +01:00
|
|
|
dd = nullptr;
|
2019-08-19 09:33:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-05 08:35:01 +01:00
|
|
|
AutotestPluginPrivate::AutotestPluginPrivate()
|
2019-08-19 09:33:14 +02:00
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
dd = this; // Needed as the code below access it via the static plugin interface
|
2019-08-19 09:33:14 +02:00
|
|
|
initializeMenuEntries();
|
2020-03-26 09:21:25 +01:00
|
|
|
m_frameworkManager.registerTestFramework(new QtTestFramework);
|
|
|
|
|
m_frameworkManager.registerTestFramework(new QuickTestFramework);
|
|
|
|
|
m_frameworkManager.registerTestFramework(new GTestFramework);
|
|
|
|
|
m_frameworkManager.registerTestFramework(new BoostTestFramework);
|
2019-01-02 16:11:44 +01:00
|
|
|
m_frameworkManager.registerTestFramework(new CatchFramework);
|
2019-08-19 09:33:14 +02:00
|
|
|
|
2020-10-19 14:47:45 +02:00
|
|
|
m_frameworkManager.registerTestTool(new CTestTool);
|
|
|
|
|
|
2020-03-26 09:21:25 +01:00
|
|
|
m_frameworkManager.synchronizeSettings(ICore::settings());
|
2019-08-19 09:33:14 +02:00
|
|
|
m_resultsPane = TestResultsPane::instance();
|
|
|
|
|
|
|
|
|
|
auto panelFactory = new ProjectExplorer::ProjectPanelFactory();
|
|
|
|
|
panelFactory->setPriority(666);
|
|
|
|
|
// panelFactory->setIcon(); // TODO ?
|
|
|
|
|
panelFactory->setDisplayName(tr("Testing"));
|
|
|
|
|
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {
|
|
|
|
|
return new ProjectTestSettingsWidget(project);
|
|
|
|
|
});
|
|
|
|
|
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
|
|
|
|
|
|
2020-10-19 14:46:21 +02:00
|
|
|
TestFrameworkManager::activateFrameworksAndToolsFromSettings(&m_settings);
|
2020-03-16 12:59:23 +01:00
|
|
|
m_testTreeModel.synchronizeTestFrameworks();
|
2020-10-19 14:46:21 +02:00
|
|
|
m_testTreeModel.synchronizeTestTools();
|
2019-08-19 09:33:14 +02:00
|
|
|
|
2020-03-05 13:31:31 +01:00
|
|
|
auto sessionManager = ProjectExplorer::SessionManager::instance();
|
|
|
|
|
connect(sessionManager, &ProjectExplorer::SessionManager::startupProjectChanged,
|
|
|
|
|
this, [this] { m_runconfigCache.clear(); });
|
|
|
|
|
|
|
|
|
|
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject,
|
2020-04-23 16:47:25 +02:00
|
|
|
this, [] (ProjectExplorer::Project *project) {
|
2020-03-05 13:31:31 +01:00
|
|
|
auto it = s_projectSettings.find(project);
|
|
|
|
|
if (it != s_projectSettings.end()) {
|
|
|
|
|
delete it.value();
|
|
|
|
|
s_projectSettings.erase(it);
|
|
|
|
|
}
|
2019-08-19 09:33:14 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutotestPluginPrivate::~AutotestPluginPrivate()
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2020-03-05 13:31:31 +01:00
|
|
|
if (!s_projectSettings.isEmpty()) {
|
2020-11-16 20:13:45 +01:00
|
|
|
qDeleteAll(s_projectSettings);
|
2020-03-05 13:31:31 +01:00
|
|
|
s_projectSettings.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 09:17:56 +01:00
|
|
|
delete m_resultsPane;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-28 12:27:13 +01:00
|
|
|
TestSettings *AutotestPlugin::settings()
|
2014-12-04 14:05:19 +01:00
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
return &dd->m_settings;
|
2015-01-06 15:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 15:47:10 +02:00
|
|
|
TestProjectSettings *AutotestPlugin::projectSettings(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
auto &settings = s_projectSettings[project];
|
|
|
|
|
if (!settings)
|
|
|
|
|
settings = new TestProjectSettings(project);
|
|
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 09:33:14 +02:00
|
|
|
void AutotestPluginPrivate::initializeMenuEntries()
|
2014-12-19 11:25:05 +01:00
|
|
|
{
|
2015-03-30 07:47:07 +02:00
|
|
|
ActionContainer *menu = ActionManager::createMenu(Constants::MENU_ID);
|
2016-01-24 09:03:45 +02:00
|
|
|
menu->menu()->setTitle(tr("&Tests"));
|
2016-10-25 14:30:51 +02:00
|
|
|
menu->setOnAllDisabledBehavior(ActionContainer::Show);
|
2015-03-30 07:47:07 +02:00
|
|
|
|
|
|
|
|
QAction *action = new QAction(tr("Run &All Tests"), this);
|
2020-12-04 14:29:20 +01:00
|
|
|
action->setIcon(Utils::Icons::RUN_SMALL.icon());
|
2017-12-04 10:11:19 +01:00
|
|
|
action->setToolTip(tr("Run All Tests"));
|
2015-03-30 07:47:07 +02:00
|
|
|
Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_ALL_ID);
|
2018-08-20 12:44:52 +02:00
|
|
|
command->setDefaultKeySequence(
|
|
|
|
|
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+A") : tr("Alt+Shift+T,Alt+A")));
|
2019-08-19 09:33:14 +02:00
|
|
|
connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunAllTriggered);
|
2017-06-15 10:43:44 +02:00
|
|
|
action->setEnabled(false);
|
2015-03-30 07:47:07 +02:00
|
|
|
menu->addAction(command);
|
|
|
|
|
|
|
|
|
|
action = new QAction(tr("&Run Selected Tests"), this);
|
2020-11-30 00:20:53 +01:00
|
|
|
action->setIcon(Utils::Icons::RUN_SELECTED.icon());
|
2017-12-04 10:11:19 +01:00
|
|
|
action->setToolTip(tr("Run Selected Tests"));
|
2015-03-30 07:47:07 +02:00
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_SELECTED_ID);
|
2018-08-20 12:44:52 +02:00
|
|
|
command->setDefaultKeySequence(
|
|
|
|
|
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+R") : tr("Alt+Shift+T,Alt+R")));
|
2019-08-19 09:33:14 +02:00
|
|
|
connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunSelectedTriggered);
|
2017-06-15 10:43:44 +02:00
|
|
|
action->setEnabled(false);
|
2015-03-30 07:47:07 +02:00
|
|
|
menu->addAction(command);
|
|
|
|
|
|
2020-09-11 09:44:21 +02:00
|
|
|
action = new QAction(tr("Run &Failed Tests"), this);
|
2020-12-04 14:29:20 +01:00
|
|
|
action->setIcon(Icons::RUN_FAILED.icon());
|
2020-09-11 09:44:21 +02:00
|
|
|
action->setToolTip(tr("Run Failed Tests"));
|
|
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_FAILED_ID);
|
|
|
|
|
command->setDefaultKeySequence(
|
|
|
|
|
useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+F") : tr("Alt+Shift+T,Alt+F"));
|
|
|
|
|
connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunFailedTriggered);
|
|
|
|
|
action->setEnabled(false);
|
|
|
|
|
menu->addAction(command);
|
|
|
|
|
|
|
|
|
|
action = new QAction(tr("Run Tests for &Current File"), this);
|
2020-11-30 00:20:53 +01:00
|
|
|
action->setIcon(Utils::Icons::RUN_FILE.icon());
|
2018-05-05 22:28:55 +03:00
|
|
|
action->setToolTip(tr("Run Tests for Current File"));
|
|
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_FILE_ID);
|
2018-08-20 12:44:52 +02:00
|
|
|
command->setDefaultKeySequence(
|
2020-09-11 09:44:21 +02:00
|
|
|
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+C") : tr("Alt+Shift+T,Alt+C")));
|
2019-08-19 09:33:14 +02:00
|
|
|
connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunFileTriggered);
|
2018-05-05 22:28:55 +03:00
|
|
|
action->setEnabled(false);
|
|
|
|
|
menu->addAction(command);
|
|
|
|
|
|
2015-03-30 07:47:07 +02:00
|
|
|
action = new QAction(tr("Re&scan Tests"), this);
|
|
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_SCAN_ID);
|
2018-08-20 12:44:52 +02:00
|
|
|
command->setDefaultKeySequence(
|
|
|
|
|
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+S") : tr("Alt+Shift+T,Alt+S")));
|
2020-03-16 12:59:23 +01:00
|
|
|
|
|
|
|
|
connect(action, &QAction::triggered, this, [] { dd->m_testCodeParser.updateTestTree(); });
|
2014-12-19 11:25:05 +01:00
|
|
|
menu->addAction(command);
|
2015-03-30 07:47:07 +02:00
|
|
|
|
2015-04-14 15:24:31 +02:00
|
|
|
ActionContainer *toolsMenu = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
|
|
|
|
toolsMenu->addMenu(menu);
|
2017-06-15 10:43:44 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
|
|
|
|
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
|
|
|
|
connect(BuildManager::instance(), &BuildManager::buildQueueFinished,
|
|
|
|
|
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
2020-02-24 15:55:15 +01:00
|
|
|
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::runActionsUpdated,
|
2017-12-04 10:11:19 +01:00
|
|
|
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
2020-03-16 12:59:23 +01:00
|
|
|
connect(&dd->m_testTreeModel, &TestTreeModel::testTreeModelChanged,
|
2015-04-14 15:24:31 +02:00
|
|
|
this, &AutotestPlugin::updateMenuItemsEnabledState);
|
2014-12-19 11:25:05 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorString)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(errorString)
|
|
|
|
|
|
2020-03-05 08:35:01 +01:00
|
|
|
dd = new AutotestPluginPrivate;
|
2021-04-28 15:59:18 +02:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
ExtensionSystem::PluginManager::registerScenario("TestStringTable",
|
2021-06-24 11:31:48 +02:00
|
|
|
[] { return dd->m_loadProjectScenario(); });
|
2021-04-30 16:52:03 +02:00
|
|
|
ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface",
|
2021-06-24 11:31:48 +02:00
|
|
|
[] { return dd->m_loadProjectScenario(); });
|
2021-04-28 15:59:18 +02:00
|
|
|
#endif
|
2014-10-07 12:30:54 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AutotestPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2018-02-16 17:57:37 +01:00
|
|
|
ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT);
|
2018-05-23 13:24:04 +02:00
|
|
|
if (!contextMenu) // if QC is started without CppEditor plugin
|
|
|
|
|
return;
|
2018-02-16 17:57:37 +01:00
|
|
|
|
|
|
|
|
QAction *action = new QAction(tr("&Run Test Under Cursor"), this);
|
|
|
|
|
action->setEnabled(false);
|
2019-12-17 18:27:37 +01:00
|
|
|
action->setIcon(Utils::Icons::RUN_SMALL.icon());
|
2018-02-16 17:57:37 +01:00
|
|
|
|
|
|
|
|
Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_UCURSOR);
|
2019-08-19 09:33:14 +02:00
|
|
|
connect(action, &QAction::triggered,
|
2020-02-28 12:27:13 +01:00
|
|
|
std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, dd, TestRunMode::Run));
|
2018-02-16 17:57:37 +01:00
|
|
|
contextMenu->addSeparator();
|
|
|
|
|
contextMenu->addAction(command);
|
|
|
|
|
|
2019-07-09 10:46:09 +02:00
|
|
|
action = new QAction(tr("&Debug Test Under Cursor"), this);
|
2018-02-16 17:57:37 +01:00
|
|
|
action->setEnabled(false);
|
|
|
|
|
action->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon());
|
|
|
|
|
|
|
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_DBG_UCURSOR);
|
2019-08-19 09:33:14 +02:00
|
|
|
connect(action, &QAction::triggered,
|
2020-02-28 12:27:13 +01:00
|
|
|
std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, dd, TestRunMode::Debug));
|
2018-02-16 17:57:37 +01:00
|
|
|
contextMenu->addAction(command);
|
|
|
|
|
contextMenu->addSeparator();
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag AutotestPlugin::aboutToShutdown()
|
|
|
|
|
{
|
2020-03-16 12:59:23 +01:00
|
|
|
dd->m_testCodeParser.aboutToShutdown();
|
|
|
|
|
dd->m_testTreeModel.disconnect();
|
2014-10-07 12:30:54 +02:00
|
|
|
return SynchronousShutdown;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 09:33:14 +02:00
|
|
|
void AutotestPluginPrivate::onRunAllTriggered()
|
2015-03-30 07:47:07 +02:00
|
|
|
{
|
2020-03-26 09:21:25 +01:00
|
|
|
m_testRunner.setSelectedTests(m_testTreeModel.getAllTestCases());
|
|
|
|
|
m_testRunner.prepareToRunTests(TestRunMode::Run);
|
2015-03-30 07:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-19 09:33:14 +02:00
|
|
|
void AutotestPluginPrivate::onRunSelectedTriggered()
|
2015-03-30 07:47:07 +02:00
|
|
|
{
|
2020-03-26 09:21:25 +01:00
|
|
|
m_testRunner.setSelectedTests(m_testTreeModel.getSelectedTests());
|
|
|
|
|
m_testRunner.prepareToRunTests(TestRunMode::Run);
|
2015-03-30 07:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-11 09:44:21 +02:00
|
|
|
void AutotestPluginPrivate::onRunFailedTriggered()
|
|
|
|
|
{
|
2020-10-13 11:37:37 +02:00
|
|
|
const QList<ITestConfiguration *> failed = m_testTreeModel.getFailedTests();
|
2020-09-11 09:44:21 +02:00
|
|
|
if (failed.isEmpty()) // the framework might not be able to provide them
|
|
|
|
|
return;
|
|
|
|
|
m_testRunner.setSelectedTests(failed);
|
|
|
|
|
m_testRunner.prepareToRunTests(TestRunMode::Run);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 09:33:14 +02:00
|
|
|
void AutotestPluginPrivate::onRunFileTriggered()
|
2018-05-05 22:28:55 +03:00
|
|
|
{
|
|
|
|
|
const IDocument *document = EditorManager::currentDocument();
|
|
|
|
|
if (!document)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
const Utils::FilePath &fileName = document->filePath();
|
2018-05-05 22:28:55 +03:00
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-10-13 11:37:37 +02:00
|
|
|
const QList<ITestConfiguration *> tests = m_testTreeModel.getTestsForFile(fileName);
|
2018-05-05 22:28:55 +03:00
|
|
|
if (tests.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-03-26 09:21:25 +01:00
|
|
|
m_testRunner.setSelectedTests(tests);
|
|
|
|
|
m_testRunner.prepareToRunTests(TestRunMode::Run);
|
2018-05-05 22:28:55 +03:00
|
|
|
}
|
|
|
|
|
|
2021-01-27 14:38:13 +01:00
|
|
|
static QList<ITestConfiguration *> testItemsToTestConfigurations(const QList<ITestTreeItem *> &items,
|
2018-10-11 12:45:13 +02:00
|
|
|
TestRunMode mode)
|
|
|
|
|
{
|
2020-10-13 11:37:37 +02:00
|
|
|
QList<ITestConfiguration *> configs;
|
2021-01-27 14:38:13 +01:00
|
|
|
for (const ITestTreeItem * item : items) {
|
2020-10-13 11:37:37 +02:00
|
|
|
if (ITestConfiguration *currentConfig = item->asConfiguration(mode))
|
2018-10-11 12:45:13 +02:00
|
|
|
configs << currentConfig;
|
|
|
|
|
}
|
|
|
|
|
return configs;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 09:33:14 +02:00
|
|
|
void AutotestPluginPrivate::onRunUnderCursorTriggered(TestRunMode mode)
|
2018-02-16 17:57:37 +01:00
|
|
|
{
|
2018-10-11 12:45:13 +02:00
|
|
|
TextEditor::BaseTextEditor *currentEditor = TextEditor::BaseTextEditor::currentTextEditor();
|
|
|
|
|
QTextCursor cursor = currentEditor->editorWidget()->textCursor();
|
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
2018-02-16 17:57:37 +01:00
|
|
|
const QString text = cursor.selectedText();
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
return; // Do not trigger when no name under cursor
|
|
|
|
|
|
2021-01-27 14:38:13 +01:00
|
|
|
const QList<ITestTreeItem *> testsItems = m_testTreeModel.testItemsByName(text);
|
2018-02-16 17:57:37 +01:00
|
|
|
if (testsItems.isEmpty())
|
|
|
|
|
return; // Wrong location triggered
|
|
|
|
|
|
2018-10-11 12:45:13 +02:00
|
|
|
// check whether we have been triggered on a test function definition
|
2019-07-24 18:40:10 +02:00
|
|
|
const int line = currentEditor->currentLine();
|
2021-05-26 15:50:03 +02:00
|
|
|
const Utils::FilePath &filePath = currentEditor->textDocument()->filePath();
|
2021-01-27 14:38:13 +01:00
|
|
|
const QList<ITestTreeItem *> filteredItems = Utils::filtered(testsItems, [&](ITestTreeItem *it){
|
2018-10-11 12:45:13 +02:00
|
|
|
return it->line() == line && it->filePath() == filePath;
|
|
|
|
|
});
|
|
|
|
|
|
2020-10-13 11:37:37 +02:00
|
|
|
const QList<ITestConfiguration *> testsToRun = testItemsToTestConfigurations(
|
2018-10-11 12:45:13 +02:00
|
|
|
filteredItems.size() == 1 ? filteredItems : testsItems, mode);
|
2018-02-16 17:57:37 +01:00
|
|
|
|
|
|
|
|
if (testsToRun.isEmpty()) {
|
2020-12-15 10:13:13 +01:00
|
|
|
MessageManager::writeFlashing(tr("Selected test was not found (%1).").arg(text));
|
2018-02-16 17:57:37 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 09:21:25 +01:00
|
|
|
m_testRunner.setSelectedTests(testsToRun);
|
|
|
|
|
m_testRunner.prepareToRunTests(mode);
|
2018-02-16 17:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-30 07:47:07 +02:00
|
|
|
void AutotestPlugin::updateMenuItemsEnabledState()
|
|
|
|
|
{
|
2018-04-06 09:24:48 +02:00
|
|
|
const ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
|
|
|
|
const ProjectExplorer::Target *target = project ? project->activeTarget() : nullptr;
|
2020-03-26 09:21:25 +01:00
|
|
|
const bool canScan = !dd->m_testRunner.isTestRunning()
|
2020-03-16 12:59:23 +01:00
|
|
|
&& dd->m_testCodeParser.state() == TestCodeParser::Idle;
|
|
|
|
|
const bool hasTests = dd->m_testTreeModel.hasTests();
|
2018-04-06 09:24:48 +02:00
|
|
|
// avoid expensive call to PE::canRunStartupProject() - limit to minimum necessary checks
|
2018-02-28 13:08:05 +01:00
|
|
|
const bool canRun = hasTests && canScan
|
2018-04-06 09:24:48 +02:00
|
|
|
&& project && !project->needsConfiguration()
|
|
|
|
|
&& target && target->activeRunConfiguration()
|
|
|
|
|
&& !ProjectExplorer::BuildManager::isBuilding();
|
2020-09-11 09:44:21 +02:00
|
|
|
const bool canRunFailed = canRun && dd->m_testTreeModel.hasFailedTests();
|
2015-03-30 07:47:07 +02:00
|
|
|
|
2018-02-28 13:08:05 +01:00
|
|
|
ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action()->setEnabled(canRun);
|
|
|
|
|
ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action()->setEnabled(canRun);
|
2020-09-11 09:44:21 +02:00
|
|
|
ActionManager::command(Constants::ACTION_RUN_FAILED_ID)->action()->setEnabled(canRunFailed);
|
2018-05-05 22:28:55 +03:00
|
|
|
ActionManager::command(Constants::ACTION_RUN_FILE_ID)->action()->setEnabled(canRun);
|
2018-02-28 13:08:05 +01:00
|
|
|
ActionManager::command(Constants::ACTION_SCAN_ID)->action()->setEnabled(canScan);
|
2018-02-16 17:57:37 +01:00
|
|
|
|
|
|
|
|
ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT);
|
|
|
|
|
if (!contextMenu)
|
|
|
|
|
return; // When no context menu, actions do not exists
|
|
|
|
|
|
|
|
|
|
ActionManager::command(Constants::ACTION_RUN_UCURSOR)->action()->setEnabled(canRun);
|
|
|
|
|
ActionManager::command(Constants::ACTION_RUN_DBG_UCURSOR)->action()->setEnabled(canRun);
|
2015-03-30 07:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-08 12:40:03 +02:00
|
|
|
void AutotestPlugin::cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice)
|
|
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
if (dd)
|
|
|
|
|
dd->m_runconfigCache.insert(buildTargetKey, choice);
|
2018-08-08 12:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChoicePair AutotestPlugin::cachedChoiceFor(const QString &buildTargetKey)
|
|
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
return dd ? dd->m_runconfigCache.value(buildTargetKey) : ChoicePair();
|
2018-08-08 12:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AutotestPlugin::clearChoiceCache()
|
|
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
if (dd)
|
|
|
|
|
dd->m_runconfigCache.clear();
|
2018-08-08 12:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 11:05:22 +01:00
|
|
|
void AutotestPlugin::popupResultsPane()
|
|
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
if (dd)
|
|
|
|
|
dd->m_resultsPane->popup(Core::IOutputPane::NoModeSwitch);
|
2019-03-13 11:05:22 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 14:12:11 +02:00
|
|
|
QVector<QObject *> AutotestPlugin::createTestObjects() const
|
2015-02-10 14:20:43 +01:00
|
|
|
{
|
2019-05-27 14:12:11 +02:00
|
|
|
QVector<QObject *> tests;
|
2015-02-10 14:20:43 +01:00
|
|
|
#ifdef WITH_TESTS
|
2020-03-16 12:59:23 +01:00
|
|
|
tests << new AutoTestUnitTests(&dd->m_testTreeModel);
|
2015-02-10 14:20:43 +01:00
|
|
|
#endif
|
|
|
|
|
return tests;
|
|
|
|
|
}
|
2018-08-08 12:40:03 +02:00
|
|
|
|
|
|
|
|
bool ChoicePair::matches(const ProjectExplorer::RunConfiguration *rc) const
|
|
|
|
|
{
|
2019-06-20 17:19:12 +02:00
|
|
|
return rc && rc->displayName() == displayName && rc->runnable().executable.toString() == executable;
|
2018-08-08 12:40:03 +02:00
|
|
|
}
|
2019-08-19 09:33:14 +02:00
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // Autotest
|
|
|
|
|
|
|
|
|
|
#include "autotestplugin.moc"
|