AutoTest: Improve handling unexpected output

If tests prints out non-XML data to stdout the XML parser gets
nuts and refuses to handle the result.
Ignore unexpected output as it will be printed out on the
command line view anyhow.

Task-number: QTCREATORBUG-22354
Change-Id: I96f453fadd834d21572080857c86d25b2d6f6aa9
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2019-05-23 12:52:18 +02:00
parent d987c3ba67
commit 389fd37a68
2 changed files with 14 additions and 1 deletions

View File

@@ -34,6 +34,8 @@
#include <QFileInfo> #include <QFileInfo>
#include <QRegularExpression> #include <QRegularExpression>
#include <cctype>
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -188,6 +190,15 @@ void QtTestOutputReader::processXMLOutput(const QByteArray &outputLine)
if (m_className.isEmpty() && outputLine.trimmed().isEmpty()) if (m_className.isEmpty() && outputLine.trimmed().isEmpty())
return; return;
if (m_expectTag) {
for (auto ch : outputLine) {
if (std::isspace(ch))
continue;
if (ch != '<')
return;
break;
}
}
m_xmlReader.addData(QString::fromUtf8(outputLine)); m_xmlReader.addData(QString::fromUtf8(outputLine));
while (!m_xmlReader.atEnd()) { while (!m_xmlReader.atEnd()) {
if (m_futureInterface.isCanceled()) if (m_futureInterface.isCanceled())
@@ -255,6 +266,7 @@ void QtTestOutputReader::processXMLOutput(const QByteArray &outputLine)
break; break;
} }
case QXmlStreamReader::Characters: { case QXmlStreamReader::Characters: {
m_expectTag = false;
QStringRef text = m_xmlReader.text().trimmed(); QStringRef text = m_xmlReader.text().trimmed();
if (text.isEmpty()) if (text.isEmpty())
break; break;
@@ -285,6 +297,7 @@ void QtTestOutputReader::processXMLOutput(const QByteArray &outputLine)
break; break;
} }
case QXmlStreamReader::EndElement: { case QXmlStreamReader::EndElement: {
m_expectTag = true;
m_cdataMode = None; m_cdataMode = None;
const QStringRef currentTag = m_xmlReader.name(); const QStringRef currentTag = m_xmlReader.name();
if (currentTag == QStringLiteral("TestFunction")) { if (currentTag == QStringLiteral("TestFunction")) {

View File

@@ -91,7 +91,7 @@ private:
QXmlStreamReader m_xmlReader; QXmlStreamReader m_xmlReader;
OutputMode m_mode = XML; OutputMode m_mode = XML;
TestType m_testType = TestType::QtTest; TestType m_testType = TestType::QtTest;
bool m_expectTag = true;
}; };
} // namespace Internal } // namespace Internal