diff options
| author | Sean D. Cline | 2014-10-11 19:57:45 -0400 |
|---|---|---|
| committer | Sean D. Cline | 2014-10-11 19:58:44 -0400 |
| commit | ea81e98d6a01fc7858ac2339ddde90b7cb8162bd (patch) | |
| tree | d1a44f41957a13e9f748c33d15b38afe0b30c13f /include | |
| parent | b0e53a8ee006cee203a40bf3c1454e8806135d9c (diff) | |
| download | catch3-ea81e98d6a01fc7858ac2339ddde90b7cb8162bd.tar.gz | |
XmlReporter enhancement: Add attributes for duration when requested by the command line.
Diffstat (limited to 'include')
| -rw-r--r-- | include/reporters/catch_reporter_xml.hpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp index 6b31107a..530bb3c5 100644 --- a/include/reporters/catch_reporter_xml.hpp +++ b/include/reporters/catch_reporter_xml.hpp @@ -13,6 +13,7 @@ #include "../internal/catch_capture.hpp" #include "../internal/catch_reporter_registrars.hpp" #include "../internal/catch_xmlwriter.hpp" +#include "../internal/catch_timer.h" namespace Catch { class XmlReporter : public StreamingReporterBase { @@ -56,6 +57,9 @@ namespace Catch { virtual void testCaseStarting( TestCaseInfo const& testInfo ) { StreamingReporterBase::testCaseStarting(testInfo); m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) ); + + if ( m_config->showDurations() == ShowDurations::Always ) + m_testCaseTimer.start(); } virtual void sectionStarting( SectionInfo const& sectionInfo ) { @@ -143,18 +147,26 @@ namespace Catch { virtual void sectionEnded( SectionStats const& sectionStats ) { StreamingReporterBase::sectionEnded( sectionStats ); if( --m_sectionDepth > 0 ) { - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", sectionStats.assertions.passed ) - .writeAttribute( "failures", sectionStats.assertions.failed ) - .writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); + e.writeAttribute( "successes", sectionStats.assertions.passed ); + e.writeAttribute( "failures", sectionStats.assertions.failed ); + e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); + m_xml.endElement(); } } virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { StreamingReporterBase::testCaseEnded( testCaseStats ); - m_xml.scopedElement( "OverallResult" ) - .writeAttribute( "success", testCaseStats.totals.assertions.allPassed() ); + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); + e.writeAttribute( "success", testCaseStats.totals.assertions.allPassed() ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); + m_xml.endElement(); } @@ -178,6 +190,7 @@ namespace Catch { } private: + Timer m_testCaseTimer; XmlWriter m_xml; int m_sectionDepth; }; |