2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
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"
|
2022-07-13 18:31:56 +02:00
|
|
|
#include "autotesttr.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"
|
|
|
|
|
|
2023-07-11 12:40:08 +02:00
|
|
|
#include "boost/boosttestsettings.h"
|
|
|
|
|
#include "catch/catchtestsettings.h"
|
|
|
|
|
#include "ctest/ctestsettings.h"
|
|
|
|
|
#include "gtest/gtestsettings.h"
|
|
|
|
|
#include "qtest/qttestsettings.h"
|
2020-10-09 13:07:55 +02:00
|
|
|
#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>
|
2018-02-16 17:57:37 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2023-02-14 15:47:22 +01:00
|
|
|
|
2022-11-30 10:10:41 +01:00
|
|
|
#include <cplusplus/CppDocument.h>
|
|
|
|
|
#include <cplusplus/LookupContext.h>
|
|
|
|
|
#include <cplusplus/Overview.h>
|
2023-02-14 15:47:22 +01:00
|
|
|
|
2018-02-16 17:57:37 +01:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
2022-11-30 10:10:41 +01:00
|
|
|
#include <cppeditor/cppmodelmanager.h>
|
2023-02-14 15:47:22 +01:00
|
|
|
|
2014-10-28 13:02:34 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2023-02-14 15:47:22 +01:00
|
|
|
|
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>
|
2023-02-14 15:47:22 +01:00
|
|
|
#include <projectexplorer/projectmanager.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/target.h>
|
2023-02-14 15:47:22 +01:00
|
|
|
|
2018-10-11 12:45:13 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
2020-10-09 13:07:55 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2023-02-14 15:47:22 +01:00
|
|
|
|
2022-05-17 14:59:01 +02:00
|
|
|
#include <utils/algorithm.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;
|
2023-01-16 15:00:15 +01:00
|
|
|
using namespace Utils;
|
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();
|
2021-07-08 16:57:00 +02:00
|
|
|
void onRunAllTriggered(TestRunMode mode);
|
|
|
|
|
void onRunSelectedTriggered(TestRunMode mode);
|
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
|
|
|
|
2023-05-12 11:00:00 +02:00
|
|
|
TestSettingsPage m_testSettingPage;
|
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();
|
2023-07-11 12:40:08 +02:00
|
|
|
m_frameworkManager.registerTestFramework(&theQtTestFramework());
|
|
|
|
|
m_frameworkManager.registerTestFramework(&theQuickTestFramework());
|
|
|
|
|
m_frameworkManager.registerTestFramework(&theGTestFramework());
|
|
|
|
|
m_frameworkManager.registerTestFramework(&theBoostTestFramework());
|
|
|
|
|
m_frameworkManager.registerTestFramework(&theCatchFramework());
|
2019-08-19 09:33:14 +02:00
|
|
|
|
2023-07-11 12:40:08 +02:00
|
|
|
m_frameworkManager.registerTestTool(&theCTestTool());
|
2020-10-19 14:47:45 +02:00
|
|
|
|
2023-07-06 09:57:16 +02:00
|
|
|
m_frameworkManager.synchronizeSettings();
|
2019-08-19 09:33:14 +02:00
|
|
|
m_resultsPane = TestResultsPane::instance();
|
|
|
|
|
|
|
|
|
|
auto panelFactory = new ProjectExplorer::ProjectPanelFactory();
|
|
|
|
|
panelFactory->setPriority(666);
|
|
|
|
|
// panelFactory->setIcon(); // TODO ?
|
2022-07-13 18:31:56 +02:00
|
|
|
panelFactory->setDisplayName(Tr::tr("Testing"));
|
2019-08-19 09:33:14 +02:00
|
|
|
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {
|
|
|
|
|
return new ProjectTestSettingsWidget(project);
|
|
|
|
|
});
|
|
|
|
|
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
|
|
|
|
|
|
2023-07-06 17:46:57 +02:00
|
|
|
TestFrameworkManager::activateFrameworksAndToolsFromSettings();
|
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
|
|
|
|
2023-02-14 15:47:22 +01:00
|
|
|
auto sessionManager = ProjectExplorer::ProjectManager::instance();
|
|
|
|
|
connect(sessionManager, &ProjectExplorer::ProjectManager::startupProjectChanged,
|
2020-03-05 13:31:31 +01:00
|
|
|
this, [this] { m_runconfigCache.clear(); });
|
|
|
|
|
|
2023-02-14 15:47:22 +01:00
|
|
|
connect(sessionManager, &ProjectExplorer::ProjectManager::aboutToRemoveProject,
|
2022-12-07 14:45:43 +01:00
|
|
|
this, [](ProjectExplorer::Project *project) {
|
2022-11-29 21:11:25 +01:00
|
|
|
const auto it = s_projectSettings.constFind(project);
|
|
|
|
|
if (it != s_projectSettings.constEnd()) {
|
2020-03-05 13:31:31 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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);
|
2022-07-13 18:31:56 +02:00
|
|
|
menu->menu()->setTitle(Tr::tr("&Tests"));
|
2016-10-25 14:30:51 +02:00
|
|
|
menu->setOnAllDisabledBehavior(ActionContainer::Show);
|
2015-03-30 07:47:07 +02:00
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
QAction *action = new QAction(Tr::tr("Run &All Tests"), this);
|
2020-12-04 14:29:20 +01:00
|
|
|
action->setIcon(Utils::Icons::RUN_SMALL.icon());
|
2023-06-19 10:52:19 +02:00
|
|
|
action->setToolTip(Tr::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(
|
2022-07-13 18:31:56 +02:00
|
|
|
QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Meta+T, Ctrl+Meta+A") : Tr::tr("Alt+Shift+T,Alt+A")));
|
2021-07-08 16:57:00 +02:00
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
std::bind(&AutotestPluginPrivate::onRunAllTriggered, this, TestRunMode::Run));
|
|
|
|
|
action->setEnabled(false);
|
|
|
|
|
menu->addAction(command);
|
|
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::tr("Run All Tests Without Deployment"), this);
|
2021-07-08 16:57:00 +02:00
|
|
|
action->setIcon(Utils::Icons::RUN_SMALL.icon());
|
2023-06-19 10:52:19 +02:00
|
|
|
action->setToolTip(Tr::tr("Run All Tests Without Deployment"));
|
2021-07-08 16:57:00 +02:00
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_ALL_NODEPLOY_ID);
|
|
|
|
|
command->setDefaultKeySequence(
|
2022-07-13 18:31:56 +02:00
|
|
|
QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Meta+T, Ctrl+Meta+E") : Tr::tr("Alt+Shift+T,Alt+E")));
|
2021-07-08 16:57:00 +02:00
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
std::bind(&AutotestPluginPrivate::onRunAllTriggered, this, TestRunMode::RunWithoutDeploy));
|
2017-06-15 10:43:44 +02:00
|
|
|
action->setEnabled(false);
|
2015-03-30 07:47:07 +02:00
|
|
|
menu->addAction(command);
|
|
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::tr("&Run Selected Tests"), this);
|
2020-11-30 00:20:53 +01:00
|
|
|
action->setIcon(Utils::Icons::RUN_SELECTED.icon());
|
2023-06-19 10:52:19 +02:00
|
|
|
action->setToolTip(Tr::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(
|
2022-07-13 18:31:56 +02:00
|
|
|
QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Meta+T, Ctrl+Meta+R") : Tr::tr("Alt+Shift+T,Alt+R")));
|
2021-07-08 16:57:00 +02:00
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
std::bind(&AutotestPluginPrivate::onRunSelectedTriggered, this, TestRunMode::Run));
|
|
|
|
|
action->setEnabled(false);
|
|
|
|
|
menu->addAction(command);
|
|
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::tr("&Run Selected Tests Without Deployment"), this);
|
2021-07-08 16:57:00 +02:00
|
|
|
action->setIcon(Utils::Icons::RUN_SELECTED.icon());
|
2023-06-19 10:52:19 +02:00
|
|
|
action->setToolTip(Tr::tr("Run Selected Tests Without Deployment"));
|
2021-07-08 16:57:00 +02:00
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_SELECTED_NODEPLOY_ID);
|
|
|
|
|
command->setDefaultKeySequence(
|
2022-07-13 18:31:56 +02:00
|
|
|
QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Meta+T, Ctrl+Meta+W") : Tr::tr("Alt+Shift+T,Alt+W")));
|
2021-07-08 16:57:00 +02:00
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
std::bind(&AutotestPluginPrivate::onRunSelectedTriggered, this, TestRunMode::RunWithoutDeploy));
|
2017-06-15 10:43:44 +02:00
|
|
|
action->setEnabled(false);
|
2015-03-30 07:47:07 +02:00
|
|
|
menu->addAction(command);
|
|
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::tr("Run &Failed Tests"), this);
|
2020-12-04 14:29:20 +01:00
|
|
|
action->setIcon(Icons::RUN_FAILED.icon());
|
2023-06-19 10:52:19 +02:00
|
|
|
action->setToolTip(Tr::tr("Run Failed Tests"));
|
2020-09-11 09:44:21 +02:00
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_FAILED_ID);
|
|
|
|
|
command->setDefaultKeySequence(
|
2022-07-13 18:31:56 +02:00
|
|
|
useMacShortcuts ? Tr::tr("Ctrl+Meta+T, Ctrl+Meta+F") : Tr::tr("Alt+Shift+T,Alt+F"));
|
2020-09-11 09:44:21 +02:00
|
|
|
connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunFailedTriggered);
|
|
|
|
|
action->setEnabled(false);
|
|
|
|
|
menu->addAction(command);
|
|
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::tr("Run Tests for &Current File"), this);
|
2020-11-30 00:20:53 +01:00
|
|
|
action->setIcon(Utils::Icons::RUN_FILE.icon());
|
2023-06-19 10:52:19 +02:00
|
|
|
action->setToolTip(Tr::tr("Run Tests for Current File"));
|
2018-05-05 22:28:55 +03:00
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_FILE_ID);
|
2018-08-20 12:44:52 +02:00
|
|
|
command->setDefaultKeySequence(
|
2022-07-13 18:31:56 +02:00
|
|
|
QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Meta+T, Ctrl+Meta+C") : Tr::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);
|
|
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::tr("Re&scan Tests"), this);
|
2015-03-30 07:47:07 +02:00
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_SCAN_ID);
|
2018-08-20 12:44:52 +02:00
|
|
|
command->setDefaultKeySequence(
|
2022-07-13 18:31:56 +02:00
|
|
|
QKeySequence(useMacShortcuts ? Tr::tr("Ctrl+Meta+T, Ctrl+Meta+S") : Tr::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
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:28:36 +01:00
|
|
|
void AutotestPlugin::initialize()
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2020-03-05 08:35:01 +01:00
|
|
|
dd = new AutotestPluginPrivate;
|
2021-04-28 15:59:18 +02:00
|
|
|
#ifdef WITH_TESTS
|
2021-04-30 16:52:03 +02:00
|
|
|
ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface",
|
2021-06-24 11:31:48 +02:00
|
|
|
[] { return dd->m_loadProjectScenario(); });
|
2023-02-09 15:07:54 +01:00
|
|
|
|
|
|
|
|
addTest<AutoTestUnitTests>(&dd->m_testTreeModel);
|
2021-04-28 15:59:18 +02:00
|
|
|
#endif
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
QAction *action = new QAction(Tr::tr("&Run Test Under Cursor"), this);
|
2018-02-16 17:57:37 +01:00
|
|
|
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);
|
|
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::tr("Run Test Under Cursor Without Deployment"), this);
|
2021-07-08 16:57:00 +02:00
|
|
|
action->setEnabled(false);
|
|
|
|
|
action->setIcon(Utils::Icons::RUN_SMALL.icon());
|
|
|
|
|
|
|
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_UCURSOR_NODEPLOY);
|
|
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, dd, TestRunMode::RunWithoutDeploy));
|
|
|
|
|
contextMenu->addAction(command);
|
|
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::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);
|
2021-07-08 16:57:00 +02:00
|
|
|
|
2022-07-13 18:31:56 +02:00
|
|
|
action = new QAction(Tr::tr("Debug Test Under Cursor Without Deployment"), this);
|
2021-07-08 16:57:00 +02:00
|
|
|
action->setEnabled(false);
|
|
|
|
|
action->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon());
|
|
|
|
|
|
|
|
|
|
command = ActionManager::registerAction(action, Constants::ACTION_RUN_DBG_UCURSOR_NODEPLOY);
|
|
|
|
|
connect(action, &QAction::triggered,
|
|
|
|
|
std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, dd, TestRunMode::DebugWithoutDeploy));
|
|
|
|
|
contextMenu->addAction(command);
|
2018-02-16 17:57:37 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-08 16:57:00 +02:00
|
|
|
void AutotestPluginPrivate::onRunAllTriggered(TestRunMode mode)
|
2015-03-30 07:47:07 +02:00
|
|
|
{
|
2023-01-13 12:30:42 +01:00
|
|
|
m_testRunner.runTests(mode, m_testTreeModel.getAllTestCases());
|
2015-03-30 07:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-08 16:57:00 +02:00
|
|
|
void AutotestPluginPrivate::onRunSelectedTriggered(TestRunMode mode)
|
2015-03-30 07:47:07 +02:00
|
|
|
{
|
2023-01-13 12:30:42 +01:00
|
|
|
m_testRunner.runTests(mode, m_testTreeModel.getSelectedTests());
|
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;
|
2023-01-13 12:30:42 +01:00
|
|
|
m_testRunner.runTests(TestRunMode::Run, failed);
|
2020-09-11 09:44:21 +02:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2023-01-16 15:00:15 +01:00
|
|
|
const 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;
|
|
|
|
|
|
2023-01-13 12:30:42 +01:00
|
|
|
m_testRunner.runTests(TestRunMode::Run, tests);
|
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();
|
2023-02-06 16:25:50 +01:00
|
|
|
QTC_ASSERT(currentEditor && currentEditor->textDocument(), return);
|
|
|
|
|
const int line = currentEditor->currentLine();
|
|
|
|
|
const FilePath filePath = currentEditor->textDocument()->filePath();
|
|
|
|
|
|
|
|
|
|
const CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::instance()->snapshot();
|
|
|
|
|
const CPlusPlus::Document::Ptr doc = snapshot.document(filePath);
|
|
|
|
|
if (doc.isNull()) // not part of C++ snapshot
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CPlusPlus::Scope *scope = doc->scopeAt(line, currentEditor->currentColumn());
|
2018-10-11 12:45:13 +02:00
|
|
|
QTextCursor cursor = currentEditor->editorWidget()->textCursor();
|
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
2018-02-16 17:57:37 +01:00
|
|
|
const QString text = cursor.selectedText();
|
2023-02-06 16:25:50 +01:00
|
|
|
|
|
|
|
|
while (scope && scope->asBlock())
|
|
|
|
|
scope = scope->enclosingScope();
|
|
|
|
|
if (scope && scope->asFunction()) { // class, namespace for further stuff?
|
|
|
|
|
const QList<const CPlusPlus::Name *> fullName
|
|
|
|
|
= CPlusPlus::LookupContext::fullyQualifiedName(scope);
|
|
|
|
|
const QString funcName = CPlusPlus::Overview().prettyName(fullName);
|
|
|
|
|
const TestFrameworks active = AutotestPlugin::activeTestFrameworks();
|
|
|
|
|
for (auto framework : active) {
|
|
|
|
|
const QStringList testName = framework->testNameForSymbolName(funcName);
|
|
|
|
|
if (!testName.size())
|
|
|
|
|
continue;
|
|
|
|
|
TestTreeItem *it = framework->rootNode()->findTestByNameAndFile(testName, filePath);
|
|
|
|
|
if (it) {
|
|
|
|
|
const QList<ITestConfiguration *> testsToRun
|
|
|
|
|
= testItemsToTestConfigurations({ it }, mode);
|
|
|
|
|
if (!testsToRun.isEmpty()) {
|
|
|
|
|
m_testRunner.runTests(mode, testsToRun);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// general approach
|
2018-02-16 17:57:37 +01:00
|
|
|
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
|
2022-11-30 10:10:41 +01:00
|
|
|
QList<ITestTreeItem *> filteredItems = Utils::filtered(testsItems, [&](ITestTreeItem *it){
|
2018-10-11 12:45:13 +02:00
|
|
|
return it->line() == line && it->filePath() == filePath;
|
|
|
|
|
});
|
|
|
|
|
|
2022-11-30 10:10:41 +01:00
|
|
|
if (filteredItems.size() == 0 && testsItems.size() > 1) {
|
2023-02-06 16:25:50 +01:00
|
|
|
CPlusPlus::Scope *scope = doc->scopeAt(line, currentEditor->currentColumn());
|
|
|
|
|
if (scope->asClass()) {
|
|
|
|
|
const QList<const CPlusPlus::Name *> fullName
|
|
|
|
|
= CPlusPlus::LookupContext::fullyQualifiedName(scope);
|
|
|
|
|
const QString className = CPlusPlus::Overview().prettyName(fullName);
|
|
|
|
|
|
|
|
|
|
filteredItems = Utils::filtered(testsItems,
|
|
|
|
|
[&text, &className](ITestTreeItem *it){
|
|
|
|
|
return it->name() == text
|
|
|
|
|
&& static_cast<ITestTreeItem *>(it->parent())->name() == className;
|
|
|
|
|
});
|
2022-11-30 10:10:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ((filteredItems.size() != 1 && testsItems.size() > 1)
|
|
|
|
|
&& (mode == TestRunMode::Debug || mode == TestRunMode::DebugWithoutDeploy)) {
|
|
|
|
|
MessageManager::writeFlashing(Tr::tr("Cannot debug multiple tests at once."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
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()) {
|
2022-07-13 18:31:56 +02:00
|
|
|
MessageManager::writeFlashing(Tr::tr("Selected test was not found (%1).").arg(text));
|
2018-02-16 17:57:37 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 12:30:42 +01:00
|
|
|
m_testRunner.runTests(mode, testsToRun);
|
2018-02-16 17:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-06 14:29:24 +01:00
|
|
|
TestFrameworks AutotestPlugin::activeTestFrameworks()
|
|
|
|
|
{
|
2023-02-14 15:47:22 +01:00
|
|
|
ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject();
|
2023-02-06 14:29:24 +01:00
|
|
|
TestFrameworks sorted;
|
|
|
|
|
if (!project || projectSettings(project)->useGlobalSettings()) {
|
|
|
|
|
sorted = Utils::filtered(TestFrameworkManager::registeredFrameworks(),
|
|
|
|
|
&ITestFramework::active);
|
|
|
|
|
} else { // we've got custom project settings
|
|
|
|
|
const TestProjectSettings *settings = projectSettings(project);
|
|
|
|
|
const QHash<ITestFramework *, bool> active = settings->activeFrameworks();
|
|
|
|
|
sorted = Utils::filtered(TestFrameworkManager::registeredFrameworks(),
|
|
|
|
|
[active](ITestFramework *framework) {
|
|
|
|
|
return active.value(framework, false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return sorted;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-30 07:47:07 +02:00
|
|
|
void AutotestPlugin::updateMenuItemsEnabledState()
|
|
|
|
|
{
|
2023-02-14 15:47:22 +01:00
|
|
|
const ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject();
|
2018-04-06 09:24:48 +02:00
|
|
|
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);
|
2021-07-08 16:57:00 +02:00
|
|
|
ActionManager::command(Constants::ACTION_RUN_ALL_NODEPLOY_ID)->action()->setEnabled(canRun);
|
|
|
|
|
ActionManager::command(Constants::ACTION_RUN_SELECTED_NODEPLOY_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);
|
2021-07-08 16:57:00 +02:00
|
|
|
ActionManager::command(Constants::ACTION_RUN_UCURSOR_NODEPLOY)->action()->setEnabled(canRun);
|
2018-02-16 17:57:37 +01:00
|
|
|
ActionManager::command(Constants::ACTION_RUN_DBG_UCURSOR)->action()->setEnabled(canRun);
|
2021-07-08 16:57:00 +02:00
|
|
|
ActionManager::command(Constants::ACTION_RUN_DBG_UCURSOR_NODEPLOY)->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
|
|
|
}
|
|
|
|
|
|
2018-08-08 12:40:03 +02:00
|
|
|
bool ChoicePair::matches(const ProjectExplorer::RunConfiguration *rc) const
|
|
|
|
|
{
|
2022-09-22 17:23:20 +02:00
|
|
|
return rc && rc->displayName() == displayName && rc->runnable().command.executable() == executable;
|
2018-08-08 12:40:03 +02:00
|
|
|
}
|
2019-08-19 09:33:14 +02:00
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // Autotest
|
|
|
|
|
|
|
|
|
|
#include "autotestplugin.moc"
|