diff --git a/addons/externaltools/autotests/externaltooltest.cpp b/addons/externaltools/autotests/externaltooltest.cpp index 2132afb96..efd551ded 100644 --- a/addons/externaltools/autotests/externaltooltest.cpp +++ b/addons/externaltools/autotests/externaltooltest.cpp @@ -1,86 +1,86 @@ /* This file is part of the KDE project * * Copyright 2019 Dominik Haumann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "externaltooltest.h" #include "../kateexternaltool.h" #include "../katetoolrunner.h" #include #include #include #include QTEST_MAIN(ExternalToolTest) void ExternalToolTest::initTestCase() { } void ExternalToolTest::cleanupTestCase() { } void ExternalToolTest::testLoadSave() { KConfig config; KConfigGroup cg(&config, "tool"); KateExternalTool tool; tool.name = QStringLiteral("git cola"); tool.icon = QStringLiteral("git-cola"); tool.executable = QStringLiteral("git-cola"); tool.arguments = QStringLiteral("none"); tool.command = QStringLiteral("git-cola"); tool.mimetypes = QStringList{ QStringLiteral("everything") }; tool.hasexec = true; tool.actionName = QStringLiteral("asdf"); tool.cmdname = QStringLiteral("git-cola"); tool.saveMode = KateExternalTool::SaveMode::None; tool.save(cg); KateExternalTool copiedTool; copiedTool.load(cg); QCOMPARE(tool.name, copiedTool.name); } void ExternalToolTest::testRunListDirectory() { KateExternalTool tool; tool.name = QStringLiteral("ls"); tool.icon = QStringLiteral("none"); tool.executable = QStringLiteral("ls"); tool.arguments = QStringLiteral("/"); tool.command = QStringLiteral("ls"); tool.mimetypes = QStringList{}; tool.hasexec = true; tool.actionName = QStringLiteral("ls"); tool.cmdname = QStringLiteral("ls"); tool.saveMode = KateExternalTool::SaveMode::None; KateToolRunner runner(&tool); runner.run(); runner.waitForFinished(); - QVERIFY(!runner.stdoutData().isEmpty()); - QVERIFY(!runner.stdoutData().contains(QStringLiteral("/home"))); + QVERIFY(!runner.outputData().isEmpty()); + QVERIFY(!runner.outputData().contains(QStringLiteral("/home"))); } // kate: space-indent on; indent-width 4; replace-tabs on; diff --git a/addons/externaltools/katetoolrunner.cpp b/addons/externaltools/katetoolrunner.cpp index 1a8b57f7a..c7421a63e 100644 --- a/addons/externaltools/katetoolrunner.cpp +++ b/addons/externaltools/katetoolrunner.cpp @@ -1,67 +1,78 @@ /* This file is part of the KDE project * * Copyright 2019 Dominik Haumann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "katetoolrunner.h" #include "kateexternaltool.h" KateToolRunner::KateToolRunner(KateExternalTool * tool) : m_tool(tool) , m_process(new QProcess()) { } KateToolRunner::~KateToolRunner() { delete m_process; m_process = nullptr; } void KateToolRunner::run() { m_process->setProcessChannelMode(QProcess::MergedChannels); QObject::connect(m_process, &QProcess::readyRead, this, &KateToolRunner::slotReadyRead); QObject::connect(m_process, static_cast(&QProcess::finished), this, &KateToolRunner::toolFinished); m_process->start(m_tool->executable, { m_tool->arguments }); } void KateToolRunner::waitForFinished() { m_process->waitForFinished(); } -QString KateToolRunner::stdoutData() const +QString KateToolRunner::outputData() const { - return QString::fromLocal8Bit(m_output ); + return QString::fromLocal8Bit(m_output); } void KateToolRunner::slotReadyRead() { m_output += m_process->readAll(); } void KateToolRunner::toolFinished(int exitCode, QProcess::ExitStatus exitStatus) { + if (exitCode != 0) { + // FIXME: somehow tell user + return; + } + + if (exitStatus != QProcess::NormalExit) { + // FIXME: somehow tell user + return; + } + + // FIXME: process m_output depending on the tool's outputMode } // kate: space-indent on; indent-width 4; replace-tabs on; diff --git a/addons/externaltools/katetoolrunner.h b/addons/externaltools/katetoolrunner.h index b619ba969..3b46cc1a2 100644 --- a/addons/externaltools/katetoolrunner.h +++ b/addons/externaltools/katetoolrunner.h @@ -1,69 +1,69 @@ /* This file is part of the KDE project * * Copyright 2019 Dominik Haumann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KTEXTEDITOR_EXTERNALTOOLRUNNER_H #define KTEXTEDITOR_EXTERNALTOOLRUNNER_H #include #include #include #include class KateExternalTool; class QProcess; /** * Helper class to run a KateExternalTool. */ class KateToolRunner : public QObject { public: KateToolRunner(KateExternalTool * tool); KateToolRunner(const KateToolRunner &) = delete; void operator=(const KateToolRunner &) = delete; ~KateToolRunner(); void run(); void waitForFinished(); - QString stdoutData() const; + QString outputData() const; private Q_SLOTS: /** * More tool output is available */ void slotReadyRead(); /** * Analysis finished * @param exitCode analyzer process exit code * @param exitStatus analyzer process exit status */ void toolFinished(int exitCode, QProcess::ExitStatus exitStatus); private: KateExternalTool * m_tool; QProcess * m_process = nullptr; QByteArray m_output; }; #endif // KTEXTEDITOR_EXTERNALTOOLRUNNER_H // kate: space-indent on; indent-width 4; replace-tabs on;