7 #ifndef CATCH_ROS_ROS_JUNIT_REPORTER_H 8 #define CATCH_ROS_ROS_JUNIT_REPORTER_H 27 class ROSReporter :
public Catch::CumulativeReporterBase<ROSReporter> {
30 : CumulativeReporterBase( _config )
31 ,
xml( _config.stream() )
33 Catch::ReporterConfig consoleConfig(_config.fullConfig(),
consoleOut);
34 console =
new Catch::ConsoleReporter(consoleConfig);
45 return "Reports test result in JUnit format tweaked for ROS";
50 console->noMatchingTestCases(spec);
55 Catch::ReporterPreferences prefs;
56 prefs.shouldRedirectStdOut =
true;
62 CumulativeReporterBase::testRunStarting( runInfo );
63 console->testRunStarting(runInfo);
67 virtual void testRunEnded( Catch::TestRunStats
const& testRunStats )
69 CumulativeReporterBase::testRunEnded( testRunStats );
74 if(testRunStats.totals.testCases.failed)
75 console->testRunEnded(testRunStats);
84 CumulativeReporterBase::testGroupStarting( groupInfo );
85 console->testGroupStarting(groupInfo);
90 CumulativeReporterBase::testGroupEnded( testGroupStats );
91 console->testGroupEnded(testGroupStats);
96 CumulativeReporterBase::sectionStarting(sectionInfo);
97 console->sectionStarting(sectionInfo);
102 CumulativeReporterBase::sectionEnded(sectionStats);
103 console->sectionEnded(sectionStats);
108 CumulativeReporterBase::assertionStarting(assertionInfo);
109 console->assertionStarting(assertionInfo);
120 console->assertionEnded(assertionStats);
121 return CumulativeReporterBase::assertionEnded( assertionStats );
126 CumulativeReporterBase::testCaseStarting(testInfo);
127 console->testCaseStarting(testInfo);
135 CumulativeReporterBase::testCaseEnded( testCaseStats );
136 console->testCaseEnded(testCaseStats);
141 CumulativeReporterBase::skipTest(testInfo);
152 Catch::XmlWriter::ScopedElement e =
xml.scopedElement(
"testsuites" );
154 unsigned int tests = 0;
155 unsigned int failures = 0;
156 for( TestRunNode::ChildNodes::const_iterator
157 it = runNode.children.begin(), itEnd = runNode.children.end();
161 failures += (*it)->value.totals.assertions.failed;
162 tests += (*it)->value.totals.assertions.total();
167 xml.writeAttribute(
"tests", tests );
169 for( TestRunNode::ChildNodes::const_iterator
170 it = runNode.children.begin(), itEnd = runNode.children.end();
178 void writeGroup( TestGroupNode
const& groupNode,
double suiteTime )
180 Catch::XmlWriter::ScopedElement e =
xml.scopedElement(
"testsuite" );
181 Catch::TestGroupStats
const& stats = groupNode.value;
182 xml.writeAttribute(
"name", m_config->name() );
185 xml.writeAttribute(
"tests", stats.totals.assertions.total() );
186 xml.writeAttribute(
"hostname",
"tbd" );
190 if( m_config->showDurations() == Catch::ShowDurations::Never )
191 xml.writeAttribute(
"time",
"" );
193 xml.writeAttribute(
"time", suiteTime );
194 xml.writeAttribute(
"timestamp",
"tbd" );
197 for( TestGroupNode::ChildNodes::const_iterator
198 it = groupNode.children.begin(), itEnd = groupNode.children.end();
209 Catch::TestCaseStats
const& stats = testCaseNode.value;
213 assert( testCaseNode.children.size() == 1 );
214 SectionNode
const& rootSection = *testCaseNode.children.front();
216 std::string className = stats.testInfo.className;
218 if( className.empty() )
220 className = m_config->name();
223 if(className.empty())
232 std::string
const& rootName,
233 SectionNode
const& sectionNode )
235 std::string name =
Catch::trim( sectionNode.stats.sectionInfo.name );
236 if( !rootName.empty() )
237 name = rootName +
"/" + name;
239 if( !sectionNode.assertions.empty() ||
240 !sectionNode.stdOut.empty() ||
241 !sectionNode.stdErr.empty() )
243 Catch::XmlWriter::ScopedElement e =
xml.scopedElement(
"testcase" );
244 if( className.empty() ) {
245 xml.writeAttribute(
"classname", name );
246 xml.writeAttribute(
"name",
"root" );
249 xml.writeAttribute(
"classname", className );
250 xml.writeAttribute(
"name", name );
252 xml.writeAttribute(
"time", std::to_string( sectionNode.stats.durationInSeconds ) );
256 if( !sectionNode.stdOut.empty() )
257 xml.scopedElement(
"system-out" ).writeText(
Catch::trim( sectionNode.stdOut ),
false );
258 if( !sectionNode.stdErr.empty() )
259 xml.scopedElement(
"system-err" ).writeText(
Catch::trim( sectionNode.stdErr ),
false );
261 for( SectionNode::ChildSections::const_iterator
262 it = sectionNode.childSections.begin(),
263 itEnd = sectionNode.childSections.end();
267 if( className.empty() )
276 for( SectionNode::Assertions::const_iterator
277 it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end();
286 Catch::AssertionResult
const& result = stats.assertionResult;
287 if( !result.isOk() ) {
288 std::string elementName;
289 switch( result.getResultType() ) {
292 elementName =
"error";
295 elementName =
"failure";
298 elementName =
"failure";
301 elementName =
"failure";
311 elementName =
"internalError";
315 Catch::XmlWriter::ScopedElement e =
xml.scopedElement( elementName );
317 xml.writeAttribute(
"message", result.getExpandedExpression() );
318 xml.writeAttribute(
"type", result.getTestMacroName() );
320 std::ostringstream oss;
321 if( !result.getMessage().empty() )
322 oss << result.getMessage() <<
"\n";
323 for( std::vector<Catch::MessageInfo>::const_iterator
324 it = stats.infoMessages.begin(),
325 itEnd = stats.infoMessages.end();
330 oss << it->message <<
"\n";
333 oss <<
"at " << result.getSourceInfo();
334 xml.writeText( oss.str(), false );
349 CATCH_REGISTER_REPORTER(
"ros_junit",
ROSReporter )
void writeRun(TestRunNode const &runNode)
virtual void testRunEnded(Catch::TestRunStats const &testRunStats)
void writeSection(std::string const &className, std::string const &rootName, SectionNode const §ionNode)
void writeTestCase(TestCaseNode const &testCaseNode)
void writeGroup(TestGroupNode const &groupNode, double suiteTime)
Catch::ConsoleReporter * console
static std::string getDescription()
virtual bool assertionEnded(Catch::AssertionStats const &assertionStats)
void writeAssertions(SectionNode const §ionNode)
unsigned int totalUnexpectedExceptions
std::ostringstream stdErrForSuite
unsigned int unexpectedExceptions
virtual void testCaseEnded(Catch::TestCaseStats const &testCaseStats)
virtual void testGroupEnded(Catch::TestGroupStats const &testGroupStats)
virtual void testCaseStarting(Catch::TestCaseInfo const &testInfo)
virtual void sectionEnded(Catch::SectionStats const §ionStats)
std::stringstream consoleOut
std::string trim(std::string const &str)
virtual void sectionStarting(Catch::SectionInfo const §ionInfo)
virtual void testRunEndedCumulative()
virtual void testRunStarting(Catch::TestRunInfo const &runInfo)
virtual void skipTest(Catch::TestCaseInfo const &testInfo)
std::ostringstream stdOutForSuite
virtual void assertionStarting(Catch::AssertionInfo const &assertionInfo)
virtual Catch::ReporterPreferences getPreferences() const
ROSReporter(Catch::ReporterConfig const &_config)
virtual void noMatchingTestCases(std::string const &spec)
virtual void testGroupStarting(Catch::GroupInfo const &groupInfo)
void writeAssertion(Catch::AssertionStats const &stats)