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();
|
||||
}
|
||||
|
||||
void BoostTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLine)
|
||||
void BoostTestOutputReader::processOutputLine(const QByteArray &outputLine)
|
||||
{
|
||||
static QRegularExpression newTestStart("^Running (\\d+) test cases?\\.\\.\\.$");
|
||||
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");
|
||||
QString noErrors("*** No errors detected");
|
||||
|
||||
const QString line = QString::fromUtf8(chopLineBreak(outputLineWithNewLine));
|
||||
const QString line = QString::fromUtf8(outputLine);
|
||||
if (line.trimmed().isEmpty())
|
||||
return;
|
||||
|
||||
@@ -376,28 +376,11 @@ void BoostTestOutputReader::processOutputLine(const QByteArray &outputLineWithNe
|
||||
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
|
||||
int start = 0;
|
||||
int index = -1;
|
||||
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);
|
||||
}
|
||||
}
|
||||
processOutputLine(outputLine);
|
||||
emit newOutputLineAvailable(outputLine);
|
||||
}
|
||||
|
||||
TestResultPtr BoostTestOutputReader::createDefaultResult() const
|
||||
|
||||
@@ -42,8 +42,8 @@ public:
|
||||
QProcess *testApplication, const QString &buildDirectory,
|
||||
const QString &projectFile, LogLevel log, ReportLevel report);
|
||||
protected:
|
||||
void processOutputLine(const QByteArray &outputLineWithNewLine) override;
|
||||
void processStdError(const QByteArray &output) override;
|
||||
void processOutputLine(const QByteArray &outputLine) override;
|
||||
void processStdError(const QByteArray &outputLine) override;
|
||||
TestResultPtr createDefaultResult() const override;
|
||||
|
||||
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 testEnds("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$");
|
||||
@@ -74,7 +74,7 @@ void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLin
|
||||
static const QRegularExpression iterations("^Repeating all tests "
|
||||
"\\(iteration (\\d+)\\) \\. \\. \\.$");
|
||||
|
||||
const QString line = QString::fromLatin1(chopLineBreak(outputLineWithNewLine));
|
||||
const QString line = QString::fromLatin1(outputLine);
|
||||
if (line.trimmed().isEmpty())
|
||||
return;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
QProcess *testApplication, const QString &buildDirectory,
|
||||
const QString &projectFile);
|
||||
protected:
|
||||
void processOutputLine(const QByteArray &outputLineWithNewLine) override;
|
||||
void processOutputLine(const QByteArray &outputLine) override;
|
||||
TestResultPtr createDefaultResult() const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -354,7 +354,7 @@ static QStringList extractFunctionInformation(const QString &testClassName,
|
||||
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 config("^Config: Using QtTest library (.*), "
|
||||
@@ -375,7 +375,7 @@ void QtTestOutputReader::processPlainTextOutput(const QByteArray &outputLineWith
|
||||
if (m_futureInterface.isCanceled())
|
||||
return;
|
||||
|
||||
const QString line = QString::fromUtf8(chopLineBreak(outputLineWithNewLine));
|
||||
const QString line = QString::fromUtf8(outputLine);
|
||||
QRegularExpressionMatch match;
|
||||
|
||||
auto hasMatch = [&match, line](const QRegularExpression ®ex) {
|
||||
|
||||
@@ -55,8 +55,8 @@ protected:
|
||||
TestResultPtr createDefaultResult() const override;
|
||||
|
||||
private:
|
||||
void processXMLOutput(const QByteArray &outputLineWithNewline);
|
||||
void processPlainTextOutput(const QByteArray &outputLineWithNewline);
|
||||
void processXMLOutput(const QByteArray &outputLine);
|
||||
void processPlainTextOutput(const QByteArray &outputLine);
|
||||
void processResultOutput(const QString &result, const QString &message);
|
||||
void processLocationOutput(const QString &fileWithLine);
|
||||
void processSummaryFinishOutput();
|
||||
|
||||
@@ -41,32 +41,40 @@ TestOutputReader::TestOutputReader(const QFutureInterface<TestResultPtr> &future
|
||||
, m_buildDir(buildDirectory)
|
||||
, 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) {
|
||||
connect(m_testApplication, &QProcess::readyRead,
|
||||
this, [this] () {
|
||||
while (m_testApplication->canReadLine()) {
|
||||
const QByteArray output = m_testApplication->readLine();
|
||||
processOutput(output);
|
||||
}
|
||||
this, [chopLineBreak, this] () {
|
||||
m_testApplication->setReadChannel(QProcess::StandardOutput);
|
||||
while (m_testApplication->canReadLine())
|
||||
processStdOutput(chopLineBreak(m_testApplication->readLine()));
|
||||
});
|
||||
connect(m_testApplication, &QProcess::readyReadStandardError,
|
||||
this, [this] () {
|
||||
const QByteArray output = m_testApplication->readAllStandardError();
|
||||
processStdError(output);
|
||||
this, [chopLineBreak, this] () {
|
||||
m_testApplication->setReadChannel(QProcess::StandardError);
|
||||
while (m_testApplication->canReadLine())
|
||||
processStdError(chopLineBreak(m_testApplication->readLine()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void TestOutputReader::processOutput(const QByteArray &output)
|
||||
void TestOutputReader::processStdOutput(const QByteArray &outputLine)
|
||||
{
|
||||
processOutputLine(output);
|
||||
emit newOutputAvailable(output);
|
||||
processOutputLine(outputLine);
|
||||
emit newOutputLineAvailable(outputLine);
|
||||
}
|
||||
|
||||
void TestOutputReader::processStdError(const QByteArray &outputLineWithNewLine)
|
||||
void TestOutputReader::processStdError(const QByteArray &outputLine)
|
||||
{
|
||||
qWarning() << "AutoTest.Run: Ignored plain output:" << outputLineWithNewLine;
|
||||
emit newOutputAvailable(outputLineWithNewLine);
|
||||
qWarning() << "AutoTest.Run: Ignored plain output:" << outputLine;
|
||||
emit newOutputLineAvailable(outputLine);
|
||||
}
|
||||
|
||||
void TestOutputReader::reportCrash()
|
||||
@@ -85,16 +93,6 @@ void TestOutputReader::createAndReportResult(const QString &message, ResultType
|
||||
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)
|
||||
{
|
||||
m_futureInterface.reportResult(result);
|
||||
|
||||
@@ -41,8 +41,8 @@ public:
|
||||
TestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
||||
QProcess *testApplication, const QString &buildDirectory);
|
||||
|
||||
void processOutput(const QByteArray &output);
|
||||
virtual void processStdError(const QByteArray &outputLineWithNewLine);
|
||||
void processStdOutput(const QByteArray &outputLine);
|
||||
virtual void processStdError(const QByteArray &outputLine);
|
||||
void reportCrash();
|
||||
void createAndReportResult(const QString &message, ResultType type);
|
||||
bool hadValidOutput() const { return m_hadValidOutput; }
|
||||
@@ -52,12 +52,10 @@ public:
|
||||
void setId(const QString &id) { m_id = id; }
|
||||
QString id() const { return m_id; }
|
||||
|
||||
static QByteArray chopLineBreak(const QByteArray &original);
|
||||
|
||||
signals:
|
||||
void newOutputAvailable(const QByteArray &outputWithLineBreak);
|
||||
void newOutputLineAvailable(const QByteArray &outputLine);
|
||||
protected:
|
||||
virtual void processOutputLine(const QByteArray &outputLineWithNewLine) = 0;
|
||||
virtual void processOutputLine(const QByteArray &outputLine) = 0;
|
||||
virtual TestResultPtr createDefaultResult() const = 0;
|
||||
|
||||
void reportResult(const TestResultPtr &result);
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <projectexplorer/buildmanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
@@ -238,9 +239,14 @@ void TestResultsPane::addTestResult(const TestResultPtr &result)
|
||||
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)
|
||||
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
void goToPrev() override;
|
||||
|
||||
void addTestResult(const TestResultPtr &result);
|
||||
void addOutput(const QByteArray &outputWithNewLine);
|
||||
void addOutputLine(const QByteArray &outputLine);
|
||||
void showTestResult(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
|
||||
@@ -204,8 +204,8 @@ void TestRunner::scheduleNext()
|
||||
m_currentOutputReader = m_currentConfig->outputReader(*m_fakeFutureInterface, m_currentProcess);
|
||||
QTC_ASSERT(m_currentOutputReader, onProcessFinished();return);
|
||||
|
||||
connect(m_currentOutputReader, &TestOutputReader::newOutputAvailable,
|
||||
TestResultsPane::instance(), &TestResultsPane::addOutput);
|
||||
connect(m_currentOutputReader, &TestOutputReader::newOutputLineAvailable,
|
||||
TestResultsPane::instance(), &TestResultsPane::addOutputLine);
|
||||
|
||||
|
||||
QStringList omitted;
|
||||
@@ -494,34 +494,23 @@ static void processOutput(TestOutputReader *outputreader, const QString &msg,
|
||||
{
|
||||
QByteArray message = msg.toUtf8();
|
||||
switch (format) {
|
||||
case Utils::OutputFormat::StdErrFormatSameLine:
|
||||
case Utils::OutputFormat::StdOutFormatSameLine:
|
||||
case Utils::OutputFormat::DebugFormat: {
|
||||
static const QByteArray gdbSpecialOut = "Qt: gdb: -nograb added to command-line options.\n"
|
||||
"\t Use the -dograb option to enforce grabbing.";
|
||||
int start = message.startsWith(gdbSpecialOut) ? gdbSpecialOut.length() + 1 : 0;
|
||||
if (start) {
|
||||
int maxIndex = message.length() - 1;
|
||||
while (start < maxIndex && msg.at(start + 1) == '\n')
|
||||
++start;
|
||||
if (start >= message.length()) // we cut out the whole message
|
||||
break;
|
||||
}
|
||||
if (message.startsWith(gdbSpecialOut))
|
||||
message = message.mid(gdbSpecialOut.length() + 1);
|
||||
message.chop(1); // all messages have an additional \n at the end
|
||||
|
||||
int index = message.indexOf('\n', start);
|
||||
while (index != -1) {
|
||||
const QByteArray line = message.mid(start, index - start + 1);
|
||||
outputreader->processOutput(line);
|
||||
start = index + 1;
|
||||
index = message.indexOf('\n', start);
|
||||
for (auto line : message.split('\n')) {
|
||||
if (format == Utils::OutputFormat::StdOutFormatSameLine)
|
||||
outputreader->processStdOutput(line);
|
||||
else
|
||||
outputreader->processStdError(line);
|
||||
}
|
||||
if (!QTC_GUARD(start == message.length())) // paranoia
|
||||
outputreader->processOutput(message.mid(start).append('\n'));
|
||||
|
||||
break;
|
||||
}
|
||||
case Utils::OutputFormat::StdErrFormatSameLine:
|
||||
outputreader->processStdError(message);
|
||||
break;
|
||||
default:
|
||||
break; // channels we're not caring about
|
||||
}
|
||||
@@ -612,8 +601,8 @@ void TestRunner::debugTests()
|
||||
if (useOutputProcessor) {
|
||||
TestOutputReader *outputreader = config->outputReader(*futureInterface, nullptr);
|
||||
outputreader->setId(inferior.executable.toString());
|
||||
connect(outputreader, &TestOutputReader::newOutputAvailable,
|
||||
TestResultsPane::instance(), &TestResultsPane::addOutput);
|
||||
connect(outputreader, &TestOutputReader::newOutputLineAvailable,
|
||||
TestResultsPane::instance(), &TestResultsPane::addOutputLine);
|
||||
connect(runControl, &RunControl::appendMessage,
|
||||
this, [outputreader](const QString &msg, Utils::OutputFormat format) {
|
||||
processOutput(outputreader, msg, format);
|
||||
|
||||
Reference in New Issue
Block a user