Fix JUnit reporter output so that it conforms to JUnit schema

The `properties` can only go under the `testsuite` tag, not under
the `testsuites` tag.

Fixes #1598
This commit is contained in:
Martin Hořeňovský 2019-04-11 13:04:54 +02:00
parent 4e32e0a563
commit 36fb856163
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 22 additions and 22 deletions

View File

@ -76,22 +76,6 @@ namespace Catch {
void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) { void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) {
CumulativeReporterBase::testRunStarting( runInfo ); CumulativeReporterBase::testRunStarting( runInfo );
xml.startElement( "testsuites" ); xml.startElement( "testsuites" );
if ( m_config->hasTestFilters() || m_config->rngSeed() != 0 )
xml.startElement("properties");
if ( m_config->hasTestFilters() ) {
xml.scopedElement( "property" )
.writeAttribute( "name" , "filters" )
.writeAttribute( "value" , serializeFilters( m_config->getTestsOrTags() ) );
}
if( m_config->rngSeed() != 0 ) {
xml.scopedElement( "property" )
.writeAttribute( "name", "random-seed" )
.writeAttribute( "value", m_config->rngSeed() );
xml.endElement();
}
} }
void JunitReporter::testGroupStarting( GroupInfo const& groupInfo ) { void JunitReporter::testGroupStarting( GroupInfo const& groupInfo ) {
@ -130,6 +114,7 @@ namespace Catch {
void JunitReporter::writeGroup( TestGroupNode const& groupNode, double suiteTime ) { void JunitReporter::writeGroup( TestGroupNode const& groupNode, double suiteTime ) {
XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
TestGroupStats const& stats = groupNode.value; TestGroupStats const& stats = groupNode.value;
xml.writeAttribute( "name", stats.groupInfo.name ); xml.writeAttribute( "name", stats.groupInfo.name );
xml.writeAttribute( "errors", unexpectedExceptions ); xml.writeAttribute( "errors", unexpectedExceptions );
@ -142,6 +127,21 @@ namespace Catch {
xml.writeAttribute( "time", suiteTime ); xml.writeAttribute( "time", suiteTime );
xml.writeAttribute( "timestamp", getCurrentTimestamp() ); xml.writeAttribute( "timestamp", getCurrentTimestamp() );
// Write properties if there are any
if (m_config->hasTestFilters() || m_config->rngSeed() != 0) {
auto properties = xml.scopedElement("properties");
if (m_config->hasTestFilters()) {
xml.scopedElement("property")
.writeAttribute("name", "filters")
.writeAttribute("value", serializeFilters(m_config->getTestsOrTags()));
}
if (m_config->rngSeed() != 0) {
xml.scopedElement("property")
.writeAttribute("name", "random-seed")
.writeAttribute("value", m_config->rngSeed());
}
}
// Write test cases // Write test cases
for( auto const& child : groupNode.children ) for( auto const& child : groupNode.children )
writeTestCase( *child ); writeTestCase( *child );

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuites> <testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="123" tests="1437" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties> <properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>
</properties> </properties>
loose text artifact
<testsuite name="<exe-name>" errors="17" failures="123" tests="1437" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/> <testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/> <testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/> <testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>