forked from qt-creator/qt-creator
AutoTest: Clear up and generalize
Instead of transforming forth and back the output try to handle the output once correctly and pass it line-wise around. This also ensures that we always get a single line when appending the output which will be necessary later on. Change-Id: I3e9c6db5f81172997dfe566eee9a86bfe2f17a1f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -182,7 +182,7 @@ void BoostTestOutputReader::handleMessageMatch(const QRegularExpressionMatch &ma
|
|||||||
sendCompleteInformation();
|
sendCompleteInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoostTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLine)
|
void BoostTestOutputReader::processOutputLine(const QByteArray &outputLine)
|
||||||
{
|
{
|
||||||
static QRegularExpression newTestStart("^Running (\\d+) test cases?\\.\\.\\.$");
|
static QRegularExpression newTestStart("^Running (\\d+) test cases?\\.\\.\\.$");
|
||||||
static QRegularExpression dependency("^Including test case (.+) as a dependency of "
|
static QRegularExpression dependency("^Including test case (.+) as a dependency of "
|
||||||
@@ -210,7 +210,7 @@ void BoostTestOutputReader::processOutputLine(const QByteArray &outputLineWithNe
|
|||||||
"test module \"(.*}\"; see standard output for details");
|
"test module \"(.*}\"; see standard output for details");
|
||||||
QString noErrors("*** No errors detected");
|
QString noErrors("*** No errors detected");
|
||||||
|
|
||||||
const QString line = QString::fromUtf8(chopLineBreak(outputLineWithNewLine));
|
const QString line = QString::fromUtf8(outputLine);
|
||||||
if (line.trimmed().isEmpty())
|
if (line.trimmed().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -376,28 +376,11 @@ void BoostTestOutputReader::processOutputLine(const QByteArray &outputLineWithNe
|
|||||||
m_description.append(line);
|
m_description.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoostTestOutputReader::processStdError(const QByteArray &output)
|
void BoostTestOutputReader::processStdError(const QByteArray &outputLine)
|
||||||
{
|
{
|
||||||
// we need to process the output, Boost UTF uses both out streams
|
// we need to process the output, Boost UTF uses both out streams
|
||||||
int start = 0;
|
processOutputLine(outputLine);
|
||||||
int index = -1;
|
emit newOutputLineAvailable(outputLine);
|
||||||
while ((index = output.indexOf('\n', start)) != -1) {
|
|
||||||
const QByteArray &line = output.mid(start, index - start + 1);
|
|
||||||
if (!line.isEmpty()) {
|
|
||||||
if (line != QByteArray(1, '\n'))
|
|
||||||
processOutputLine(line);
|
|
||||||
emit newOutputAvailable(line);
|
|
||||||
}
|
|
||||||
start = index + 1;
|
|
||||||
}
|
|
||||||
if (start > 0) { // remove? this never happens
|
|
||||||
const QByteArray lastLine = output.mid(start) + '\n';
|
|
||||||
if (!lastLine.isEmpty()) {
|
|
||||||
if (lastLine != QByteArray(1, '\n'))
|
|
||||||
processOutputLine(lastLine);
|
|
||||||
emit newOutputAvailable(lastLine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResultPtr BoostTestOutputReader::createDefaultResult() const
|
TestResultPtr BoostTestOutputReader::createDefaultResult() const
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ public:
|
|||||||
QProcess *testApplication, const QString &buildDirectory,
|
QProcess *testApplication, const QString &buildDirectory,
|
||||||
const QString &projectFile, LogLevel log, ReportLevel report);
|
const QString &projectFile, LogLevel log, ReportLevel report);
|
||||||
protected:
|
protected:
|
||||||
void processOutputLine(const QByteArray &outputLineWithNewLine) override;
|
void processOutputLine(const QByteArray &outputLine) override;
|
||||||
void processStdError(const QByteArray &output) override;
|
void processStdError(const QByteArray &outputLine) override;
|
||||||
TestResultPtr createDefaultResult() const override;
|
TestResultPtr createDefaultResult() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ GTestOutputReader::GTestOutputReader(const QFutureInterface<TestResultPtr> &futu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLine)
|
void GTestOutputReader::processOutputLine(const QByteArray &outputLine)
|
||||||
{
|
{
|
||||||
static const QRegularExpression newTestStarts("^\\[-{10}\\] \\d+ tests? from (.*)$");
|
static const QRegularExpression newTestStarts("^\\[-{10}\\] \\d+ tests? from (.*)$");
|
||||||
static const QRegularExpression testEnds("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$");
|
static const QRegularExpression testEnds("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$");
|
||||||
@@ -74,7 +74,7 @@ void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLin
|
|||||||
static const QRegularExpression iterations("^Repeating all tests "
|
static const QRegularExpression iterations("^Repeating all tests "
|
||||||
"\\(iteration (\\d+)\\) \\. \\. \\.$");
|
"\\(iteration (\\d+)\\) \\. \\. \\.$");
|
||||||
|
|
||||||
const QString line = QString::fromLatin1(chopLineBreak(outputLineWithNewLine));
|
const QString line = QString::fromLatin1(outputLine);
|
||||||
if (line.trimmed().isEmpty())
|
if (line.trimmed().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
QProcess *testApplication, const QString &buildDirectory,
|
QProcess *testApplication, const QString &buildDirectory,
|
||||||
const QString &projectFile);
|
const QString &projectFile);
|
||||||
protected:
|
protected:
|
||||||
void processOutputLine(const QByteArray &outputLineWithNewLine) override;
|
void processOutputLine(const QByteArray &outputLine) override;
|
||||||
TestResultPtr createDefaultResult() const override;
|
TestResultPtr createDefaultResult() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ static QStringList extractFunctionInformation(const QString &testClassName,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtTestOutputReader::processPlainTextOutput(const QByteArray &outputLineWithNewLine)
|
void QtTestOutputReader::processPlainTextOutput(const QByteArray &outputLine)
|
||||||
{
|
{
|
||||||
static const QRegularExpression start("^[*]{9} Start testing of (.*) [*]{9}$");
|
static const QRegularExpression start("^[*]{9} Start testing of (.*) [*]{9}$");
|
||||||
static const QRegularExpression config("^Config: Using QtTest library (.*), "
|
static const QRegularExpression config("^Config: Using QtTest library (.*), "
|
||||||
@@ -375,7 +375,7 @@ void QtTestOutputReader::processPlainTextOutput(const QByteArray &outputLineWith
|
|||||||
if (m_futureInterface.isCanceled())
|
if (m_futureInterface.isCanceled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QString line = QString::fromUtf8(chopLineBreak(outputLineWithNewLine));
|
const QString line = QString::fromUtf8(outputLine);
|
||||||
QRegularExpressionMatch match;
|
QRegularExpressionMatch match;
|
||||||
|
|
||||||
auto hasMatch = [&match, line](const QRegularExpression ®ex) {
|
auto hasMatch = [&match, line](const QRegularExpression ®ex) {
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ protected:
|
|||||||
TestResultPtr createDefaultResult() const override;
|
TestResultPtr createDefaultResult() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processXMLOutput(const QByteArray &outputLineWithNewline);
|
void processXMLOutput(const QByteArray &outputLine);
|
||||||
void processPlainTextOutput(const QByteArray &outputLineWithNewline);
|
void processPlainTextOutput(const QByteArray &outputLine);
|
||||||
void processResultOutput(const QString &result, const QString &message);
|
void processResultOutput(const QString &result, const QString &message);
|
||||||
void processLocationOutput(const QString &fileWithLine);
|
void processLocationOutput(const QString &fileWithLine);
|
||||||
void processSummaryFinishOutput();
|
void processSummaryFinishOutput();
|
||||||
|
|||||||
@@ -41,32 +41,40 @@ TestOutputReader::TestOutputReader(const QFutureInterface<TestResultPtr> &future
|
|||||||
, m_buildDir(buildDirectory)
|
, m_buildDir(buildDirectory)
|
||||||
, m_id(testApplication ? testApplication->program() : QString())
|
, m_id(testApplication ? testApplication->program() : QString())
|
||||||
{
|
{
|
||||||
|
auto chopLineBreak = [](QByteArray line) {
|
||||||
|
if (line.endsWith('\n'))
|
||||||
|
line.chop(1);
|
||||||
|
if (line.endsWith('\r'))
|
||||||
|
line.chop(1);
|
||||||
|
return line;
|
||||||
|
};
|
||||||
|
|
||||||
if (m_testApplication) {
|
if (m_testApplication) {
|
||||||
connect(m_testApplication, &QProcess::readyRead,
|
connect(m_testApplication, &QProcess::readyRead,
|
||||||
this, [this] () {
|
this, [chopLineBreak, this] () {
|
||||||
while (m_testApplication->canReadLine()) {
|
m_testApplication->setReadChannel(QProcess::StandardOutput);
|
||||||
const QByteArray output = m_testApplication->readLine();
|
while (m_testApplication->canReadLine())
|
||||||
processOutput(output);
|
processStdOutput(chopLineBreak(m_testApplication->readLine()));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
connect(m_testApplication, &QProcess::readyReadStandardError,
|
connect(m_testApplication, &QProcess::readyReadStandardError,
|
||||||
this, [this] () {
|
this, [chopLineBreak, this] () {
|
||||||
const QByteArray output = m_testApplication->readAllStandardError();
|
m_testApplication->setReadChannel(QProcess::StandardError);
|
||||||
processStdError(output);
|
while (m_testApplication->canReadLine())
|
||||||
|
processStdError(chopLineBreak(m_testApplication->readLine()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestOutputReader::processOutput(const QByteArray &output)
|
void TestOutputReader::processStdOutput(const QByteArray &outputLine)
|
||||||
{
|
{
|
||||||
processOutputLine(output);
|
processOutputLine(outputLine);
|
||||||
emit newOutputAvailable(output);
|
emit newOutputLineAvailable(outputLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestOutputReader::processStdError(const QByteArray &outputLineWithNewLine)
|
void TestOutputReader::processStdError(const QByteArray &outputLine)
|
||||||
{
|
{
|
||||||
qWarning() << "AutoTest.Run: Ignored plain output:" << outputLineWithNewLine;
|
qWarning() << "AutoTest.Run: Ignored plain output:" << outputLine;
|
||||||
emit newOutputAvailable(outputLineWithNewLine);
|
emit newOutputLineAvailable(outputLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestOutputReader::reportCrash()
|
void TestOutputReader::reportCrash()
|
||||||
@@ -85,16 +93,6 @@ void TestOutputReader::createAndReportResult(const QString &message, ResultType
|
|||||||
reportResult(result);
|
reportResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray TestOutputReader::chopLineBreak(const QByteArray &original)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(original.endsWith('\n'), return original);
|
|
||||||
QByteArray output(original);
|
|
||||||
output.chop(1); // remove the newline from the output
|
|
||||||
if (output.endsWith('\r'))
|
|
||||||
output.chop(1);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestOutputReader::reportResult(const TestResultPtr &result)
|
void TestOutputReader::reportResult(const TestResultPtr &result)
|
||||||
{
|
{
|
||||||
m_futureInterface.reportResult(result);
|
m_futureInterface.reportResult(result);
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ public:
|
|||||||
TestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
TestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
||||||
QProcess *testApplication, const QString &buildDirectory);
|
QProcess *testApplication, const QString &buildDirectory);
|
||||||
|
|
||||||
void processOutput(const QByteArray &output);
|
void processStdOutput(const QByteArray &outputLine);
|
||||||
virtual void processStdError(const QByteArray &outputLineWithNewLine);
|
virtual void processStdError(const QByteArray &outputLine);
|
||||||
void reportCrash();
|
void reportCrash();
|
||||||
void createAndReportResult(const QString &message, ResultType type);
|
void createAndReportResult(const QString &message, ResultType type);
|
||||||
bool hadValidOutput() const { return m_hadValidOutput; }
|
bool hadValidOutput() const { return m_hadValidOutput; }
|
||||||
@@ -52,12 +52,10 @@ public:
|
|||||||
void setId(const QString &id) { m_id = id; }
|
void setId(const QString &id) { m_id = id; }
|
||||||
QString id() const { return m_id; }
|
QString id() const { return m_id; }
|
||||||
|
|
||||||
static QByteArray chopLineBreak(const QByteArray &original);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void newOutputAvailable(const QByteArray &outputWithLineBreak);
|
void newOutputLineAvailable(const QByteArray &outputLine);
|
||||||
protected:
|
protected:
|
||||||
virtual void processOutputLine(const QByteArray &outputLineWithNewLine) = 0;
|
virtual void processOutputLine(const QByteArray &outputLine) = 0;
|
||||||
virtual TestResultPtr createDefaultResult() const = 0;
|
virtual TestResultPtr createDefaultResult() const = 0;
|
||||||
|
|
||||||
void reportResult(const TestResultPtr &result);
|
void reportResult(const TestResultPtr &result);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
#include <projectexplorer/buildmanager.h>
|
#include <projectexplorer/buildmanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
@@ -238,9 +239,14 @@ void TestResultsPane::addTestResult(const TestResultPtr &result)
|
|||||||
navigateStateChanged();
|
navigateStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestResultsPane::addOutput(const QByteArray &output)
|
void TestResultsPane::addOutputLine(const QByteArray &outputLine)
|
||||||
{
|
{
|
||||||
m_textOutput->appendPlainText(QString::fromUtf8(TestOutputReader::chopLineBreak(output)));
|
if (!QTC_GUARD(!outputLine.contains('\n'))) {
|
||||||
|
for (auto line : outputLine.split('\n'))
|
||||||
|
addOutputLine(line);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_textOutput->appendPlainText(QString::fromUtf8(outputLine));
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *TestResultsPane::outputWidget(QWidget *parent)
|
QWidget *TestResultsPane::outputWidget(QWidget *parent)
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public:
|
|||||||
void goToPrev() override;
|
void goToPrev() override;
|
||||||
|
|
||||||
void addTestResult(const TestResultPtr &result);
|
void addTestResult(const TestResultPtr &result);
|
||||||
void addOutput(const QByteArray &outputWithNewLine);
|
void addOutputLine(const QByteArray &outputLine);
|
||||||
void showTestResult(const QModelIndex &index);
|
void showTestResult(const QModelIndex &index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -204,8 +204,8 @@ void TestRunner::scheduleNext()
|
|||||||
m_currentOutputReader = m_currentConfig->outputReader(*m_fakeFutureInterface, m_currentProcess);
|
m_currentOutputReader = m_currentConfig->outputReader(*m_fakeFutureInterface, m_currentProcess);
|
||||||
QTC_ASSERT(m_currentOutputReader, onProcessFinished();return);
|
QTC_ASSERT(m_currentOutputReader, onProcessFinished();return);
|
||||||
|
|
||||||
connect(m_currentOutputReader, &TestOutputReader::newOutputAvailable,
|
connect(m_currentOutputReader, &TestOutputReader::newOutputLineAvailable,
|
||||||
TestResultsPane::instance(), &TestResultsPane::addOutput);
|
TestResultsPane::instance(), &TestResultsPane::addOutputLine);
|
||||||
|
|
||||||
|
|
||||||
QStringList omitted;
|
QStringList omitted;
|
||||||
@@ -494,34 +494,23 @@ static void processOutput(TestOutputReader *outputreader, const QString &msg,
|
|||||||
{
|
{
|
||||||
QByteArray message = msg.toUtf8();
|
QByteArray message = msg.toUtf8();
|
||||||
switch (format) {
|
switch (format) {
|
||||||
|
case Utils::OutputFormat::StdErrFormatSameLine:
|
||||||
case Utils::OutputFormat::StdOutFormatSameLine:
|
case Utils::OutputFormat::StdOutFormatSameLine:
|
||||||
case Utils::OutputFormat::DebugFormat: {
|
case Utils::OutputFormat::DebugFormat: {
|
||||||
static const QByteArray gdbSpecialOut = "Qt: gdb: -nograb added to command-line options.\n"
|
static const QByteArray gdbSpecialOut = "Qt: gdb: -nograb added to command-line options.\n"
|
||||||
"\t Use the -dograb option to enforce grabbing.";
|
"\t Use the -dograb option to enforce grabbing.";
|
||||||
int start = message.startsWith(gdbSpecialOut) ? gdbSpecialOut.length() + 1 : 0;
|
if (message.startsWith(gdbSpecialOut))
|
||||||
if (start) {
|
message = message.mid(gdbSpecialOut.length() + 1);
|
||||||
int maxIndex = message.length() - 1;
|
message.chop(1); // all messages have an additional \n at the end
|
||||||
while (start < maxIndex && msg.at(start + 1) == '\n')
|
|
||||||
++start;
|
|
||||||
if (start >= message.length()) // we cut out the whole message
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = message.indexOf('\n', start);
|
for (auto line : message.split('\n')) {
|
||||||
while (index != -1) {
|
if (format == Utils::OutputFormat::StdOutFormatSameLine)
|
||||||
const QByteArray line = message.mid(start, index - start + 1);
|
outputreader->processStdOutput(line);
|
||||||
outputreader->processOutput(line);
|
else
|
||||||
start = index + 1;
|
outputreader->processStdError(line);
|
||||||
index = message.indexOf('\n', start);
|
|
||||||
}
|
}
|
||||||
if (!QTC_GUARD(start == message.length())) // paranoia
|
|
||||||
outputreader->processOutput(message.mid(start).append('\n'));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Utils::OutputFormat::StdErrFormatSameLine:
|
|
||||||
outputreader->processStdError(message);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break; // channels we're not caring about
|
break; // channels we're not caring about
|
||||||
}
|
}
|
||||||
@@ -612,8 +601,8 @@ void TestRunner::debugTests()
|
|||||||
if (useOutputProcessor) {
|
if (useOutputProcessor) {
|
||||||
TestOutputReader *outputreader = config->outputReader(*futureInterface, nullptr);
|
TestOutputReader *outputreader = config->outputReader(*futureInterface, nullptr);
|
||||||
outputreader->setId(inferior.executable.toString());
|
outputreader->setId(inferior.executable.toString());
|
||||||
connect(outputreader, &TestOutputReader::newOutputAvailable,
|
connect(outputreader, &TestOutputReader::newOutputLineAvailable,
|
||||||
TestResultsPane::instance(), &TestResultsPane::addOutput);
|
TestResultsPane::instance(), &TestResultsPane::addOutputLine);
|
||||||
connect(runControl, &RunControl::appendMessage,
|
connect(runControl, &RunControl::appendMessage,
|
||||||
this, [outputreader](const QString &msg, Utils::OutputFormat format) {
|
this, [outputreader](const QString &msg, Utils::OutputFormat format) {
|
||||||
processOutput(outputreader, msg, format);
|
processOutput(outputreader, msg, format);
|
||||||
|
|||||||
Reference in New Issue
Block a user