AutoTest: Refactor output handling

Handle getting output from application's process inside base class
and just process output inside the sub classes.
Additionally this is a preparation for being able to process output
for debugging tests as well.

Change-Id: I8a2289dc7faab25afe08530b5021a0318f3ba6a6
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2016-07-21 10:08:11 +02:00
parent ce8bff4b31
commit bb643a3cdc
6 changed files with 240 additions and 245 deletions

View File

@@ -43,11 +43,8 @@ GTestOutputReader::GTestOutputReader(const QFutureInterface<TestResultPtr> &futu
{
}
void GTestOutputReader::processOutput()
void GTestOutputReader::processOutput(const QByteArray &outputLine)
{
if (!m_testApplication || m_testApplication->state() != QProcess::Running)
return;
static QRegExp newTestStarts(QStringLiteral("^\\[-{10}\\] \\d+ tests? from (.*)$"));
static QRegExp testEnds(QStringLiteral("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$"));
static QRegExp newTestSetStarts(QStringLiteral("^\\[ RUN \\] (.*)$"));
@@ -58,17 +55,14 @@ void GTestOutputReader::processOutput()
static QRegExp errorLocation(QStringLiteral("^(.*)\\((\\d+)\\): error:.*$"));
static QRegExp iterations(QStringLiteral("^Repeating all tests \\(iteration (\\d+)\\) . . .$"));
while (m_testApplication->canReadLine()) {
if (m_futureInterface.isCanceled())
return;
QByteArray read = m_testApplication->readLine();
QByteArray read = outputLine;
if (!m_unprocessed.isEmpty()) {
read = m_unprocessed + read;
m_unprocessed.clear();
}
if (!read.endsWith('\n')) {
m_unprocessed = read;
continue;
return;
}
read.chop(1); // remove the newline from the output
if (read.endsWith('\r'))
@@ -76,7 +70,7 @@ void GTestOutputReader::processOutput()
const QString line = QString::fromLatin1(read);
if (line.trimmed().isEmpty())
continue;
return;
if (!line.startsWith(QLatin1Char('['))) {
m_description.append(line).append(QLatin1Char('\n'));
@@ -98,7 +92,7 @@ void GTestOutputReader::processOutput()
m_futureInterface.reportResult(testResult);
m_description.clear();
}
continue;
return; //continue;
}
if (testEnds.exactMatch(line)) {
@@ -173,7 +167,6 @@ void GTestOutputReader::processOutput()
m_futureInterface.reportResult(TestResultPtr(testResult));
m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1);
}
}
}
} // namespace Internal

View File

@@ -37,7 +37,7 @@ public:
QProcess *testApplication, const QString &buildDirectory);
protected:
void processOutput() override;
void processOutput(const QByteArray &outputLine) override;
private:
QString m_currentTestName;

View File

@@ -133,10 +133,8 @@ QtTestOutputReader::QtTestOutputReader(const QFutureInterface<TestResultPtr> &fu
{
}
void QtTestOutputReader::processOutput()
void QtTestOutputReader::processOutput(const QByteArray &outputLine)
{
if (!m_testApplication || m_testApplication->state() != QProcess::Running)
return;
static QStringList validEndTags = { QStringLiteral("Incident"),
QStringLiteral("Message"),
QStringLiteral("BenchmarkResult"),
@@ -144,8 +142,7 @@ void QtTestOutputReader::processOutput()
QStringLiteral("QtBuild"),
QStringLiteral("QTestVersion") };
while (m_testApplication->canReadLine()) {
m_xmlReader.addData(m_testApplication->readLine());
m_xmlReader.addData(outputLine);
while (!m_xmlReader.atEnd()) {
if (m_futureInterface.isCanceled())
return;
@@ -281,7 +278,6 @@ void QtTestOutputReader::processOutput()
break;
}
}
}
}
} // namespace Internal

View File

@@ -39,7 +39,7 @@ public:
QProcess *testApplication, const QString &buildDirectory);
protected:
void processOutput() override;
void processOutput(const QByteArray &outputLine) override;
private:
enum CDATAMode

View File

@@ -38,14 +38,20 @@ TestOutputReader::TestOutputReader(const QFutureInterface<TestResultPtr> &future
, m_testApplication(testApplication)
, m_buildDir(buildDirectory)
{
connect(m_testApplication, &QProcess::readyRead, this, &TestOutputReader::processOutput);
connect(m_testApplication, &QProcess::readyRead,
this, [this] () {
while (m_testApplication->canReadLine())
processOutput(m_testApplication->readLine());
});
connect(m_testApplication, &QProcess::readyReadStandardError,
this, &TestOutputReader::processStdError);
this, [this] () {
processStdError(m_testApplication->readAllStandardError());
});
}
void TestOutputReader::processStdError()
void TestOutputReader::processStdError(const QByteArray &output)
{
qWarning() << "AutoTest.Run: Ignored plain output:" << m_testApplication->readAllStandardError();
qWarning() << "AutoTest.Run: Ignored plain output:" << output;
}
} // namespace Internal

View File

@@ -43,8 +43,8 @@ public:
QProcess *testApplication, const QString &buildDirectory);
protected:
virtual void processOutput() = 0;
virtual void processStdError();
virtual void processOutput(const QByteArray &outputLine) = 0;
virtual void processStdError(const QByteArray &output);
QFutureInterface<TestResultPtr> m_futureInterface;
QProcess *m_testApplication; // not owned
QString m_buildDir;