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 "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-12 12:51:06 +02:00
|
|
|
#include "boost/boosttestframework.h"
|
|
|
|
|
#include "catch/catchtestframework.h"
|
|
|
|
|
#include "ctest/ctesttool.h"
|
|
|
|
|
#include "gtest/gtestframework.h"
|
2023-12-05 14:12:06 +01:00
|
|
|
#include "qtest/datataglocatorfilter.h"
|
2023-07-12 12:51:06 +02:00
|
|
|
#include "qtest/qttestframework.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/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-08-25 14:10:10 +02:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.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
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
#include <extensionsystem/iplugin.h>
|
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>
|
2023-08-16 19:24:06 +02:00
|
|
|
#include <projectexplorer/runconfiguration.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>
|
2023-08-16 19:24:06 +02:00
|
|
|
#include <utils/processinterface.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
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
namespace Autotest::Internal {
|
2019-08-19 09:33:14 +02:00
|
|
|
|
2024-01-09 16:01:16 +01:00
|
|
|
class AutotestPluginPrivate final : public QObject
|
2019-08-19 09:33:14 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2020-03-05 08:35:01 +01:00
|
|
|
AutotestPluginPrivate();
|
2024-01-09 16:01:16 +01:00
|
|
|
~AutotestPluginPrivate() final;
|
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);
|
2023-08-25 14:10:10 +02:00
|
|
|
void onDisableTemporarily(bool disable);
|
2020-02-28 12:27:13 +01:00
|
|
|
|
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;
|
2023-12-05 14:12:06 +01:00
|
|
|
DataTagLocatorFilter m_dataTagLocatorFilter;
|
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
|
|
|
|
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-27 16:40:46 +02:00
|
|
|
TestFrameworkManager::registerTestFramework(&theQtTestFramework());
|
|
|
|
|
TestFrameworkManager::registerTestFramework(&theQuickTestFramework());
|
|
|
|
|
TestFrameworkManager::registerTestFramework(&theGTestFramework());
|
|
|
|
|
TestFrameworkManager::registerTestFramework(&theBoostTestFramework());
|
|
|
|
|
TestFrameworkManager::registerTestFramework(&theCatchFramework());
|
2019-08-19 09:33:14 +02:00
|
|
|
|
2023-07-27 16:40:46 +02:00
|
|
|
TestFrameworkManager::registerTestTool(&theCTestTool());
|
2020-10-19 14:47:45 +02:00
|
|
|
|
2019-08-19 09:33:14 +02:00
|
|
|
m_resultsPane = TestResultsPane::instance();
|
|
|
|
|
|
2023-11-14 18:00:23 +01:00
|
|
|
setupAutotestProjectPanel();
|
2019-08-19 09:33:14 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
TestProjectSettings *projectSettings(ProjectExplorer::Project *project)
|
2019-08-05 15:47:10 +02:00
|
|
|
{
|
|
|
|
|
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
|
|
|
{
|
2024-01-29 11:13:06 +01:00
|
|
|
const Id menuId = Constants::MENU_ID;
|
|
|
|
|
|
|
|
|
|
MenuBuilder(menuId)
|
|
|
|
|
.setTitle(Tr::tr("&Tests"))
|
|
|
|
|
.setOnAllDisabledBehavior(ActionContainer::Show)
|
|
|
|
|
.addToContainer(Core::Constants::M_TOOLS);
|
2015-03-30 07:47:07 +02:00
|
|
|
|
2023-12-19 15:50:49 +01:00
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_ALL_ID)
|
|
|
|
|
.setText(Tr::tr("Run &All Tests"))
|
|
|
|
|
.setIcon(Utils::Icons::RUN_SMALL.icon())
|
|
|
|
|
.setToolTip(Tr::tr("Run All Tests"))
|
|
|
|
|
.setDefaultKeySequence(Tr::tr("Ctrl+Meta+T, Ctrl+Meta+A"), Tr::tr("Alt+Shift+T,Alt+A"))
|
2024-01-29 11:13:06 +01:00
|
|
|
.addToContainer(menuId)
|
2023-12-19 15:50:49 +01:00
|
|
|
.setEnabled(false)
|
|
|
|
|
.addOnTriggered(this, [this] { onRunAllTriggered(TestRunMode::Run); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_ALL_NODEPLOY_ID)
|
|
|
|
|
.setText(Tr::tr("Run All Tests Without Deployment"))
|
|
|
|
|
.setIcon(Utils::Icons::RUN_SMALL.icon())
|
|
|
|
|
.setToolTip(Tr::tr("Run All Tests Without Deployment"))
|
|
|
|
|
.setDefaultKeySequence(Tr::tr("Ctrl+Meta+T, Ctrl+Meta+E"), Tr::tr("Alt+Shift+T,Alt+E"))
|
2024-01-29 11:13:06 +01:00
|
|
|
.addToContainer(menuId)
|
2023-12-19 15:50:49 +01:00
|
|
|
.setEnabled(false)
|
|
|
|
|
.addOnTriggered(this, [this] { onRunAllTriggered(TestRunMode::RunWithoutDeploy); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_SELECTED_ID)
|
|
|
|
|
.setText(Tr::tr("&Run Selected Tests"))
|
|
|
|
|
.setIcon(Utils::Icons::RUN_SELECTED.icon())
|
|
|
|
|
.setToolTip(Tr::tr("Run Selected Tests"))
|
|
|
|
|
.setDefaultKeySequence(Tr::tr("Ctrl+Meta+T, Ctrl+Meta+R"), Tr::tr("Alt+Shift+T,Alt+R"))
|
2024-01-29 11:13:06 +01:00
|
|
|
.addToContainer(menuId)
|
2023-12-19 15:50:49 +01:00
|
|
|
.setEnabled(false)
|
|
|
|
|
.addOnTriggered(this, [this] { onRunSelectedTriggered(TestRunMode::Run); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_SELECTED_NODEPLOY_ID)
|
|
|
|
|
.setText(Tr::tr("&Run Selected Tests Without Deployment"))
|
|
|
|
|
.setIcon(Utils::Icons::RUN_SELECTED.icon())
|
|
|
|
|
.setToolTip(Tr::tr("Run Selected Tests Without Deployment"))
|
|
|
|
|
.setDefaultKeySequence(Tr::tr("Ctrl+Meta+T, Ctrl+Meta+W"), Tr::tr("Alt+Shift+T,Alt+W"))
|
2024-01-29 11:13:06 +01:00
|
|
|
.addToContainer(menuId)
|
2023-12-19 15:50:49 +01:00
|
|
|
.setEnabled(false)
|
|
|
|
|
.addOnTriggered(this, [this] { onRunSelectedTriggered(TestRunMode::RunWithoutDeploy); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_FAILED_ID)
|
|
|
|
|
.setText(Tr::tr("Run &Failed Tests"))
|
|
|
|
|
.setIcon(Icons::RUN_FAILED.icon())
|
|
|
|
|
.setToolTip(Tr::tr("Run Failed Tests"))
|
|
|
|
|
.setDefaultKeySequence(Tr::tr("Ctrl+Meta+T, Ctrl+Meta+F"), Tr::tr("Alt+Shift+T,Alt+F"))
|
2024-01-29 11:13:06 +01:00
|
|
|
.addToContainer(menuId)
|
2023-12-19 15:50:49 +01:00
|
|
|
.setEnabled(false)
|
|
|
|
|
.addOnTriggered(this, [this] { onRunFailedTriggered(); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_FILE_ID)
|
|
|
|
|
.setText(Tr::tr("Run Tests for &Current File"))
|
|
|
|
|
.setIcon(Utils::Icons::RUN_FILE.icon())
|
|
|
|
|
.setToolTip(Tr::tr("Run Tests for Current File"))
|
|
|
|
|
.setDefaultKeySequence(Tr::tr("Ctrl+Meta+T, Ctrl+Meta+C"), Tr::tr("Alt+Shift+T,Alt+C"))
|
2024-01-29 11:13:06 +01:00
|
|
|
.addToContainer(menuId)
|
2023-12-19 15:50:49 +01:00
|
|
|
.setEnabled(false)
|
|
|
|
|
.addOnTriggered(this, [this] { onRunFileTriggered(); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_DISABLE_TMP)
|
|
|
|
|
.setText(Tr::tr("Disable Temporarily"))
|
|
|
|
|
.setToolTip(Tr::tr("Disable scanning and other actions until explicitly rescanning, "
|
|
|
|
|
"re-enabling, or restarting Qt Creator."))
|
|
|
|
|
.setCheckable(true)
|
2024-01-29 11:13:06 +01:00
|
|
|
.addToContainer(menuId)
|
2023-12-19 15:50:49 +01:00
|
|
|
.addOnTriggered(this, [this](bool on) { onDisableTemporarily(on); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_SCAN_ID)
|
|
|
|
|
.setText(Tr::tr("Re&scan Tests"))
|
|
|
|
|
.setDefaultKeySequence(Tr::tr("Ctrl+Meta+T, Ctrl+Meta+S"), Tr::tr("Alt+Shift+T,Alt+S"))
|
2024-01-29 11:13:06 +01:00
|
|
|
.addToContainer(menuId)
|
2023-12-19 15:50:49 +01:00
|
|
|
.addOnTriggered(this, [] {
|
|
|
|
|
if (dd->m_testCodeParser.state() == TestCodeParser::DisabledTemporarily)
|
|
|
|
|
dd->onDisableTemporarily(false); // Rescan Test should explicitly re-enable
|
|
|
|
|
else
|
|
|
|
|
dd->m_testCodeParser.updateTestTree();
|
|
|
|
|
});
|
2015-03-30 07:47:07 +02:00
|
|
|
|
2017-06-15 10:43:44 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
2024-01-12 08:51:08 +01:00
|
|
|
this, &updateMenuItemsEnabledState);
|
2017-06-15 10:43:44 +02:00
|
|
|
connect(BuildManager::instance(), &BuildManager::buildQueueFinished,
|
2024-01-12 08:51:08 +01:00
|
|
|
this, &updateMenuItemsEnabledState);
|
2020-02-24 15:55:15 +01:00
|
|
|
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::runActionsUpdated,
|
2024-01-12 08:51:08 +01:00
|
|
|
this, &updateMenuItemsEnabledState);
|
2020-03-16 12:59:23 +01:00
|
|
|
connect(&dd->m_testTreeModel, &TestTreeModel::testTreeModelChanged,
|
2024-01-12 08:51:08 +01:00
|
|
|
this, &updateMenuItemsEnabledState);
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
2023-07-12 09:47:29 +02:00
|
|
|
const CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::snapshot();
|
2023-02-06 16:25:50 +01:00
|
|
|
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);
|
2024-01-12 08:51:08 +01:00
|
|
|
const TestFrameworks active = activeTestFrameworks();
|
2023-02-06 16:25:50 +01:00
|
|
|
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-08-25 14:10:10 +02:00
|
|
|
void AutotestPluginPrivate::onDisableTemporarily(bool disable)
|
|
|
|
|
{
|
|
|
|
|
if (disable) {
|
|
|
|
|
// cancel running parse
|
|
|
|
|
m_testCodeParser.aboutToShutdown(false);
|
|
|
|
|
// clear model
|
|
|
|
|
m_testTreeModel.removeAllTestItems();
|
|
|
|
|
m_testTreeModel.removeAllTestToolItems();
|
2024-01-12 08:51:08 +01:00
|
|
|
updateMenuItemsEnabledState();
|
2023-08-25 14:10:10 +02:00
|
|
|
} else {
|
|
|
|
|
// re-enable
|
|
|
|
|
m_testCodeParser.setState(TestCodeParser::Idle);
|
|
|
|
|
// trigger scan
|
|
|
|
|
m_testCodeParser.updateTestTree();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
TestFrameworks activeTestFrameworks()
|
2023-02-06 14:29:24 +01:00
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
void updateMenuItemsEnabledState()
|
2015-03-30 07:47:07 +02:00
|
|
|
{
|
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;
|
2023-08-25 14:10:10 +02:00
|
|
|
const bool disabled = dd->m_testCodeParser.state() == TestCodeParser::DisabledTemporarily;
|
|
|
|
|
const bool canScan = disabled || (!dd->m_testRunner.isTestRunning()
|
|
|
|
|
&& dd->m_testCodeParser.state() == TestCodeParser::Idle);
|
2020-03-16 12:59:23 +01:00
|
|
|
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
|
2023-08-25 14:10:10 +02:00
|
|
|
const bool canRun = !disabled && 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
|
|
|
}
|
|
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice)
|
2018-08-08 12:40:03 +02:00
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
if (dd)
|
|
|
|
|
dd->m_runconfigCache.insert(buildTargetKey, choice);
|
2018-08-08 12:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
ChoicePair cachedChoiceFor(const QString &buildTargetKey)
|
2018-08-08 12:40:03 +02:00
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
return dd ? dd->m_runconfigCache.value(buildTargetKey) : ChoicePair();
|
2018-08-08 12:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
void clearChoiceCache()
|
2018-08-08 12:40:03 +02:00
|
|
|
{
|
2020-02-28 12:27:13 +01:00
|
|
|
if (dd)
|
|
|
|
|
dd->m_runconfigCache.clear();
|
2018-08-08 12:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
void popupResultsPane()
|
2019-03-13 11:05:22 +01:00
|
|
|
{
|
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
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
// AutotestPlugin
|
|
|
|
|
|
|
|
|
|
class AutotestPlugin final : public ExtensionSystem::IPlugin
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "AutoTest.json")
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
AutotestPlugin()
|
|
|
|
|
{
|
|
|
|
|
// needed to be used in QueuedConnection connects
|
|
|
|
|
qRegisterMetaType<TestResult>();
|
|
|
|
|
qRegisterMetaType<TestTreeItem *>();
|
|
|
|
|
qRegisterMetaType<TestCodeLocationAndType>();
|
|
|
|
|
// warm up meta type system to be able to read Qt::CheckState with persistent settings
|
|
|
|
|
qRegisterMetaType<Qt::CheckState>();
|
|
|
|
|
|
|
|
|
|
setupTestNavigationWidgetFactory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~AutotestPlugin() final
|
|
|
|
|
{
|
|
|
|
|
delete dd;
|
|
|
|
|
dd = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initialize() final
|
|
|
|
|
{
|
2024-01-29 09:02:52 +01:00
|
|
|
setupTestSettingsPage();
|
|
|
|
|
|
2024-01-12 08:51:08 +01:00
|
|
|
dd = new AutotestPluginPrivate;
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface",
|
|
|
|
|
[] { return dd->m_loadProjectScenario(); });
|
|
|
|
|
|
2024-01-19 12:25:23 +01:00
|
|
|
addTestCreator(createAutotestUnitTests);
|
2024-01-12 08:51:08 +01:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT);
|
|
|
|
|
if (!contextMenu) // if QC is started without CppEditor plugin
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const Id menuId = "Autotest.TestUnderCursor";
|
|
|
|
|
ActionContainer * const runTestMenu = ActionManager::createMenu(menuId);
|
|
|
|
|
runTestMenu->menu()->setTitle(Tr::tr("Run Test Under Cursor"));
|
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
|
contextMenu->addMenu(runTestMenu);
|
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_UCURSOR)
|
|
|
|
|
.setText(Tr::tr("&Run Test"))
|
|
|
|
|
.setEnabled(false)
|
|
|
|
|
.setIcon(Utils::Icons::RUN_SMALL.icon())
|
|
|
|
|
.addToContainer(menuId)
|
|
|
|
|
.addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::Run); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_UCURSOR_NODEPLOY)
|
|
|
|
|
.setText(Tr::tr("Run Test Without Deployment"))
|
|
|
|
|
.setIcon(Utils::Icons::RUN_SMALL.icon())
|
|
|
|
|
.setEnabled(false)
|
|
|
|
|
.addToContainer(menuId)
|
|
|
|
|
.addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::RunWithoutDeploy); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_DBG_UCURSOR)
|
|
|
|
|
.setText(Tr::tr("&Debug Test"))
|
|
|
|
|
.setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon())
|
|
|
|
|
.setEnabled(false)
|
|
|
|
|
.addToContainer(menuId)
|
|
|
|
|
.addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::Debug); });
|
|
|
|
|
|
|
|
|
|
ActionBuilder(this, Constants::ACTION_RUN_DBG_UCURSOR_NODEPLOY)
|
|
|
|
|
.setText(Tr::tr("Debug Test Without Deployment"))
|
|
|
|
|
.setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon())
|
|
|
|
|
.setEnabled(false)
|
|
|
|
|
.addToContainer(menuId)
|
|
|
|
|
.addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::DebugWithoutDeploy); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShutdownFlag aboutToShutdown() final
|
|
|
|
|
{
|
|
|
|
|
dd->m_testCodeParser.aboutToShutdown(true);
|
|
|
|
|
dd->m_testTreeModel.disconnect();
|
|
|
|
|
return SynchronousShutdown;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // Autotest::Internal
|
2019-08-19 09:33:14 +02:00
|
|
|
|
|
|
|
|
#include "autotestplugin.moc"
|