AutoTest: Fix outputparser

This patch amends 3056105c66. This patch fixes
handling of output while debugging and appending
to the "real" output if the user interacts with
the output while the test is running.

Change-Id: I1db54382f1df3e2b9a5a860002aac8fb208ee5b9
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2018-11-06 16:00:48 +01:00
parent 790a86d508
commit 1cfaa828a8
9 changed files with 33 additions and 16 deletions

View File

@@ -62,7 +62,7 @@ GTestOutputReader::GTestOutputReader(const QFutureInterface<TestResultPtr> &futu
}
}
void GTestOutputReader::processOutput(const QByteArray &outputLineWithNewLine)
void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLine)
{
static QRegExp newTestStarts("^\\[-{10}\\] \\d+ tests? from (.*)$");
static QRegExp testEnds("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$");

View File

@@ -44,7 +44,7 @@ public:
QProcess *testApplication, const QString &buildDirectory,
const QString &projectFile);
protected:
void processOutput(const QByteArray &outputLineWithNewLine) override;
void processOutputLine(const QByteArray &outputLineWithNewLine) override;
TestResultPtr createDefaultResult() const override;
private:

View File

@@ -139,7 +139,7 @@ QtTestOutputReader::QtTestOutputReader(const QFutureInterface<TestResultPtr> &fu
{
}
void QtTestOutputReader::processOutput(const QByteArray &outputLine)
void QtTestOutputReader::processOutputLine(const QByteArray &outputLine)
{
static const QByteArray qmlDebug = "QML Debugger: Waiting for connection on port";
switch (m_mode) {

View File

@@ -51,7 +51,7 @@ public:
QProcess *testApplication, const QString &buildDirectory,
const QString &projectFile, OutputMode mode, TestType type);
protected:
void processOutput(const QByteArray &outputLine) override;
void processOutputLine(const QByteArray &outputLine) override;
TestResultPtr createDefaultResult() const override;
private:

View File

@@ -47,7 +47,6 @@ TestOutputReader::TestOutputReader(const QFutureInterface<TestResultPtr> &future
this, [this] () {
while (m_testApplication->canReadLine()) {
const QByteArray output = m_testApplication->readLine();
emit newOutputAvailable(output);
processOutput(output);
}
});
@@ -60,6 +59,12 @@ TestOutputReader::TestOutputReader(const QFutureInterface<TestResultPtr> &future
}
}
void TestOutputReader::processOutput(const QByteArray &output)
{
processOutputLine(output);
emit newOutputAvailable(output);
}
void TestOutputReader::processStdError(const QByteArray &outputLineWithNewLine)
{
qWarning() << "AutoTest.Run: Ignored plain output:" << outputLineWithNewLine;

View File

@@ -42,7 +42,7 @@ public:
TestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
QProcess *testApplication, const QString &buildDirectory);
virtual void processOutput(const QByteArray &outputLineWithNewLine) = 0;
void processOutput(const QByteArray &output);
virtual void processStdError(const QByteArray &outputLineWithNewLine);
void reportCrash();
void createAndReportResult(const QString &message, Result::Type type);
@@ -55,6 +55,7 @@ public:
signals:
void newOutputAvailable(const QByteArray &outputWithLineBreak);
protected:
virtual void processOutputLine(const QByteArray &outputLineWithNewLine) = 0;
virtual TestResultPtr createDefaultResult() const = 0;
void reportResult(const TestResultPtr &result);

View File

@@ -33,6 +33,7 @@
#include "testtreemodel.h"
#include "testcodeparser.h"
#include "testeditormark.h"
#include "testoutputreader.h"
#include <aggregation/aggregate.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -236,7 +237,7 @@ void TestResultsPane::addTestResult(const TestResultPtr &result)
void TestResultsPane::addOutput(const QByteArray &output)
{
m_textOutput->insertPlainText(QString::fromLatin1(output));
m_textOutput->appendPlainText(QString::fromLatin1(TestOutputReader::chopLineBreak(output)));
}
QWidget *TestResultsPane::outputWidget(QWidget *parent)

View File

@@ -92,7 +92,7 @@ public:
void goToPrev() override;
void addTestResult(const TestResultPtr &result);
void addOutput(const QByteArray &output);
void addOutput(const QByteArray &outputWithNewLine);
void showTestResult(const QModelIndex &index);
private:

View File

@@ -471,25 +471,35 @@ void TestRunner::runTests()
static void processOutput(TestOutputReader *outputreader, const QString &msg,
Utils::OutputFormat format)
{
QByteArray message = msg.toUtf8();
switch (format) {
case Utils::OutputFormat::StdOutFormatSameLine:
case Utils::OutputFormat::DebugFormat: {
static const QString gdbSpecialOut = "Qt: gdb: -nograb added to command-line options.\n"
"\t Use the -dograb option to enforce grabbing.";
int start = msg.startsWith(gdbSpecialOut) ? gdbSpecialOut.length() + 1 : 0;
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 = msg.length() - 1;
int maxIndex = message.length() - 1;
while (start < maxIndex && msg.at(start + 1) == '\n')
++start;
if (start >= msg.length()) // we cut out the whole message
if (start >= message.length()) // we cut out the whole message
break;
}
for (const QString &line : msg.mid(start).split('\n'))
outputreader->processOutput(line.toUtf8());
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);
}
if (!QTC_GUARD(start == message.length())) // paranoia
outputreader->processOutput(message.mid(start).append('\n'));
break;
}
case Utils::OutputFormat::StdErrFormatSameLine:
outputreader->processStdError(msg.toUtf8());
outputreader->processStdError(message);
break;
default:
break; // channels we're not caring about