forked from qt-creator/qt-creator
AutoTest: Support run failed
If the last run had failures and the test frameworks support matching a test result to a test tree item give the user an easy way to re-run all failed tests. Change-Id: I4f3150ca8a6514c09cf7ca819f84e38c6419a310 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -33,6 +33,7 @@ namespace Constants {
|
||||
const char ACTION_SCAN_ID[] = "AutoTest.ScanAction";
|
||||
const char ACTION_RUN_ALL_ID[] = "AutoTest.RunAll";
|
||||
const char ACTION_RUN_SELECTED_ID[] = "AutoTest.RunSelected";
|
||||
const char ACTION_RUN_FAILED_ID[] = "AutoTest.RunFailed";
|
||||
const char ACTION_RUN_FILE_ID[] = "AutoTest.RunFile";
|
||||
const char ACTION_RUN_UCURSOR[] = "AutoTest.RunUnderCursor";
|
||||
const char ACTION_RUN_DBG_UCURSOR[] = "AutoTest.RunDebugUnderCursor";
|
||||
|
||||
@@ -36,6 +36,8 @@ const Utils::Icon SORT_NATURALLY({
|
||||
const Utils::Icon RUN_SELECTED_OVERLAY({
|
||||
{":/utils/images/runselected_boxes.png", Utils::Theme::BackgroundColorDark},
|
||||
{":/utils/images/runselected_tickmarks.png", Utils::Theme::IconsBaseColor}});
|
||||
const Utils::Icon RUN_FAILED_OVERLAY({
|
||||
{":utils/images/iconoverlay_reset.png", Utils::Theme::OutputPanes_TestXPassTextColor}});
|
||||
const Utils::Icon RUN_FILE_OVERLAY({
|
||||
{":/utils/images/run_file.png", Utils::Theme::IconsBaseColor}});
|
||||
const Utils::Icon RESULT_PASS({
|
||||
|
||||
@@ -97,6 +97,7 @@ public:
|
||||
void initializeMenuEntries();
|
||||
void onRunAllTriggered();
|
||||
void onRunSelectedTriggered();
|
||||
void onRunFailedTriggered();
|
||||
void onRunFileTriggered();
|
||||
void onRunUnderCursorTriggered(TestRunMode mode);
|
||||
|
||||
@@ -222,7 +223,20 @@ void AutotestPluginPrivate::initializeMenuEntries()
|
||||
action->setEnabled(false);
|
||||
menu->addAction(command);
|
||||
|
||||
action = new QAction(tr("Run Tests for Current &File"), this);
|
||||
action = new QAction(tr("Run &Failed Tests"), this);
|
||||
Utils::Icon runFailedIcon = Utils::Icons::RUN_SMALL_TOOLBAR;
|
||||
for (const Utils::IconMaskAndColor &maskAndColor: Icons::RUN_FAILED_OVERLAY)
|
||||
runFailedIcon.append(maskAndColor);
|
||||
action->setIcon(runFailedIcon.icon());
|
||||
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);
|
||||
Utils::Icon runFileIcon = Utils::Icons::RUN_SMALL_TOOLBAR;
|
||||
for (const Utils::IconMaskAndColor &maskAndColor : Icons::RUN_FILE_OVERLAY)
|
||||
runFileIcon.append(maskAndColor);
|
||||
@@ -230,7 +244,7 @@ void AutotestPluginPrivate::initializeMenuEntries()
|
||||
action->setToolTip(tr("Run Tests for Current File"));
|
||||
command = ActionManager::registerAction(action, Constants::ACTION_RUN_FILE_ID);
|
||||
command->setDefaultKeySequence(
|
||||
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+F") : tr("Alt+Shift+T,Alt+F")));
|
||||
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+C") : tr("Alt+Shift+T,Alt+C")));
|
||||
connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunFileTriggered);
|
||||
action->setEnabled(false);
|
||||
menu->addAction(command);
|
||||
@@ -311,6 +325,15 @@ void AutotestPluginPrivate::onRunSelectedTriggered()
|
||||
m_testRunner.prepareToRunTests(TestRunMode::Run);
|
||||
}
|
||||
|
||||
void AutotestPluginPrivate::onRunFailedTriggered()
|
||||
{
|
||||
const QList<TestConfiguration *> failed = m_testTreeModel.getFailedTests();
|
||||
if (failed.isEmpty()) // the framework might not be able to provide them
|
||||
return;
|
||||
m_testRunner.setSelectedTests(failed);
|
||||
m_testRunner.prepareToRunTests(TestRunMode::Run);
|
||||
}
|
||||
|
||||
void AutotestPluginPrivate::onRunFileTriggered()
|
||||
{
|
||||
const IDocument *document = EditorManager::currentDocument();
|
||||
@@ -384,9 +407,11 @@ void AutotestPlugin::updateMenuItemsEnabledState()
|
||||
&& project && !project->needsConfiguration()
|
||||
&& target && target->activeRunConfiguration()
|
||||
&& !ProjectExplorer::BuildManager::isBuilding();
|
||||
const bool canRunFailed = canRun && dd->m_testTreeModel.hasFailedTests();
|
||||
|
||||
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_FAILED_ID)->action()->setEnabled(canRunFailed);
|
||||
ActionManager::command(Constants::ACTION_RUN_FILE_ID)->action()->setEnabled(canRun);
|
||||
ActionManager::command(Constants::ACTION_SCAN_ID)->action()->setEnabled(canScan);
|
||||
|
||||
|
||||
@@ -185,6 +185,8 @@ void TestResultsPane::createToolButtons()
|
||||
m_runSelected = new QToolButton(m_treeView);
|
||||
m_runSelected->setDefaultAction(ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action());
|
||||
|
||||
m_runFailed = new QToolButton(m_treeView);
|
||||
m_runFailed->setDefaultAction(ActionManager::command(Constants::ACTION_RUN_FAILED_ID)->action());
|
||||
m_runFile = new QToolButton(m_treeView);
|
||||
m_runFile->setDefaultAction(ActionManager::command(Constants::ACTION_RUN_FILE_ID)->action());
|
||||
|
||||
@@ -304,7 +306,7 @@ QWidget *TestResultsPane::outputWidget(QWidget *parent)
|
||||
|
||||
QList<QWidget *> TestResultsPane::toolBarWidgets() const
|
||||
{
|
||||
return {m_expandCollapse, m_runAll, m_runSelected, m_runFile, m_stopTestRun,
|
||||
return {m_expandCollapse, m_runAll, m_runSelected, m_runFailed, m_runFile, m_stopTestRun,
|
||||
m_outputToggleButton, m_filterButton};
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,6 @@ public:
|
||||
void addTestResult(const TestResultPtr &result);
|
||||
void addOutputLine(const QByteArray &outputLine, OutputChannel channel);
|
||||
void showTestResult(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
explicit TestResultsPane(QObject *parent = nullptr);
|
||||
|
||||
@@ -136,6 +135,7 @@ private:
|
||||
QToolButton *m_expandCollapse;
|
||||
QToolButton *m_runAll;
|
||||
QToolButton *m_runSelected;
|
||||
QToolButton *m_runFailed;
|
||||
QToolButton *m_runFile;
|
||||
QToolButton *m_stopTestRun;
|
||||
QToolButton *m_filterButton;
|
||||
|
||||
Reference in New Issue
Block a user