From d370de63bdfff40e5c3700e2a718a1fce8d5446d Mon Sep 17 00:00:00 2001 From: Amaury Chamayou Date: Fri, 15 Jun 2018 08:06:55 +0100 Subject: [PATCH] Always report the topLevel testcase in JUnit backend --- include/reporters/catch_reporter_junit.cpp | 19 +++++---- include/reporters/catch_reporter_junit.h | 3 +- .../SelfTest/Baselines/junit.sw.approved.txt | 42 +++++++++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/include/reporters/catch_reporter_junit.cpp b/include/reporters/catch_reporter_junit.cpp index 55129b76..81f5bda4 100644 --- a/include/reporters/catch_reporter_junit.cpp +++ b/include/reporters/catch_reporter_junit.cpp @@ -152,19 +152,20 @@ namespace Catch { if ( !m_config->name().empty() ) className = m_config->name() + "." + className; - writeSection( className, "", rootSection ); + writeSection( className, "", rootSection, true); } void JunitReporter::writeSection( std::string const& className, std::string const& rootName, - SectionNode const& sectionNode ) { + SectionNode const& sectionNode, + bool topLevel) { std::string name = trim( sectionNode.stats.sectionInfo.name ); if( !rootName.empty() ) name = rootName + '/' + name; - if( !sectionNode.assertions.empty() || - !sectionNode.stdOut.empty() || - !sectionNode.stdErr.empty() ) { + if (topLevel || (!sectionNode.assertions.empty() || + !sectionNode.stdOut.empty() || + !sectionNode.stdErr.empty())) { XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); if( className.empty() ) { xml.writeAttribute( "classname", name ); @@ -176,18 +177,20 @@ namespace Catch { } xml.writeAttribute( "time", ::Catch::Detail::stringify( sectionNode.stats.durationInSeconds ) ); - writeAssertions( sectionNode ); + if( !sectionNode.assertions.empty() ) + writeAssertions( sectionNode ); if( !sectionNode.stdOut.empty() ) xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); if( !sectionNode.stdErr.empty() ) xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); } + for( auto const& childNode : sectionNode.childSections ) if( className.empty() ) - writeSection( name, "", *childNode ); + writeSection( name, "", *childNode, false ); else - writeSection( className, name, *childNode ); + writeSection( className, name, *childNode, false ); } void JunitReporter::writeAssertions( SectionNode const& sectionNode ) { diff --git a/include/reporters/catch_reporter_junit.h b/include/reporters/catch_reporter_junit.h index 5ee3a570..88767de3 100644 --- a/include/reporters/catch_reporter_junit.h +++ b/include/reporters/catch_reporter_junit.h @@ -43,7 +43,8 @@ namespace Catch { void writeSection(std::string const& className, std::string const& rootName, - SectionNode const& sectionNode); + SectionNode const& sectionNode, + bool topLevel); void writeAssertions(SectionNode const& sectionNode); void writeAssertion(AssertionStats const& stats); diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 62ca9094..50c54060 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -9,6 +9,7 @@ + expected exception @@ -32,6 +33,7 @@ Misc.tests.cpp: + @@ -64,6 +66,7 @@ Condition.tests.cpp: + @@ -97,6 +100,7 @@ Tricky.tests.cpp: + @@ -112,6 +116,7 @@ Exception.tests.cpp: + @@ -120,8 +125,10 @@ Exception.tests.cpp: + + @@ -219,6 +226,7 @@ Matchers.tests.cpp: + Matchers.tests.cpp: @@ -246,6 +254,7 @@ Matchers.tests.cpp: + @@ -280,10 +289,12 @@ Message.tests.cpp: + + @@ -424,6 +435,7 @@ Condition.tests.cpp: + Message from section one @@ -436,6 +448,7 @@ Message from section two Message.tests.cpp: + @@ -469,6 +482,7 @@ Message.tests.cpp: + @@ -511,11 +525,15 @@ Matchers.tests.cpp: + + + + @@ -530,6 +548,7 @@ A string sent to stderr via clog + Message from section one @@ -544,10 +563,12 @@ Matchers.tests.cpp: Matchers.tests.cpp: + + @@ -580,6 +601,7 @@ Matchers.tests.cpp: Misc.tests.cpp: + @@ -616,12 +638,15 @@ Exception.tests.cpp: + + + Matchers.tests.cpp: @@ -691,18 +716,21 @@ expected exception Exception.tests.cpp: + unexpected exception Exception.tests.cpp: + + @@ -711,6 +739,7 @@ Exception.tests.cpp: + @@ -740,16 +769,21 @@ Misc.tests.cpp: + + + Previous info should not be seen Message.tests.cpp: + + Misc.tests.cpp: @@ -781,6 +815,7 @@ Testing if fib[7] (21) is even Misc.tests.cpp: + Misc.tests.cpp: @@ -788,6 +823,7 @@ Misc.tests.cpp: + @@ -797,8 +833,10 @@ Misc.tests.cpp: + + @@ -806,6 +844,7 @@ Misc.tests.cpp: + 3 @@ -819,11 +858,13 @@ i := 7 Message.tests.cpp: + + @@ -873,6 +914,7 @@ Exception.tests.cpp: +