Skip to content

Commit 873ef27

Browse files
committed
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
1 parent bc68b9f commit 873ef27

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

include/internal/catch_xmlwriter.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ namespace Catch {
211211
return *this;
212212
}
213213

214+
void ensureTagClosed() {
215+
if( m_tagIsOpen ) {
216+
m_os << ">" << std::endl;
217+
m_tagIsOpen = false;
218+
}
219+
}
220+
214221
private:
215222
XmlWriter( XmlWriter const& );
216223
void operator=( XmlWriter const& );
@@ -219,13 +226,6 @@ namespace Catch {
219226
m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
220227
}
221228

222-
void ensureTagClosed() {
223-
if( m_tagIsOpen ) {
224-
m_os << ">" << std::endl;
225-
m_tagIsOpen = false;
226-
}
227-
}
228-
229229
void newlineIfNecessary() {
230230
if( m_needsNewline ) {
231231
m_os << std::endl;

include/reporters/catch_reporter_xml.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ namespace Catch {
6767

6868
if ( m_config->showDurations() == ShowDurations::Always )
6969
m_testCaseTimer.start();
70+
m_xml.ensureTagClosed();
7071
}
7172

7273
virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
@@ -75,6 +76,7 @@ namespace Catch {
7576
m_xml.startElement( "Section" )
7677
.writeAttribute( "name", trim( sectionInfo.name ) )
7778
.writeAttribute( "description", sectionInfo.description );
79+
m_xml.ensureTagClosed();
7880
}
7981
}
8082

projects/SelfTest/Baselines/console.std.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ MiscTests.cpp:<line number>: FAILED:
711711
with expansion:
712712
false
713713

714-
-------------------------------------------------------------------------------
714+
spanner-------------------------------------------------------------------------------
715715
just failure
716716
-------------------------------------------------------------------------------
717717
MessageTests.cpp:<line number>
@@ -829,6 +829,6 @@ with expansion:
829829
"first" == "second"
830830

831831
===============================================================================
832-
test cases: 160 | 116 passed | 42 failed | 2 failed as expected
832+
test cases: 161 | 117 passed | 42 failed | 2 failed as expected
833833
assertions: 932 | 836 passed | 78 failed | 18 failed as expected
834834

projects/SelfTest/Baselines/console.sw.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8329,7 +8329,7 @@ MiscTests.cpp:<line number>
83298329
MiscTests.cpp:<line number>:
83308330
PASSED:
83318331

8332-
-------------------------------------------------------------------------------
8332+
spanner-------------------------------------------------------------------------------
83338333
just failure
83348334
-------------------------------------------------------------------------------
83358335
MessageTests.cpp:<line number>
@@ -9164,6 +9164,6 @@ MiscTests.cpp:<line number>:
91649164
PASSED:
91659165

91669166
===============================================================================
9167-
test cases: 160 | 115 passed | 43 failed | 2 failed as expected
9167+
test cases: 161 | 116 passed | 43 failed | 2 failed as expected
91689168
assertions: 934 | 836 passed | 80 failed | 18 failed as expected
91699169

projects/SelfTest/Baselines/junit.sw.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<testsuites>
2+
<testsuitesspanner>
33
<testsuite name="<exe-name>" errors="13" failures="68" tests="935" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
44
<testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
55
<testcase classname="global" name="#542" time="{duration}"/>

projects/SelfTest/Baselines/xml.sw.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8845,6 +8845,9 @@ there"
88458845
<TestCase name="first tag" tags="[tag1]">
88468846
<OverallResult success="true"/>
88478847
</TestCase>
8848+
<TestCase name="has printf">
8849+
spanner <OverallResult success="true"/>
8850+
</TestCase>
88488851
<TestCase name="just failure" tags="[.][fail][hide][isolated info][messages]">
88498852
<Failure>
88508853
Previous info should not be seen

projects/SelfTest/TrickyTests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,9 @@ TEST_CASE( "X/level/0/a", "[Tricky]" ) { SUCCEED(""); }
399399
TEST_CASE( "X/level/0/b", "[Tricky][fizz]" ){ SUCCEED(""); }
400400
TEST_CASE( "X/level/1/a", "[Tricky]" ) { SUCCEED(""); }
401401
TEST_CASE( "X/level/1/b", "[Tricky]" ) { SUCCEED(""); }
402+
403+
TEST_CASE( "has printf", "" ) {
404+
405+
// This can cause problems as, currently, stdout itself is not redirect - only the cout (and cerr) buffer
406+
printf( "spanner" );
407+
}

0 commit comments

Comments
 (0)