MCPcopy Create free account
hub / github.com/catchorg/Catch2 / writeSection

Method writeSection

extras/catch_amalgamated.cpp:11168–11213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11166 }
11167
11168 void JunitReporter::writeSection( std::string const& className,
11169 std::string const& rootName,
11170 SectionNode const& sectionNode,
11171 bool testOkToFail) {
11172 std::string name = trim( sectionNode.stats.sectionInfo.name );
11173 if( !rootName.empty() )
11174 name = rootName + '/' + name;
11175
11176 if ( sectionNode.stats.assertions.total() > 0
11177 || !sectionNode.stdOut.empty()
11178 || !sectionNode.stdErr.empty() ) {
11179 XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
11180 if( className.empty() ) {
11181 xml.writeAttribute( "classname"_sr, name );
11182 xml.writeAttribute( "name"_sr, "root"_sr );
11183 }
11184 else {
11185 xml.writeAttribute( "classname"_sr, className );
11186 xml.writeAttribute( "name"_sr, name );
11187 }
11188 xml.writeAttribute( "time"_sr, formatDuration( sectionNode.stats.durationInSeconds ) );
11189 // This is not ideal, but it should be enough to mimic gtest's
11190 // junit output.
11191 // Ideally the JUnit reporter would also handle `skipTest`
11192 // events and write those out appropriately.
11193 xml.writeAttribute( "status"_sr, "run"_sr );
11194
11195 if (sectionNode.stats.assertions.failedButOk) {
11196 xml.scopedElement("skipped")
11197 .writeAttribute("message", "TEST_CASE tagged with !mayfail");
11198 }
11199
11200 writeAssertions( sectionNode );
11201
11202
11203 if( !sectionNode.stdOut.empty() )
11204 xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), XmlFormatting::Newline );
11205 if( !sectionNode.stdErr.empty() )
11206 xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), XmlFormatting::Newline );
11207 }
11208 for( auto const& childNode : sectionNode.childSections )
11209 if( className.empty() )
11210 writeSection( name, "", *childNode, testOkToFail );
11211 else
11212 writeSection( className, name, *childNode, testOkToFail );
11213 }
11214
11215 void JunitReporter::writeAssertions( SectionNode const& sectionNode ) {
11216 for (auto const& assertionOrBenchmark : sectionNode.assertionsAndBenchmarks) {

Callers

nothing calls this directly

Calls 5

trimFunction · 0.70
formatDurationFunction · 0.70
emptyMethod · 0.45
totalMethod · 0.45
scopedElementMethod · 0.45

Tested by

no test coverage detected