From 743a37dda253e3e727cfeebc0e00897cd9cf38a9 Mon Sep 17 00:00:00 2001 From: Sergey Morozov Date: Thu, 3 May 2018 23:29:18 +0300 Subject: [PATCH] Autotest: Add editor's mark for test's failed assertion Tooltip shows failure details. Click navigates to test results pane. Task-number: QTCREATORBUG-20328 Change-Id: I47ffaef1f035dfc5b244644a099e1c7d8db6715b Reviewed-by: Christian Stenger --- src/plugins/autotest/autotest.pro | 6 ++- src/plugins/autotest/autotest.qbs | 2 + src/plugins/autotest/autotestconstants.h | 1 + src/plugins/autotest/testeditormark.cpp | 45 ++++++++++++++++++++++ src/plugins/autotest/testeditormark.h | 48 ++++++++++++++++++++++++ src/plugins/autotest/testresultspane.cpp | 41 ++++++++++++++++++++ src/plugins/autotest/testresultspane.h | 6 +++ 7 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 src/plugins/autotest/testeditormark.cpp create mode 100644 src/plugins/autotest/testeditormark.h diff --git a/src/plugins/autotest/autotest.pro b/src/plugins/autotest/autotest.pro index f8ae42d7466..d8af2b75c76 100644 --- a/src/plugins/autotest/autotest.pro +++ b/src/plugins/autotest/autotest.pro @@ -49,7 +49,8 @@ SOURCES += \ quick/quicktestvisitors.cpp \ quick/quicktestframework.cpp \ quick/quicktest_utils.cpp \ - testframeworkmanager.cpp + testframeworkmanager.cpp \ + testeditormark.cpp HEADERS += \ @@ -105,7 +106,8 @@ HEADERS += \ quick/quicktestframework.h \ testframeworkmanager.h \ testrunconfiguration.h \ - itestsettingspage.h + itestsettingspage.h \ + testeditormark.h RESOURCES += \ autotest.qrc diff --git a/src/plugins/autotest/autotest.qbs b/src/plugins/autotest/autotest.qbs index 62c5d9fd8bc..b25a27ce9cf 100644 --- a/src/plugins/autotest/autotest.qbs +++ b/src/plugins/autotest/autotest.qbs @@ -41,6 +41,8 @@ QtcPlugin { "testcodeparser.h", "testconfiguration.cpp", "testconfiguration.h", + "testeditormark.cpp", + "testeditormark.h", "testnavigationwidget.cpp", "testnavigationwidget.h", "testresult.cpp", diff --git a/src/plugins/autotest/autotestconstants.h b/src/plugins/autotest/autotestconstants.h index 19dde06e97a..2de0fe43abc 100644 --- a/src/plugins/autotest/autotestconstants.h +++ b/src/plugins/autotest/autotestconstants.h @@ -45,6 +45,7 @@ const char AUTOTEST_SETTINGS_TR[] = QT_TRANSLATE_NOOP("AutoTest", "Testing const char FRAMEWORK_PREFIX[] = "AutoTest.Framework."; const char SETTINGSPAGE_PREFIX[] = "A.AutoTest."; const char SETTINGSGROUP[] = "Autotest"; +const char TASK_MARK_ID[] = "Autotest.TaskMark"; } // namespace Constants namespace Internal { diff --git a/src/plugins/autotest/testeditormark.cpp b/src/plugins/autotest/testeditormark.cpp new file mode 100644 index 00000000000..61e53ef4bdb --- /dev/null +++ b/src/plugins/autotest/testeditormark.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** 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. +** +** 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. +** +****************************************************************************/ + +#include "testeditormark.h" +#include "testresultspane.h" + +namespace Autotest { +namespace Internal { + +TestEditorMark::TestEditorMark(QPersistentModelIndex item, const Utils::FileName &file, int line) + : TextEditor::TextMark(file, line, Core::Id(Constants::TASK_MARK_ID)), + m_item(item) +{ +} + +void TestEditorMark::clicked() +{ + auto instance = TestResultsPane::instance(); + instance->showTestResult(m_item); +} + +} // namespace Internal +} // namespace Autotest diff --git a/src/plugins/autotest/testeditormark.h b/src/plugins/autotest/testeditormark.h new file mode 100644 index 00000000000..c84e8efb738 --- /dev/null +++ b/src/plugins/autotest/testeditormark.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** 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. +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include + +#include + +namespace Autotest { +namespace Internal { + +class TestEditorMark : public TextEditor::TextMark +{ +public: + TestEditorMark(QPersistentModelIndex item, const Utils::FileName &file, int line); + + bool isClickable() const override { return true; } + void clicked() override; + +private: + QPersistentModelIndex m_item; +}; + +} // namespace Internal +} // namespace Autotest diff --git a/src/plugins/autotest/testresultspane.cpp b/src/plugins/autotest/testresultspane.cpp index 3286d5490c1..d2b3ec97dd1 100644 --- a/src/plugins/autotest/testresultspane.cpp +++ b/src/plugins/autotest/testresultspane.cpp @@ -32,6 +32,7 @@ #include "testsettings.h" #include "testtreemodel.h" #include "testcodeparser.h" +#include "testeditormark.h" #include #include @@ -273,6 +274,7 @@ void TestResultsPane::clearContents() connect(m_treeView->verticalScrollBar(), &QScrollBar::rangeChanged, this, &TestResultsPane::onScrollBarRangeChanged, Qt::UniqueConnection); m_textOutput->clear(); + clearMarks(); } void TestResultsPane::visibilityChanged(bool /*visible*/) @@ -508,6 +510,7 @@ void TestResultsPane::onTestRunFinished() this, &TestResultsPane::onScrollBarRangeChanged); if (!m_treeView->isVisible()) popup(Core::IOutputPane::NoModeSwitch); + createMarks(); } void TestResultsPane::onScrollBarRangeChanged(int, int max) @@ -629,5 +632,43 @@ QString TestResultsPane::getWholeOutput(const QModelIndex &parent) return output; } +void TestResultsPane::createMarks(const QModelIndex &parent) +{ + for (int row = 0, count = m_model->rowCount(parent); row < count; ++row) { + const QModelIndex index = m_model->index(row, 0, parent); + const TestResult *result = m_model->testResult(index); + QTC_ASSERT(result, continue); + + if (m_model->hasChildren(index)) + createMarks(index); + + const QVector interested{Result::Fail, Result::UnexpectedPass}; + if (interested.contains(result->result())) { + const Utils::FileName fileName = Utils::FileName::fromString(result->fileName()); + TestEditorMark *mark = new TestEditorMark(index, fileName, result->line()); + mark->setIcon(index.data(Qt::DecorationRole).value()); + mark->setColor(Utils::Theme::OutputPanes_TestFailTextColor); + mark->setPriority(TextEditor::TextMark::NormalPriority); + mark->setToolTip(result->description()); + m_marks << mark; + } + } +} + +void TestResultsPane::clearMarks() +{ + qDeleteAll(m_marks); + m_marks.clear(); +} + +void TestResultsPane::showTestResult(const QModelIndex &index) +{ + QModelIndex mapped = m_filterModel->mapFromSource(index); + if (mapped.isValid()) { + popup(Core::IOutputPane::NoModeSwitch); + m_treeView->setCurrentIndex(mapped); + } +} + } // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/testresultspane.h b/src/plugins/autotest/testresultspane.h index 12a3720091c..7156cd1c859 100644 --- a/src/plugins/autotest/testresultspane.h +++ b/src/plugins/autotest/testresultspane.h @@ -53,6 +53,7 @@ namespace Internal { class TestResultModel; class TestResultFilterModel; class TestResult; +class TestEditorMark; class ResultsTreeView : public Utils::TreeView { @@ -92,6 +93,7 @@ public: void addTestResult(const TestResultPtr &result); void addOutput(const QByteArray &output); + void showTestResult(const QModelIndex &index); private: explicit TestResultsPane(QObject *parent = 0); @@ -117,6 +119,9 @@ private: void toggleOutputStyle(); QString getWholeOutput(const QModelIndex &parent = QModelIndex()); + void createMarks(const QModelIndex& parent = QModelIndex()); + void clearMarks(); + QStackedWidget *m_outputWidget; QFrame *m_summaryWidget; QLabel *m_summaryLabel; @@ -135,6 +140,7 @@ private: bool m_autoScroll = false; bool m_atEnd = false; bool m_testRunning = false; + QVector m_marks; }; } // namespace Internal