ProjectExplorer: Move outputparser test class creation class

... closer to the tested code.

Change-Id: Icdc2efcae8bfa6129ed641116ca6e8c917d8c0f3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2024-01-17 14:10:27 +01:00
parent 4d1f1f98d1
commit a4e6d36427
4 changed files with 53 additions and 38 deletions

View File

@@ -1,17 +1,42 @@
// Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifdef WITH_TESTS
#include "ioutputparser.h"
#include "outputparser_test.h" #include "outputparser_test.h"
#include "projectexplorer.h"
#include "task.h" #include "task.h"
#include "taskhub.h" #include "taskhub.h"
#if defined(WITH_TESTS)
#include <QtTest> #include <QtTest>
namespace ProjectExplorer { namespace ProjectExplorer {
class TestTerminator final : public OutputTaskParser
{
public:
explicit TestTerminator(OutputParserTester *t)
: m_tester(t)
{
if (!t->lineParsers().isEmpty()) {
for (const Utils::FilePath &searchDir : t->lineParsers().constFirst()->searchDirectories())
addSearchDir(searchDir);
}
}
private:
Result handleLine(const QString &line, Utils::OutputFormat type) final
{
if (type == Utils::StdOutFormat)
m_tester->m_receivedStdOutChildLine.append(line + '\n');
else
m_tester->m_receivedStdErrChildLine.append(line + '\n');
return Status::Done;
}
OutputParserTester *m_tester = nullptr;
};
static inline QByteArray msgFileComparisonFail(const Utils::FilePath &f1, const Utils::FilePath &f2) static inline QByteArray msgFileComparisonFail(const Utils::FilePath &f1, const Utils::FilePath &f2)
{ {
const QString result = '"' + f1.toUserOutput() + "\" != \"" + f2.toUserOutput() + '"'; const QString result = '"' + f1.toUserOutput() + "\" != \"" + f2.toUserOutput() + '"';
@@ -99,25 +124,16 @@ void OutputParserTester::reset()
m_receivedOutput.clear(); m_receivedOutput.clear();
} }
TestTerminator::TestTerminator(OutputParserTester *t) : class OutputParserTest final : public QObject
m_tester(t)
{ {
if (!t->lineParsers().isEmpty()) { Q_OBJECT
for (const Utils::FilePath &searchDir : t->lineParsers().constFirst()->searchDirectories())
addSearchDir(searchDir);
}
}
Utils::OutputLineParser::Result TestTerminator::handleLine(const QString &line, Utils::OutputFormat type) private slots:
{ void testAnsiFilterOutputParser_data();
if (type == Utils::StdOutFormat) void testAnsiFilterOutputParser();
m_tester->m_receivedStdOutChildLine.append(line + '\n'); };
else
m_tester->m_receivedStdErrChildLine.append(line + '\n');
return Status::Done;
}
void ProjectExplorerPlugin::testAnsiFilterOutputParser_data() void OutputParserTest::testAnsiFilterOutputParser_data()
{ {
QTest::addColumn<QString>("input"); QTest::addColumn<QString>("input");
QTest::addColumn<OutputParserTester::Channel>("inputChannel"); QTest::addColumn<OutputParserTester::Channel>("inputChannel");
@@ -162,7 +178,7 @@ void ProjectExplorerPlugin::testAnsiFilterOutputParser_data()
<< QString::fromLatin1("test\n") << QString(); << QString::fromLatin1("test\n") << QString();
} }
void ProjectExplorerPlugin::testAnsiFilterOutputParser() void OutputParserTest::testAnsiFilterOutputParser()
{ {
OutputParserTester testbench; OutputParserTester testbench;
QFETCH(QString, input); QFETCH(QString, input);
@@ -175,6 +191,13 @@ void ProjectExplorerPlugin::testAnsiFilterOutputParser()
QString()); QString());
} }
QObject *createOutputParserTest()
{
return new OutputParserTest;
}
} // namespace ProjectExplorer } // namespace ProjectExplorer
#endif #include "outputparser_test.moc"
#endif // WITH_TESTS

View File

@@ -3,13 +3,14 @@
#pragma once #pragma once
#if defined(WITH_TESTS) #ifdef WITH_TESTS
#include "projectexplorer_export.h" #include "projectexplorer_export.h"
#include "ioutputparser.h"
#include "task.h" #include "task.h"
#include <utils/outputformatter.h>
namespace ProjectExplorer { namespace ProjectExplorer {
class TestTerminator; class TestTerminator;
@@ -52,18 +53,7 @@ private:
friend class TestTerminator; friend class TestTerminator;
}; };
class TestTerminator : public OutputTaskParser QObject *createOutputParserTest();
{
Q_OBJECT
public:
explicit TestTerminator(OutputParserTester *t);
private:
Result handleLine(const QString &line, Utils::OutputFormat type) override;
OutputParserTester *m_tester = nullptr;
};
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -53,6 +53,7 @@
#include "kitmanager.h" #include "kitmanager.h"
#include "miniprojecttargetselector.h" #include "miniprojecttargetselector.h"
#include "namedwidget.h" #include "namedwidget.h"
#include "outputparser_test.h"
#include "parseissuesdialog.h" #include "parseissuesdialog.h"
#include "processstep.h" #include "processstep.h"
#include "project.h" #include "project.h"
@@ -810,6 +811,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
{ {
Q_UNUSED(error) Q_UNUSED(error)
#ifdef WITH_TESTS
addTestCreator(createOutputParserTest);
#endif
setupGccToolchains(); setupGccToolchains();
setupMsvcToolchain(); setupMsvcToolchain();
setupClangClToolchain(); setupClangClToolchain();

View File

@@ -198,9 +198,6 @@ private slots:
void testJsonWizardsComboBox(); void testJsonWizardsComboBox();
void testJsonWizardsIconList(); void testJsonWizardsIconList();
void testAnsiFilterOutputParser_data();
void testAnsiFilterOutputParser();
void testGccOutputParsers_data(); void testGccOutputParsers_data();
void testGccOutputParsers(); void testGccOutputParsers();