diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-02 14:29:28 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-06 17:00:22 +0200 |
commit | a2026e4116e325767b899505cf248a75b9647195 (patch) | |
tree | 3017b370a33d93bebfd3b91ad82e7c7d5aa1c711 /src/testlib | |
parent | 0ce70a29b36a43f08ff3c8cdecde7ea75af0840f (diff) |
testlib: Write failure details as <failure> content in JUnit reporter
Pick-to: 6.2
Change-Id: Ica48769e7dfcabdc4bc8f0ed058bc22e29a0b632
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qjunittestlogger.cpp | 15 | ||||
-rw-r--r-- | src/testlib/qtestjunitstreamer.cpp | 17 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/testlib/qjunittestlogger.cpp b/src/testlib/qjunittestlogger.cpp index a120171c3a..10fe8fd81a 100644 --- a/src/testlib/qjunittestlogger.cpp +++ b/src/testlib/qjunittestlogger.cpp @@ -258,7 +258,20 @@ void QJUnitTestLogger::addIncident(IncidentTypes type, const char *description, if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass) { QTestElement *failureElement = new QTestElement(QTest::LET_Failure); failureElement->addAttribute(QTest::AI_Type, typeBuf); - failureElement->addAttribute(QTest::AI_Message, description); + + // Assume the first line is the message, and the remainder are details + QString descriptionString = QString::fromUtf8(description); + QString message = descriptionString.section(QLatin1Char('\n'), 0, 0); + QString details = descriptionString.section(QLatin1Char('\n'), 1); + + failureElement->addAttribute(QTest::AI_Message, message.toUtf8().constData()); + + if (!details.isEmpty()) { + auto messageElement = new QTestElement(QTest::LET_Message); + messageElement->addAttribute(QTest::AI_Message, details.toUtf8().constData()); + failureElement->addLogElement(messageElement); + } + currentLogElement->addLogElement(failureElement); } diff --git a/src/testlib/qtestjunitstreamer.cpp b/src/testlib/qtestjunitstreamer.cpp index 96757f0768..8176205cbb 100644 --- a/src/testlib/qtestjunitstreamer.cpp +++ b/src/testlib/qtestjunitstreamer.cpp @@ -83,11 +83,13 @@ void QTestJUnitStreamer::formatStart(const QTestElement *element, QTestCharBuffe indentForElement(element, indent, sizeof(indent)); // Messages/errors are written as CDATA within system-out, system-err, - // respectively, comments elsewhere + // error, and failure respectively, comments elsewhere if (element->elementType() == QTest::LET_Message) { switch (element->parentElement()->elementType()) { case QTest::LET_SystemOutput: case QTest::LET_SystemError: + case QTest::LET_Failure: + case QTest::LET_Error: QTest::qt_asprintf(formatted, "%s<![CDATA[", indent); break; default: @@ -123,11 +125,12 @@ void QTestJUnitStreamer::formatAttributes(const QTestElement* element, const QTe QTest::AttributeIndex attrindex = attribute->index(); - // For messages/errors within system-out, system-err, respectively, - // we only want to output `message' + // For messages we only want to output the `message' attribute value if (element && element->elementType() == QTest::LET_Message && (element->parentElement()->elementType() == QTest::LET_SystemOutput - || element->parentElement()->elementType() == QTest::LET_SystemError)) { + || element->parentElement()->elementType() == QTest::LET_SystemError + || element->parentElement()->elementType() == QTest::LET_Failure + || element->parentElement()->elementType() == QTest::LET_Error)) { if (attrindex != QTest::AI_Message) return; @@ -146,12 +149,14 @@ void QTestJUnitStreamer::formatAfterAttributes(const QTestElement *element, QTes if (!element || !formatted ) return; - // Messages/errors are written as CDATA within system-out, system-err, - // respectively, comments elsewhere + // Messages are written as CDATA within system-out, system-err, + // error, and failure respectively, comments elsewhere if (element->elementType() == QTest::LET_Message) { switch (element->parentElement()->elementType()) { case QTest::LET_SystemOutput: case QTest::LET_SystemError: + case QTest::LET_Failure: + case QTest::LET_Error: QTest::qt_asprintf(formatted, "]]>\n"); break; default: |