summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-07-28 15:40:22 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-08-05 03:58:49 +0200
commit177d259782f228257a376e3e87b30da6ad96f3fb (patch)
treebddc5820f210473d0a927e275c6b0ed46d3ee6db
parentf1ab1132ea6f8be5cf41e9bd77d5f582d5e25ee0 (diff)
testlib: Simplify JUnit test logger
- Use the right name for the attribute (AI_Message), rather than fixing it up in QTestJUnitStreamer. - Don't pretend that we're adding line and file information, only to discard it in QTestJUnitStreamer. - Don't pretend to add benchmark information, only to discard it in QTestJUnitStreamer. Pick-to: 6.2 Change-Id: Ib6eadc12300157216fe9c6e8bcfebd7eb8a3ea68 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/testlib/qjunittestlogger.cpp51
-rw-r--r--src/testlib/qjunittestlogger_p.h3
-rw-r--r--src/testlib/qtestelementattribute.cpp4
-rw-r--r--src/testlib/qtestelementattribute_p.h2
-rw-r--r--src/testlib/qtestjunitstreamer.cpp40
-rw-r--r--tests/auto/testlib/selftests/expected_benchlibcounting.junitxml3
-rw-r--r--tests/auto/testlib/selftests/expected_benchlibeventcounter.junitxml3
-rw-r--r--tests/auto/testlib/selftests/expected_benchliboptions.junitxml9
-rw-r--r--tests/auto/testlib/selftests/expected_benchlibtickcounter.junitxml3
-rw-r--r--tests/auto/testlib/selftests/expected_benchlibwalltime.junitxml9
10 files changed, 35 insertions, 92 deletions
diff --git a/src/testlib/qjunittestlogger.cpp b/src/testlib/qjunittestlogger.cpp
index 147777f77c..6374eb0f9d 100644
--- a/src/testlib/qjunittestlogger.cpp
+++ b/src/testlib/qjunittestlogger.cpp
@@ -167,7 +167,6 @@ void QJUnitTestLogger::addIncident(IncidentTypes type, const char *description,
const char *file, int line)
{
const char *typeBuf = nullptr;
- char buf[100];
switch (type) {
case QAbstractTestLogger::XPass:
@@ -206,13 +205,7 @@ 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_Result, typeBuf);
- if (file)
- failureElement->addAttribute(QTest::AI_File, file);
- else
- failureElement->addAttribute(QTest::AI_File, "");
- qsnprintf(buf, sizeof(buf), "%i", line);
- failureElement->addAttribute(QTest::AI_Line, buf);
- failureElement->addAttribute(QTest::AI_Description, description);
+ failureElement->addAttribute(QTest::AI_Message, description);
addTag(failureElement);
currentLogElement->addLogElement(failureElement);
}
@@ -251,14 +244,6 @@ void QJUnitTestLogger::addIncident(IncidentTypes type, const char *description,
currentLogElement->addAttribute(QTest::AI_Result, typeBuf);
}
- if (file)
- currentLogElement->addAttribute(QTest::AI_File, file);
- else
- currentLogElement->addAttribute(QTest::AI_File, "");
-
- qsnprintf(buf, sizeof(buf), "%i", line);
- currentLogElement->addAttribute(QTest::AI_Line, buf);
-
/*
Since XFAIL does not add a failure to the testlog in junitxml, add a message, so we still
have some information about the expected failure.
@@ -268,24 +253,6 @@ void QJUnitTestLogger::addIncident(IncidentTypes type, const char *description,
}
}
-void QJUnitTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
-{
- QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark);
-
- benchmarkElement->addAttribute(
- QTest::AI_Metric,
- QTest::benchmarkMetricName(result.metric));
- benchmarkElement->addAttribute(QTest::AI_Tag, result.context.tag.toUtf8().data());
-
- const qreal valuePerIteration = qreal(result.value) / qreal(result.iterations);
- benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(valuePerIteration).constData());
-
- char buf[100];
- qsnprintf(buf, sizeof(buf), "%i", result.iterations);
- benchmarkElement->addAttribute(QTest::AI_Iterations, buf);
- currentLogElement->addLogElement(benchmarkElement);
-}
-
void QJUnitTestLogger::addTag(QTestElement* element)
{
const char *tag = QTestResult::currentDataTag();
@@ -309,6 +276,9 @@ void QJUnitTestLogger::addTag(QTestElement* element)
void QJUnitTestLogger::addMessage(MessageTypes type, const QString &message, const char *file, int line)
{
+ Q_UNUSED(file);
+ Q_UNUSED(line);
+
auto messageElement = new QTestElement(QTest::LET_Message);
auto systemLogElement = systemOutputElement;
const char *typeBuf = nullptr;
@@ -347,25 +317,16 @@ void QJUnitTestLogger::addMessage(MessageTypes type, const QString &message, con
}
messageElement->addAttribute(QTest::AI_Type, typeBuf);
- messageElement->addAttribute(QTest::AI_Description, message.toUtf8().constData());
+ messageElement->addAttribute(QTest::AI_Message, message.toUtf8().constData());
addTag(messageElement);
- if (file)
- messageElement->addAttribute(QTest::AI_File, file);
- else
- messageElement->addAttribute(QTest::AI_File, "");
-
- char buf[100];
- qsnprintf(buf, sizeof(buf), "%i", line);
- messageElement->addAttribute(QTest::AI_Line, buf);
-
currentLogElement->addLogElement(messageElement);
++errorCounter;
// Also add the message to the system log (stdout/stderr), if one exists
if (systemLogElement) {
auto messageElement = new QTestElement(QTest::LET_Message);
- messageElement->addAttribute(QTest::AI_Description, message.toUtf8().constData());
+ messageElement->addAttribute(QTest::AI_Message, message.toUtf8().constData());
systemLogElement->addLogElement(messageElement);
}
}
diff --git a/src/testlib/qjunittestlogger_p.h b/src/testlib/qjunittestlogger_p.h
index 0be9e8aeb0..30de0b2eb0 100644
--- a/src/testlib/qjunittestlogger_p.h
+++ b/src/testlib/qjunittestlogger_p.h
@@ -72,12 +72,13 @@ class QJUnitTestLogger : public QAbstractTestLogger
void addIncident(IncidentTypes type, const char *description,
const char *file = nullptr, int line = 0) override;
- void addBenchmarkResult(const QBenchmarkResult &result) override;
void addTag(QTestElement* element);
void addMessage(MessageTypes type, const QString &message,
const char *file = nullptr, int line = 0) override;
+ void addBenchmarkResult(const QBenchmarkResult &) override {}
+
private:
QTestElement *currentTestSuite = nullptr;
QTestElement *listOfTestcases = nullptr;
diff --git a/src/testlib/qtestelementattribute.cpp b/src/testlib/qtestelementattribute.cpp
index ec47ee1900..265f126e5a 100644
--- a/src/testlib/qtestelementattribute.cpp
+++ b/src/testlib/qtestelementattribute.cpp
@@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE
\value AI_Type
- \value AI_Description
+ \value AI_Message
\value AI_PropertyValue
@@ -132,7 +132,7 @@ const char *QTestElementAttribute::name() const
"failures",
"errors",
"type",
- "description",
+ "message",
"value",
"qtestversion",
"qtversion",
diff --git a/src/testlib/qtestelementattribute_p.h b/src/testlib/qtestelementattribute_p.h
index 523dd7435e..a09e19dccb 100644
--- a/src/testlib/qtestelementattribute_p.h
+++ b/src/testlib/qtestelementattribute_p.h
@@ -67,7 +67,7 @@ namespace QTest {
AI_Failures = 3,
AI_Errors = 4,
AI_Type = 5,
- AI_Description = 6,
+ AI_Message = 6,
AI_PropertyValue = 7,
AI_QTestVersion = 8,
AI_QtVersion = 9,
diff --git a/src/testlib/qtestjunitstreamer.cpp b/src/testlib/qtestjunitstreamer.cpp
index 28879c6e06..d469e2a949 100644
--- a/src/testlib/qtestjunitstreamer.cpp
+++ b/src/testlib/qtestjunitstreamer.cpp
@@ -129,25 +129,16 @@ void QTestJUnitStreamer::formatAttributes(const QTestElement* element, const QTe
&& (element->parentElement()->elementType() == QTest::LET_SystemOutput
|| element->parentElement()->elementType() == QTest::LET_SystemError)) {
- if (attrindex != QTest::AI_Description) return;
+ if (attrindex != QTest::AI_Message) return;
QXmlTestLogger::xmlCdata(formatted, attribute->value());
return;
}
- char const* key = nullptr;
- if (attrindex == QTest::AI_Description)
- key = "message";
- else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line)
- key = attribute->name();
-
- if (key) {
- QTestCharBuffer quotedValue;
- QXmlTestLogger::xmlQuote(&quotedValue, attribute->value());
- QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData());
- } else {
- formatted->data()[0] = '\0';
- }
+ QTestCharBuffer quotedValue;
+ QXmlTestLogger::xmlQuote(&quotedValue, attribute->value());
+ QTest::qt_asprintf(formatted, " %s=\"%s\"",
+ attribute->name(), quotedValue.constData());
}
void QTestJUnitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const
@@ -197,21 +188,20 @@ void QTestJUnitStreamer::outputElements(QTestElement *element, bool) const
while (element) {
hasChildren = element->childElements();
- if (element->elementType() != QTest::LET_Benchmark) {
- formatStart(element, &buf);
- outputString(buf.data());
+ formatStart(element, &buf);
+ outputString(buf.data());
- outputElementAttributes(element, element->attributes());
+ outputElementAttributes(element, element->attributes());
- formatAfterAttributes(element, &buf);
- outputString(buf.data());
+ formatAfterAttributes(element, &buf);
+ outputString(buf.data());
- if (hasChildren)
- outputElements(element->childElements(), true);
+ if (hasChildren)
+ outputElements(element->childElements(), true);
+
+ formatEnd(element, &buf);
+ outputString(buf.data());
- formatEnd(element, &buf);
- outputString(buf.data());
- }
element = element->previousElement();
}
}
diff --git a/tests/auto/testlib/selftests/expected_benchlibcounting.junitxml b/tests/auto/testlib/selftests/expected_benchlibcounting.junitxml
index 1766bbd5b2..166a924c9b 100644
--- a/tests/auto/testlib/selftests/expected_benchlibcounting.junitxml
+++ b/tests/auto/testlib/selftests/expected_benchlibcounting.junitxml
@@ -6,8 +6,7 @@
<property name="QtBuild" value=""/>
</properties>
<testcase name="initTestCase" result="pass" time="@TEST_DURATION@"/>
- <testcase name="passingBenchmark" result="pass" time="@TEST_DURATION@">
- </testcase>
+ <testcase name="passingBenchmark" result="pass" time="@TEST_DURATION@"/>
<testcase name="skippingBenchmark" time="@TEST_DURATION@">
<!-- type="skip" message="This is a skipping benchmark" -->
</testcase>
diff --git a/tests/auto/testlib/selftests/expected_benchlibeventcounter.junitxml b/tests/auto/testlib/selftests/expected_benchlibeventcounter.junitxml
index c268450f69..68d2ec129e 100644
--- a/tests/auto/testlib/selftests/expected_benchlibeventcounter.junitxml
+++ b/tests/auto/testlib/selftests/expected_benchlibeventcounter.junitxml
@@ -6,8 +6,7 @@
<property name="QtBuild" value=""/>
</properties>
<testcase name="initTestCase" result="pass" time="@TEST_DURATION@"/>
- <testcase name="events" result="pass" time="@TEST_DURATION@">
- </testcase>
+ <testcase name="events" result="pass" time="@TEST_DURATION@"/>
<testcase name="cleanupTestCase" result="pass" time="@TEST_DURATION@"/>
<system-err/>
</testsuite>
diff --git a/tests/auto/testlib/selftests/expected_benchliboptions.junitxml b/tests/auto/testlib/selftests/expected_benchliboptions.junitxml
index c54113f031..1744c63973 100644
--- a/tests/auto/testlib/selftests/expected_benchliboptions.junitxml
+++ b/tests/auto/testlib/selftests/expected_benchliboptions.junitxml
@@ -6,8 +6,7 @@
<property name="QtBuild" value=""/>
</properties>
<testcase name="initTestCase" result="pass" time="@TEST_DURATION@"/>
- <testcase name="threeEvents" result="pass" time="@TEST_DURATION@">
- </testcase>
+ <testcase name="threeEvents" result="pass" time="@TEST_DURATION@"/>
<testcase name="cleanupTestCase" result="pass" time="@TEST_DURATION@"/>
<system-err/>
</testsuite>
@@ -19,8 +18,7 @@
<property name="QtBuild" value=""/>
</properties>
<testcase name="initTestCase" result="pass" time="@TEST_DURATION@"/>
- <testcase name="threeEvents" result="pass" time="@TEST_DURATION@">
- </testcase>
+ <testcase name="threeEvents" result="pass" time="@TEST_DURATION@"/>
<testcase name="cleanupTestCase" result="pass" time="@TEST_DURATION@"/>
<system-err/>
</testsuite>
@@ -32,8 +30,7 @@
<property name="QtBuild" value=""/>
</properties>
<testcase name="initTestCase" result="pass" time="@TEST_DURATION@"/>
- <testcase name="threeEvents" result="pass" time="@TEST_DURATION@">
- </testcase>
+ <testcase name="threeEvents" result="pass" time="@TEST_DURATION@"/>
<testcase name="cleanupTestCase" result="pass" time="@TEST_DURATION@"/>
<system-err/>
</testsuite>
diff --git a/tests/auto/testlib/selftests/expected_benchlibtickcounter.junitxml b/tests/auto/testlib/selftests/expected_benchlibtickcounter.junitxml
index 641ece34ef..59240506bd 100644
--- a/tests/auto/testlib/selftests/expected_benchlibtickcounter.junitxml
+++ b/tests/auto/testlib/selftests/expected_benchlibtickcounter.junitxml
@@ -6,8 +6,7 @@
<property name="QtBuild" value=""/>
</properties>
<testcase name="initTestCase" result="pass" time="@TEST_DURATION@"/>
- <testcase name="threeBillionTicks" result="pass" time="@TEST_DURATION@">
- </testcase>
+ <testcase name="threeBillionTicks" result="pass" time="@TEST_DURATION@"/>
<testcase name="cleanupTestCase" result="pass" time="@TEST_DURATION@"/>
<system-err/>
</testsuite>
diff --git a/tests/auto/testlib/selftests/expected_benchlibwalltime.junitxml b/tests/auto/testlib/selftests/expected_benchlibwalltime.junitxml
index b08b037614..0267b52ce6 100644
--- a/tests/auto/testlib/selftests/expected_benchlibwalltime.junitxml
+++ b/tests/auto/testlib/selftests/expected_benchlibwalltime.junitxml
@@ -6,12 +6,9 @@
<property name="QtBuild" value=""/>
</properties>
<testcase name="initTestCase" result="pass" time="@TEST_DURATION@"/>
- <testcase name="waitForOneThousand" result="pass" time="@TEST_DURATION@">
- </testcase>
- <testcase name="waitForFourThousand" result="pass" time="@TEST_DURATION@">
- </testcase>
- <testcase name="qbenchmark_once" result="pass" time="@TEST_DURATION@">
- </testcase>
+ <testcase name="waitForOneThousand" result="pass" time="@TEST_DURATION@"/>
+ <testcase name="waitForFourThousand" result="pass" time="@TEST_DURATION@"/>
+ <testcase name="qbenchmark_once" result="pass" time="@TEST_DURATION@"/>
<testcase name="cleanupTestCase" result="pass" time="@TEST_DURATION@"/>
<system-err/>
</testsuite>