2013-08-05 21:30:41 +03:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Andre Hartmann.
|
2013-08-05 21:30:41 +03:00
|
|
|
** Contact: aha_1980@gmx.de
|
|
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-08-05 21:30:41 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-08-05 21:30:41 +03:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "customparser.h"
|
2020-05-06 12:51:08 +02:00
|
|
|
|
2013-08-05 21:30:41 +03:00
|
|
|
#include "projectexplorerconstants.h"
|
2020-05-12 08:32:38 +02:00
|
|
|
#include "projectexplorer.h"
|
2020-05-06 12:51:08 +02:00
|
|
|
#include "task.h"
|
2013-08-05 21:30:41 +03:00
|
|
|
|
2020-05-06 12:51:08 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2013-08-05 21:30:41 +03:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2020-05-06 12:51:08 +02:00
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPair>
|
2013-08-05 21:30:41 +03:00
|
|
|
#include <QString>
|
2020-05-06 12:51:08 +02:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
# include <QTest>
|
|
|
|
|
|
|
|
|
|
# include "projectexplorer.h"
|
|
|
|
|
# include "outputparser_test.h"
|
|
|
|
|
#endif
|
2013-08-05 21:30:41 +03:00
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
using namespace Utils;
|
2020-05-06 12:51:08 +02:00
|
|
|
|
|
|
|
|
const char idKey[] = "Id";
|
|
|
|
|
const char nameKey[] = "Name";
|
|
|
|
|
const char errorKey[] = "Error";
|
|
|
|
|
const char warningKey[] = "Warning";
|
|
|
|
|
const char patternKey[] = "Pattern";
|
|
|
|
|
const char lineNumberCapKey[] = "LineNumberCap";
|
|
|
|
|
const char fileNameCapKey[] = "FileNameCap";
|
|
|
|
|
const char messageCapKey[] = "MessageCap";
|
|
|
|
|
const char channelKey[] = "Channel";
|
|
|
|
|
const char exampleKey[] = "Example";
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
2013-08-05 21:30:41 +03:00
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
bool CustomParserExpression::operator ==(const CustomParserExpression &other) const
|
|
|
|
|
{
|
|
|
|
|
return pattern() == other.pattern() && fileNameCap() == other.fileNameCap()
|
|
|
|
|
&& lineNumberCap() == other.lineNumberCap() && messageCap() == other.messageCap()
|
|
|
|
|
&& channel() == other.channel() && example() == other.example();
|
|
|
|
|
}
|
2013-08-05 21:30:41 +03:00
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
QString CustomParserExpression::pattern() const
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
2015-12-16 21:04:45 +01:00
|
|
|
return m_regExp.pattern();
|
2013-08-05 21:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
2020-05-06 12:51:08 +02:00
|
|
|
void CustomParserExpression::setPattern(const QString &pattern)
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
2015-12-16 21:04:45 +01:00
|
|
|
m_regExp.setPattern(pattern);
|
|
|
|
|
QTC_CHECK(m_regExp.isValid());
|
|
|
|
|
}
|
2013-08-05 21:30:41 +03:00
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
CustomParserExpression::CustomParserChannel CustomParserExpression::channel() const
|
|
|
|
|
{
|
|
|
|
|
return m_channel;
|
2013-08-05 21:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
void CustomParserExpression::setChannel(CustomParserExpression::CustomParserChannel channel)
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
2015-12-16 21:04:45 +01:00
|
|
|
QTC_ASSERT(channel > ParseNoChannel && channel <= ParseBothChannels,
|
|
|
|
|
channel = ParseBothChannels);
|
|
|
|
|
|
|
|
|
|
m_channel = channel;
|
2013-08-05 21:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
QString CustomParserExpression::example() const
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
2015-12-16 21:04:45 +01:00
|
|
|
return m_example;
|
2013-08-05 21:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
void CustomParserExpression::setExample(const QString &example)
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
2015-12-16 21:04:45 +01:00
|
|
|
m_example = example;
|
2013-08-05 21:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
int CustomParserExpression::messageCap() const
|
|
|
|
|
{
|
|
|
|
|
return m_messageCap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomParserExpression::setMessageCap(int messageCap)
|
|
|
|
|
{
|
|
|
|
|
m_messageCap = messageCap;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 12:51:08 +02:00
|
|
|
QVariantMap CustomParserExpression::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map;
|
|
|
|
|
map.insert(patternKey, pattern());
|
|
|
|
|
map.insert(messageCapKey, messageCap());
|
|
|
|
|
map.insert(fileNameCapKey, fileNameCap());
|
|
|
|
|
map.insert(lineNumberCapKey, lineNumberCap());
|
|
|
|
|
map.insert(exampleKey, example());
|
|
|
|
|
map.insert(channelKey, channel());
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomParserExpression::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
setPattern(map.value(patternKey).toString());
|
|
|
|
|
setMessageCap(map.value(messageCapKey).toInt());
|
|
|
|
|
setFileNameCap(map.value(fileNameCapKey).toInt());
|
|
|
|
|
setLineNumberCap(map.value(lineNumberCapKey).toInt());
|
|
|
|
|
setExample(map.value(exampleKey).toString());
|
|
|
|
|
int channel = map.value(channelKey).toInt();
|
|
|
|
|
if (channel == ParseNoChannel || channel > ParseBothChannels)
|
|
|
|
|
channel = ParseStdErrChannel;
|
|
|
|
|
setChannel(static_cast<CustomParserChannel>(channel));
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
int CustomParserExpression::lineNumberCap() const
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
|
|
|
|
return m_lineNumberCap;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
void CustomParserExpression::setLineNumberCap(int lineNumberCap)
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
|
|
|
|
m_lineNumberCap = lineNumberCap;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
int CustomParserExpression::fileNameCap() const
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
|
|
|
|
return m_fileNameCap;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
void CustomParserExpression::setFileNameCap(int fileNameCap)
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
|
|
|
|
m_fileNameCap = fileNameCap;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
bool CustomParserSettings::operator ==(const CustomParserSettings &other) const
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
2020-05-06 12:51:08 +02:00
|
|
|
return id == other.id && displayName == other.displayName
|
|
|
|
|
&& error == other.error && warning == other.warning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap CustomParserSettings::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map;
|
|
|
|
|
map.insert(idKey, id.toSetting());
|
|
|
|
|
map.insert(nameKey, displayName);
|
|
|
|
|
map.insert(errorKey, error.toMap());
|
|
|
|
|
map.insert(warningKey, warning.toMap());
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomParserSettings::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
id = Core::Id::fromSetting(map.value(idKey));
|
|
|
|
|
displayName = map.value(nameKey).toString();
|
|
|
|
|
error.fromMap(map.value(errorKey).toMap());
|
|
|
|
|
warning.fromMap(map.value(warningKey).toMap());
|
2013-08-05 21:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
CustomParser::CustomParser(const CustomParserSettings &settings)
|
|
|
|
|
{
|
2018-06-14 21:10:02 +02:00
|
|
|
setObjectName("CustomParser");
|
2015-12-16 21:04:45 +01:00
|
|
|
|
|
|
|
|
setSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 21:30:41 +03:00
|
|
|
void CustomParser::setSettings(const CustomParserSettings &settings)
|
|
|
|
|
{
|
2015-12-16 21:04:45 +01:00
|
|
|
m_error = settings.error;
|
|
|
|
|
m_warning = settings.warning;
|
2013-08-05 21:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
2020-05-06 12:51:08 +02:00
|
|
|
CustomParser *CustomParser::createFromId(Core::Id id)
|
|
|
|
|
{
|
|
|
|
|
const Internal::CustomParserSettings parser = findOrDefault(ProjectExplorerPlugin::customParsers(),
|
|
|
|
|
[id](const Internal::CustomParserSettings &p) { return p.id == id; });
|
|
|
|
|
if (parser.id.isValid())
|
|
|
|
|
return new CustomParser(parser);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 21:45:41 +02:00
|
|
|
Core::Id CustomParser::id()
|
|
|
|
|
{
|
|
|
|
|
return Core::Id("ProjectExplorer.OutputParser.Custom");
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 13:53:05 +02:00
|
|
|
OutputLineParser::Result CustomParser::handleLine(const QString &line, OutputFormat type)
|
2020-04-08 09:42:51 +02:00
|
|
|
{
|
|
|
|
|
const CustomParserExpression::CustomParserChannel channel = type == StdErrFormat
|
|
|
|
|
? CustomParserExpression::ParseStdErrChannel
|
|
|
|
|
: CustomParserExpression::ParseStdOutChannel;
|
2020-04-16 13:53:05 +02:00
|
|
|
return parseLine(line, channel);
|
2020-04-08 09:42:51 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-16 13:53:05 +02:00
|
|
|
OutputLineParser::Result CustomParser::hasMatch(
|
|
|
|
|
const QString &line,
|
|
|
|
|
CustomParserExpression::CustomParserChannel channel,
|
|
|
|
|
const CustomParserExpression &expression,
|
|
|
|
|
Task::TaskType taskType
|
|
|
|
|
)
|
2013-08-05 21:30:41 +03:00
|
|
|
{
|
2015-12-16 21:04:45 +01:00
|
|
|
if (!(channel & expression.channel()))
|
2020-04-16 13:53:05 +02:00
|
|
|
return Status::NotHandled;
|
2015-12-16 21:04:45 +01:00
|
|
|
|
|
|
|
|
if (expression.pattern().isEmpty())
|
2020-04-16 13:53:05 +02:00
|
|
|
return Status::NotHandled;
|
2013-08-05 21:30:41 +03:00
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
const QRegularExpressionMatch match = expression.match(line);
|
2015-12-16 18:51:32 +01:00
|
|
|
if (!match.hasMatch())
|
2020-04-16 13:53:05 +02:00
|
|
|
return Status::NotHandled;
|
2013-08-05 21:30:41 +03:00
|
|
|
|
2020-04-07 13:49:34 +02:00
|
|
|
const FilePath fileName = absoluteFilePath(FilePath::fromString(
|
|
|
|
|
match.captured(expression.fileNameCap())));
|
2015-12-16 21:04:45 +01:00
|
|
|
const int lineNumber = match.captured(expression.lineNumberCap()).toInt();
|
|
|
|
|
const QString message = match.captured(expression.messageCap());
|
2020-04-16 13:53:05 +02:00
|
|
|
LinkSpecs linkSpecs;
|
|
|
|
|
addLinkSpecForAbsoluteFilePath(linkSpecs, fileName, lineNumber, match,
|
|
|
|
|
expression.fileNameCap());
|
|
|
|
|
scheduleTask(CompileTask(taskType, message, fileName, lineNumber), 1);
|
2020-05-06 12:51:08 +02:00
|
|
|
return {Status::Done, linkSpecs};
|
2013-08-05 21:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
2020-04-16 13:53:05 +02:00
|
|
|
OutputLineParser::Result CustomParser::parseLine(
|
|
|
|
|
const QString &rawLine,
|
|
|
|
|
CustomParserExpression::CustomParserChannel channel
|
|
|
|
|
)
|
2015-12-16 21:04:45 +01:00
|
|
|
{
|
|
|
|
|
const QString line = rawLine.trimmed();
|
2020-04-16 13:53:05 +02:00
|
|
|
const Result res = hasMatch(line, channel, m_error, Task::Error);
|
|
|
|
|
if (res.status != Status::NotHandled)
|
|
|
|
|
return res;
|
2015-12-16 21:04:45 +01:00
|
|
|
return hasMatch(line, channel, m_warning, Task::Warning);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 12:51:08 +02:00
|
|
|
namespace {
|
|
|
|
|
class SelectionWidget : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
SelectionWidget(QWidget *parent = nullptr) : QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
const auto layout = new QVBoxLayout(this);
|
|
|
|
|
const auto explanatoryLabel = new QLabel(tr(
|
|
|
|
|
"Custom output parsers scan command line output for user-provided error patterns<br>"
|
|
|
|
|
"in order to create entries in the issues pane.<br>"
|
|
|
|
|
"The parsers can be configured <a href=\"dummy\">here</a>."));
|
|
|
|
|
layout->addWidget(explanatoryLabel);
|
|
|
|
|
connect(explanatoryLabel, &QLabel::linkActivated, [] {
|
|
|
|
|
Core::ICore::showOptionsDialog(Constants::CUSTOM_PARSERS_SETTINGS_PAGE_ID);
|
|
|
|
|
});
|
|
|
|
|
updateUi();
|
|
|
|
|
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::customParsersChanged,
|
|
|
|
|
this, &SelectionWidget::updateUi);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setSelectedParsers(const QList<Core::Id> &parsers)
|
|
|
|
|
{
|
|
|
|
|
for (const auto &p : qAsConst(parserCheckBoxes))
|
|
|
|
|
p.first->setChecked(parsers.contains(p.second));
|
|
|
|
|
emit selectionChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Core::Id> selectedParsers() const
|
|
|
|
|
{
|
|
|
|
|
QList<Core::Id> parsers;
|
|
|
|
|
for (const auto &p : qAsConst(parserCheckBoxes)) {
|
|
|
|
|
if (p.first->isChecked())
|
|
|
|
|
parsers << p.second;
|
|
|
|
|
}
|
|
|
|
|
return parsers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void selectionChanged();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void updateUi()
|
|
|
|
|
{
|
|
|
|
|
const auto layout = qobject_cast<QVBoxLayout *>(this->layout());
|
|
|
|
|
QTC_ASSERT(layout, return);
|
|
|
|
|
const QList<Core::Id> parsers = selectedParsers();
|
|
|
|
|
for (const auto &p : qAsConst(parserCheckBoxes))
|
|
|
|
|
delete p.first;
|
|
|
|
|
parserCheckBoxes.clear();
|
|
|
|
|
for (const CustomParserSettings &s : ProjectExplorerPlugin::customParsers()) {
|
|
|
|
|
const auto checkBox = new QCheckBox(s.displayName, this);
|
|
|
|
|
connect(checkBox, &QCheckBox::stateChanged,
|
|
|
|
|
this, &SelectionWidget::selectionChanged);
|
|
|
|
|
parserCheckBoxes << qMakePair(checkBox, s.id);
|
|
|
|
|
layout->addWidget(checkBox);
|
|
|
|
|
}
|
|
|
|
|
setSelectedParsers(parsers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QPair<QCheckBox *, Core::Id>> parserCheckBoxes;
|
|
|
|
|
};
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
CustomParsersSelectionWidget::CustomParsersSelectionWidget(QWidget *parent) : DetailsWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
const auto widget = new SelectionWidget(this);
|
|
|
|
|
connect(widget, &SelectionWidget::selectionChanged, [this] {
|
|
|
|
|
updateSummary();
|
|
|
|
|
emit selectionChanged();
|
|
|
|
|
});
|
|
|
|
|
setWidget(widget);
|
|
|
|
|
updateSummary();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomParsersSelectionWidget::setSelectedParsers(const QList<Core::Id> &parsers)
|
|
|
|
|
{
|
|
|
|
|
qobject_cast<SelectionWidget *>(widget())->setSelectedParsers(parsers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Core::Id> CustomParsersSelectionWidget::selectedParsers() const
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<SelectionWidget *>(widget())->selectedParsers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomParsersSelectionWidget::updateSummary()
|
|
|
|
|
{
|
|
|
|
|
const QList<Core::Id> parsers
|
|
|
|
|
= qobject_cast<SelectionWidget *>(widget())->selectedParsers();
|
|
|
|
|
if (parsers.isEmpty())
|
|
|
|
|
setSummaryText(tr("There are no custom parsers active"));
|
|
|
|
|
else
|
|
|
|
|
setSummaryText(tr("There are %n custom parsers active", nullptr, parsers.count()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CustomParsersAspect::CustomParsersAspect(Target *target)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(target)
|
|
|
|
|
setId("CustomOutputParsers");
|
|
|
|
|
setSettingsKey("CustomOutputParsers");
|
|
|
|
|
setDisplayName(tr("Custom Output Parsers"));
|
|
|
|
|
setConfigWidgetCreator([this] {
|
|
|
|
|
const auto widget = new CustomParsersSelectionWidget;
|
|
|
|
|
widget->setSelectedParsers(m_parsers);
|
|
|
|
|
connect(widget, &CustomParsersSelectionWidget::selectionChanged,
|
|
|
|
|
this, [this, widget] { m_parsers = widget->selectedParsers(); });
|
|
|
|
|
return widget;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomParsersAspect::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
m_parsers = transform(map.value(settingsKey()).toList(), &Core::Id::fromSetting);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomParsersAspect::toMap(QVariantMap &map) const
|
|
|
|
|
{
|
|
|
|
|
map.insert(settingsKey(), transform(m_parsers, &Core::Id::toSetting));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2013-08-05 21:30:41 +03:00
|
|
|
// Unit tests:
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
|
2020-05-06 12:51:08 +02:00
|
|
|
using namespace Internal;
|
2013-08-05 21:30:41 +03:00
|
|
|
|
|
|
|
|
void ProjectExplorerPlugin::testCustomOutputParsers_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QString>("input");
|
2018-03-07 18:44:28 +01:00
|
|
|
QTest::addColumn<QString>("workDir");
|
2013-08-05 21:30:41 +03:00
|
|
|
QTest::addColumn<OutputParserTester::Channel>("inputChannel");
|
2015-12-16 21:04:45 +01:00
|
|
|
QTest::addColumn<CustomParserExpression::CustomParserChannel>("filterErrorChannel");
|
|
|
|
|
QTest::addColumn<CustomParserExpression::CustomParserChannel>("filterWarningChannel");
|
|
|
|
|
QTest::addColumn<QString>("errorPattern");
|
|
|
|
|
QTest::addColumn<int>("errorFileNameCap");
|
|
|
|
|
QTest::addColumn<int>("errorLineNumberCap");
|
|
|
|
|
QTest::addColumn<int>("errorMessageCap");
|
|
|
|
|
QTest::addColumn<QString>("warningPattern");
|
|
|
|
|
QTest::addColumn<int>("warningFileNameCap");
|
|
|
|
|
QTest::addColumn<int>("warningLineNumberCap");
|
|
|
|
|
QTest::addColumn<int>("warningMessageCap");
|
2013-08-05 21:30:41 +03:00
|
|
|
QTest::addColumn<QString>("childStdOutLines");
|
|
|
|
|
QTest::addColumn<QString>("childStdErrLines");
|
2019-05-27 16:09:44 +02:00
|
|
|
QTest::addColumn<Tasks >("tasks");
|
2013-08-05 21:30:41 +03:00
|
|
|
QTest::addColumn<QString>("outputLines");
|
|
|
|
|
|
2018-06-14 21:10:02 +02:00
|
|
|
const QString simplePattern = "^([a-z]+\\.[a-z]+):(\\d+): error: ([^\\s].+)$";
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath fileName = FilePath::fromUserInput("main.c");
|
2013-08-05 21:30:41 +03:00
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
QTest::newRow("empty patterns")
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString::fromLatin1("Sometext")
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< OutputParserTester::STDOUT
|
2015-12-16 21:04:45 +01:00
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString::fromLatin1("Sometext\n") << QString()
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("pass-through stdout")
|
|
|
|
|
<< QString::fromLatin1("Sometext")
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< OutputParserTester::STDOUT
|
2015-12-16 21:04:45 +01:00
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString::fromLatin1("Sometext\n") << QString()
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("pass-through stderr")
|
|
|
|
|
<< QString::fromLatin1("Sometext")
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< OutputParserTester::STDERR
|
2015-12-16 21:04:45 +01:00
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString() << QString::fromLatin1("Sometext\n")
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString();
|
|
|
|
|
|
2018-06-14 21:10:02 +02:00
|
|
|
const QString simpleError = "main.c:9: error: `sfasdf' undeclared (first use this function)";
|
|
|
|
|
const QString simpleErrorPassThrough = simpleError + '\n';
|
|
|
|
|
const QString message = "`sfasdf' undeclared (first use this function)";
|
2013-08-05 21:30:41 +03:00
|
|
|
|
|
|
|
|
QTest::newRow("simple error")
|
|
|
|
|
<< simpleError
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< OutputParserTester::STDERR
|
2015-12-16 21:04:45 +01:00
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 0 << 0 << 0
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error, message, fileName, 9)})
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString();
|
|
|
|
|
|
2018-03-07 18:44:28 +01:00
|
|
|
const QString pathPattern = "^([a-z\\./]+):(\\d+): error: ([^\\s].+)$";
|
|
|
|
|
QString workingDir = "/home/src/project";
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath expandedFileName = FilePath::fromString("/home/src/project/main.c");
|
2018-03-07 18:44:28 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("simple error with expanded path")
|
|
|
|
|
<< "main.c:9: error: `sfasdf' undeclared (first use this function)"
|
|
|
|
|
<< workingDir
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< pathPattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 0 << 0 << 0
|
|
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error, message, expandedFileName, 9)})
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
expandedFileName = FilePath::fromString("/home/src/project/subdir/main.c");
|
2018-03-07 18:44:28 +01:00
|
|
|
QTest::newRow("simple error with subdir path")
|
|
|
|
|
<< "subdir/main.c:9: error: `sfasdf' undeclared (first use this function)"
|
|
|
|
|
<< workingDir
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< pathPattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 0 << 0 << 0
|
|
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error, message, expandedFileName, 9)})
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
workingDir = "/home/src/build-project";
|
|
|
|
|
QTest::newRow("simple error with buildir path")
|
|
|
|
|
<< "../project/subdir/main.c:9: error: `sfasdf' undeclared (first use this function)"
|
|
|
|
|
<< workingDir
|
|
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< pathPattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 0 << 0 << 0
|
|
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error, message, expandedFileName, 9)})
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
QTest::newRow("simple error on wrong channel")
|
|
|
|
|
<< simpleError
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< OutputParserTester::STDOUT
|
|
|
|
|
<< CustomParserExpression::ParseStdErrChannel << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 0 << 0 << 0
|
|
|
|
|
<< simpleErrorPassThrough << QString()
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("simple error on other wrong channel")
|
|
|
|
|
<< simpleError
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< CustomParserExpression::ParseStdOutChannel << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 0 << 0 << 0
|
|
|
|
|
<< QString() << simpleErrorPassThrough
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
2018-06-14 21:10:02 +02:00
|
|
|
const QString simpleError2 = "Error: Line 19 in main.c: `sfasdf' undeclared (first use this function)";
|
|
|
|
|
const QString simplePattern2 = "^Error: Line (\\d+) in ([a-z]+\\.[a-z]+): ([^\\s].+)$";
|
2013-08-05 21:30:41 +03:00
|
|
|
const int lineNumber2 = 19;
|
|
|
|
|
|
|
|
|
|
QTest::newRow("another simple error on stderr")
|
|
|
|
|
<< simpleError2
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< OutputParserTester::STDERR
|
2015-12-16 21:04:45 +01:00
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern2 << 2 << 1 << 3
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error, message, fileName, lineNumber2)})
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("another simple error on stdout")
|
|
|
|
|
<< simpleError2
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< OutputParserTester::STDOUT
|
2015-12-16 21:04:45 +01:00
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern2 << 2 << 1 << 3
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error, message, fileName, lineNumber2)})
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString();
|
|
|
|
|
|
2018-06-14 21:10:02 +02:00
|
|
|
const QString simpleWarningPattern = "^([a-z]+\\.[a-z]+):(\\d+): warning: ([^\\s].+)$";
|
|
|
|
|
const QString simpleWarning = "main.c:1234: warning: `helloWorld' declared but not used";
|
|
|
|
|
const QString warningMessage = "`helloWorld' declared but not used";
|
2015-12-16 21:04:45 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("simple warning")
|
|
|
|
|
<< simpleWarning
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
|
|
|
|
<< simpleWarningPattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Warning, warningMessage, fileName, 1234)})
|
2015-12-16 21:04:45 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
2018-06-14 21:10:02 +02:00
|
|
|
const QString simpleWarning2 = "Warning: `helloWorld' declared but not used (main.c:19)";
|
|
|
|
|
const QString simpleWarningPassThrough2 = simpleWarning2 + '\n';
|
|
|
|
|
const QString simpleWarningPattern2 = "^Warning: (.*) \\(([a-z]+\\.[a-z]+):(\\d+)\\)$";
|
2015-12-16 21:04:45 +01:00
|
|
|
|
|
|
|
|
QTest::newRow("another simple warning on stdout")
|
|
|
|
|
<< simpleWarning2
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< OutputParserTester::STDOUT
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseStdOutChannel
|
|
|
|
|
<< simplePattern2 << 1 << 2 << 3
|
|
|
|
|
<< simpleWarningPattern2 << 2 << 3 << 1
|
|
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Warning, warningMessage, fileName, lineNumber2)})
|
2015-12-16 21:04:45 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("warning on wrong channel")
|
|
|
|
|
<< simpleWarning2
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< OutputParserTester::STDOUT
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseStdErrChannel
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
|
|
|
|
<< simpleWarningPattern2 << 2 << 3 << 1
|
|
|
|
|
<< simpleWarningPassThrough2 << QString()
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("warning on other wrong channel")
|
|
|
|
|
<< simpleWarning2
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseStdOutChannel
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
|
|
|
|
<< simpleWarningPattern2 << 2 << 3 << 1
|
|
|
|
|
<< QString() << simpleWarningPassThrough2
|
2019-05-27 16:09:44 +02:00
|
|
|
<< Tasks()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("error and *warning*")
|
|
|
|
|
<< simpleWarning
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern << 1 << 2 << 3
|
|
|
|
|
<< simpleWarningPattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Warning, warningMessage, fileName, 1234)})
|
2015-12-16 21:04:45 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
|
|
|
|
QTest::newRow("*error* when equal pattern")
|
|
|
|
|
<< simpleError
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2015-12-16 21:04:45 +01:00
|
|
|
<< OutputParserTester::STDERR
|
|
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< simplePattern << 1 << 2 << 3
|
|
|
|
|
<< simplePattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error, message, fileName, 9)})
|
2015-12-16 21:04:45 +01:00
|
|
|
<< QString();
|
|
|
|
|
|
2018-06-14 21:10:02 +02:00
|
|
|
const QString unitTestError = "../LedDriver/LedDriverTest.c:63: FAIL: Expected 0x0080 Was 0xffff";
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath unitTestFileName = FilePath::fromUserInput("../LedDriver/LedDriverTest.c");
|
2018-06-14 21:10:02 +02:00
|
|
|
const QString unitTestMessage = "Expected 0x0080 Was 0xffff";
|
|
|
|
|
const QString unitTestPattern = "^([^:]+):(\\d+): FAIL: ([^\\s].+)$";
|
2013-08-05 21:30:41 +03:00
|
|
|
const int unitTestLineNumber = 63;
|
|
|
|
|
|
|
|
|
|
QTest::newRow("unit test error")
|
|
|
|
|
<< unitTestError
|
2018-03-07 18:44:28 +01:00
|
|
|
<< QString()
|
2013-08-05 21:30:41 +03:00
|
|
|
<< OutputParserTester::STDOUT
|
2015-12-16 21:04:45 +01:00
|
|
|
<< CustomParserExpression::ParseBothChannels << CustomParserExpression::ParseBothChannels
|
|
|
|
|
<< unitTestPattern << 1 << 2 << 3
|
|
|
|
|
<< QString() << 1 << 2 << 3
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString() << QString()
|
2020-01-15 08:56:11 +01:00
|
|
|
<< Tasks({CompileTask(Task::Error, unitTestMessage, unitTestFileName, unitTestLineNumber)})
|
2013-08-05 21:30:41 +03:00
|
|
|
<< QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectExplorerPlugin::testCustomOutputParsers()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(QString, input);
|
2018-03-07 18:44:28 +01:00
|
|
|
QFETCH(QString, workDir);
|
2013-08-05 21:30:41 +03:00
|
|
|
QFETCH(OutputParserTester::Channel, inputChannel);
|
2015-12-16 21:04:45 +01:00
|
|
|
QFETCH(CustomParserExpression::CustomParserChannel, filterErrorChannel);
|
|
|
|
|
QFETCH(CustomParserExpression::CustomParserChannel, filterWarningChannel);
|
|
|
|
|
QFETCH(QString, errorPattern);
|
|
|
|
|
QFETCH(int, errorFileNameCap);
|
|
|
|
|
QFETCH(int, errorLineNumberCap);
|
|
|
|
|
QFETCH(int, errorMessageCap);
|
|
|
|
|
QFETCH(QString, warningPattern);
|
|
|
|
|
QFETCH(int, warningFileNameCap);
|
|
|
|
|
QFETCH(int, warningLineNumberCap);
|
|
|
|
|
QFETCH(int, warningMessageCap);
|
2013-08-05 21:30:41 +03:00
|
|
|
QFETCH(QString, childStdOutLines);
|
|
|
|
|
QFETCH(QString, childStdErrLines);
|
2019-05-27 16:09:44 +02:00
|
|
|
QFETCH(Tasks, tasks);
|
2013-08-05 21:30:41 +03:00
|
|
|
QFETCH(QString, outputLines);
|
|
|
|
|
|
2015-12-16 21:04:45 +01:00
|
|
|
CustomParserSettings settings;
|
|
|
|
|
settings.error.setPattern(errorPattern);
|
|
|
|
|
settings.error.setFileNameCap(errorFileNameCap);
|
|
|
|
|
settings.error.setLineNumberCap(errorLineNumberCap);
|
|
|
|
|
settings.error.setMessageCap(errorMessageCap);
|
|
|
|
|
settings.error.setChannel(filterErrorChannel);
|
|
|
|
|
settings.warning.setPattern(warningPattern);
|
|
|
|
|
settings.warning.setFileNameCap(warningFileNameCap);
|
|
|
|
|
settings.warning.setLineNumberCap(warningLineNumberCap);
|
|
|
|
|
settings.warning.setMessageCap(warningMessageCap);
|
|
|
|
|
settings.warning.setChannel(filterWarningChannel);
|
|
|
|
|
|
2013-08-05 21:30:41 +03:00
|
|
|
CustomParser *parser = new CustomParser;
|
2015-12-16 21:04:45 +01:00
|
|
|
parser->setSettings(settings);
|
2020-04-07 13:49:34 +02:00
|
|
|
parser->addSearchDir(FilePath::fromString(workDir));
|
|
|
|
|
parser->skipFileExistsCheck();
|
2013-08-05 21:30:41 +03:00
|
|
|
|
|
|
|
|
OutputParserTester testbench;
|
2020-04-08 17:45:39 +02:00
|
|
|
testbench.addLineParser(parser);
|
2013-08-05 21:30:41 +03:00
|
|
|
testbench.testParsing(input, inputChannel,
|
|
|
|
|
tasks, childStdOutLines, childStdErrLines,
|
|
|
|
|
outputLines);
|
|
|
|
|
}
|
2020-05-06 12:51:08 +02:00
|
|
|
|
2013-08-05 21:30:41 +03:00
|
|
|
#endif
|
2020-05-06 12:51:08 +02:00
|
|
|
|
2020-05-12 08:32:38 +02:00
|
|
|
} // namespace ProjectExplorer
|
|
|
|
|
|
2020-05-06 12:51:08 +02:00
|
|
|
#include <customparser.moc>
|