Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Use [#filename] tag for junit testcase classname attribute

If [#filename] is present in tags, use it for the classname attribute,
rather than "global". If the test fixture is present that still takes
precedence.
Commit
a6b03031ba56ffda9c2b655ac2d17ed9d49e3659
Author
Thomas Sondergaard ·
Parents
a64a0c6f06bd

Files · Download .tar.gz

Changes

 include/reporters/catch_reporter_junit.hpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp
index c8f1238e..2b5a9bd5 100644
--- a/include/reporters/catch_reporter_junit.hpp
+++ b/include/reporters/catch_reporter_junit.hpp
@@ -128,6 +128,13 @@ namespace Catch {
             xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
         }
 
+        static std::string fileNameTag( const std::set<std::string> &tags ) {
+            std::set<std::string>::const_iterator it = tags.lower_bound("#");
+            if( it != tags.end() && !it->empty() && it->front() == '#' )
+                return it->substr(1);
+            return std::string();
+        }
+
         void writeTestCase( TestCaseNode const& testCaseNode ) {
             TestCaseStats const& stats = testCaseNode.value;
 
@@ -139,7 +146,9 @@ namespace Catch {
             std::string className = stats.testInfo.className;
 
             if( className.empty() ) {
-                className = "global";
+                className = fileNameTag(stats.testInfo.tags);
+                if ( className.empty() )
+                    className = "global";
             }
             writeSection( className, "", rootSection );
         }