XmlReporter enhancement: Add attributes for duration when requested by the command line.

This commit is contained in:
Sean D. Cline 2014-10-11 19:57:45 -04:00
parent b0e53a8ee0
commit ea81e98d6a

View File

@ -13,6 +13,7 @@
#include "../internal/catch_capture.hpp" #include "../internal/catch_capture.hpp"
#include "../internal/catch_reporter_registrars.hpp" #include "../internal/catch_reporter_registrars.hpp"
#include "../internal/catch_xmlwriter.hpp" #include "../internal/catch_xmlwriter.hpp"
#include "../internal/catch_timer.h"
namespace Catch { namespace Catch {
class XmlReporter : public StreamingReporterBase { class XmlReporter : public StreamingReporterBase {
@ -56,6 +57,9 @@ namespace Catch {
virtual void testCaseStarting( TestCaseInfo const& testInfo ) { virtual void testCaseStarting( TestCaseInfo const& testInfo ) {
StreamingReporterBase::testCaseStarting(testInfo); StreamingReporterBase::testCaseStarting(testInfo);
m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) ); m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) );
if ( m_config->showDurations() == ShowDurations::Always )
m_testCaseTimer.start();
} }
virtual void sectionStarting( SectionInfo const& sectionInfo ) { virtual void sectionStarting( SectionInfo const& sectionInfo ) {
@ -143,18 +147,26 @@ namespace Catch {
virtual void sectionEnded( SectionStats const& sectionStats ) { virtual void sectionEnded( SectionStats const& sectionStats ) {
StreamingReporterBase::sectionEnded( sectionStats ); StreamingReporterBase::sectionEnded( sectionStats );
if( --m_sectionDepth > 0 ) { if( --m_sectionDepth > 0 ) {
m_xml.scopedElement( "OverallResults" ) XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
.writeAttribute( "successes", sectionStats.assertions.passed ) e.writeAttribute( "successes", sectionStats.assertions.passed );
.writeAttribute( "failures", sectionStats.assertions.failed ) e.writeAttribute( "failures", sectionStats.assertions.failed );
.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
if ( m_config->showDurations() == ShowDurations::Always )
e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
m_xml.endElement(); m_xml.endElement();
} }
} }
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { virtual void testCaseEnded( TestCaseStats const& testCaseStats ) {
StreamingReporterBase::testCaseEnded( testCaseStats ); StreamingReporterBase::testCaseEnded( testCaseStats );
m_xml.scopedElement( "OverallResult" ) XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
.writeAttribute( "success", testCaseStats.totals.assertions.allPassed() ); e.writeAttribute( "success", testCaseStats.totals.assertions.allPassed() );
if ( m_config->showDurations() == ShowDurations::Always )
e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
m_xml.endElement(); m_xml.endElement();
} }
@ -178,6 +190,7 @@ namespace Catch {
} }
private: private:
Timer m_testCaseTimer;
XmlWriter m_xml; XmlWriter m_xml;
int m_sectionDepth; int m_sectionDepth;
}; };