XML Reporter closes tag and flushes stream at end of TestCase and Section tags.

This fixes an issue where XML reports on stdout are broken by printf statements
This commit is contained in:
Phil Nash 2017-02-13 15:56:25 +00:00
parent bc68b9f454
commit 873ef276b6
7 changed files with 23 additions and 12 deletions

View File

@ -211,6 +211,13 @@ namespace Catch {
return *this; return *this;
} }
void ensureTagClosed() {
if( m_tagIsOpen ) {
m_os << ">" << std::endl;
m_tagIsOpen = false;
}
}
private: private:
XmlWriter( XmlWriter const& ); XmlWriter( XmlWriter const& );
void operator=( XmlWriter const& ); void operator=( XmlWriter const& );
@ -219,13 +226,6 @@ namespace Catch {
m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
} }
void ensureTagClosed() {
if( m_tagIsOpen ) {
m_os << ">" << std::endl;
m_tagIsOpen = false;
}
}
void newlineIfNecessary() { void newlineIfNecessary() {
if( m_needsNewline ) { if( m_needsNewline ) {
m_os << std::endl; m_os << std::endl;

View File

@ -67,6 +67,7 @@ namespace Catch {
if ( m_config->showDurations() == ShowDurations::Always ) if ( m_config->showDurations() == ShowDurations::Always )
m_testCaseTimer.start(); m_testCaseTimer.start();
m_xml.ensureTagClosed();
} }
virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
@ -75,6 +76,7 @@ namespace Catch {
m_xml.startElement( "Section" ) m_xml.startElement( "Section" )
.writeAttribute( "name", trim( sectionInfo.name ) ) .writeAttribute( "name", trim( sectionInfo.name ) )
.writeAttribute( "description", sectionInfo.description ); .writeAttribute( "description", sectionInfo.description );
m_xml.ensureTagClosed();
} }
} }

View File

@ -711,7 +711,7 @@ MiscTests.cpp:<line number>: FAILED:
with expansion: with expansion:
false false
------------------------------------------------------------------------------- spanner-------------------------------------------------------------------------------
just failure just failure
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
MessageTests.cpp:<line number> MessageTests.cpp:<line number>
@ -829,6 +829,6 @@ with expansion:
"first" == "second" "first" == "second"
=============================================================================== ===============================================================================
test cases: 160 | 116 passed | 42 failed | 2 failed as expected test cases: 161 | 117 passed | 42 failed | 2 failed as expected
assertions: 932 | 836 passed | 78 failed | 18 failed as expected assertions: 932 | 836 passed | 78 failed | 18 failed as expected

View File

@ -8329,7 +8329,7 @@ MiscTests.cpp:<line number>
MiscTests.cpp:<line number>: MiscTests.cpp:<line number>:
PASSED: PASSED:
------------------------------------------------------------------------------- spanner-------------------------------------------------------------------------------
just failure just failure
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
MessageTests.cpp:<line number> MessageTests.cpp:<line number>
@ -9164,6 +9164,6 @@ MiscTests.cpp:<line number>:
PASSED: PASSED:
=============================================================================== ===============================================================================
test cases: 160 | 115 passed | 43 failed | 2 failed as expected test cases: 161 | 116 passed | 43 failed | 2 failed as expected
assertions: 934 | 836 passed | 80 failed | 18 failed as expected assertions: 934 | 836 passed | 80 failed | 18 failed as expected

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuites> <testsuitesspanner>
<testsuite name="<exe-name>" errors="13" failures="68" tests="935" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="13" failures="68" tests="935" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="global" name="# A test name that starts with a #" time="{duration}"/> <testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="global" name="#542" time="{duration}"/> <testcase classname="global" name="#542" time="{duration}"/>

View File

@ -8845,6 +8845,9 @@ there"
<TestCase name="first tag" tags="[tag1]"> <TestCase name="first tag" tags="[tag1]">
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="has printf">
spanner <OverallResult success="true"/>
</TestCase>
<TestCase name="just failure" tags="[.][fail][hide][isolated info][messages]"> <TestCase name="just failure" tags="[.][fail][hide][isolated info][messages]">
<Failure> <Failure>
Previous info should not be seen Previous info should not be seen

View File

@ -399,3 +399,9 @@ TEST_CASE( "X/level/0/a", "[Tricky]" ) { SUCCEED(""); }
TEST_CASE( "X/level/0/b", "[Tricky][fizz]" ){ SUCCEED(""); } TEST_CASE( "X/level/0/b", "[Tricky][fizz]" ){ SUCCEED(""); }
TEST_CASE( "X/level/1/a", "[Tricky]" ) { SUCCEED(""); } TEST_CASE( "X/level/1/a", "[Tricky]" ) { SUCCEED(""); }
TEST_CASE( "X/level/1/b", "[Tricky]" ) { SUCCEED(""); } TEST_CASE( "X/level/1/b", "[Tricky]" ) { SUCCEED(""); }
TEST_CASE( "has printf", "" ) {
// This can cause problems as, currently, stdout itself is not redirect - only the cout (and cerr) buffer
printf( "spanner" );
}