| 16968 | } |
| 16969 | |
| 16970 | void JunitReporter::writeSection( std::string const& className, |
| 16971 | std::string const& rootName, |
| 16972 | SectionNode const& sectionNode, |
| 16973 | bool testOkToFail) { |
| 16974 | std::string name = trim( sectionNode.stats.sectionInfo.name ); |
| 16975 | if( !rootName.empty() ) |
| 16976 | name = rootName + '/' + name; |
| 16977 | |
| 16978 | if( !sectionNode.assertions.empty() || |
| 16979 | !sectionNode.stdOut.empty() || |
| 16980 | !sectionNode.stdErr.empty() ) { |
| 16981 | XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); |
| 16982 | if( className.empty() ) { |
| 16983 | xml.writeAttribute( "classname", name ); |
| 16984 | xml.writeAttribute( "name", "root" ); |
| 16985 | } |
| 16986 | else { |
| 16987 | xml.writeAttribute( "classname", className ); |
| 16988 | xml.writeAttribute( "name", name ); |
| 16989 | } |
| 16990 | xml.writeAttribute( "time", formatDuration( sectionNode.stats.durationInSeconds ) ); |
| 16991 | // This is not ideal, but it should be enough to mimic gtest's |
| 16992 | // junit output. |
| 16993 | // Ideally the JUnit reporter would also handle `skipTest` |
| 16994 | // events and write those out appropriately. |
| 16995 | xml.writeAttribute( "status", "run" ); |
| 16996 | |
| 16997 | if (sectionNode.stats.assertions.failedButOk) { |
| 16998 | xml.scopedElement("skipped") |
| 16999 | .writeAttribute("message", "TEST_CASE tagged with !mayfail"); |
| 17000 | } |
| 17001 | |
| 17002 | writeAssertions( sectionNode ); |
| 17003 | |
| 17004 | if( !sectionNode.stdOut.empty() ) |
| 17005 | xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), XmlFormatting::Newline ); |
| 17006 | if( !sectionNode.stdErr.empty() ) |
| 17007 | xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), XmlFormatting::Newline ); |
| 17008 | } |
| 17009 | for( auto const& childNode : sectionNode.childSections ) |
| 17010 | if( className.empty() ) |
| 17011 | writeSection( name, "", *childNode, testOkToFail ); |
| 17012 | else |
| 17013 | writeSection( className, name, *childNode, testOkToFail ); |
| 17014 | } |
| 17015 | |
| 17016 | void JunitReporter::writeAssertions( SectionNode const& sectionNode ) { |
| 17017 | for( auto const& assertion : sectionNode.assertions ) |
nothing calls this directly
no test coverage detected