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

Allow name to be provided for overall test run

Commit
b3db552cfab5bd0f7821a439e1bd509f2cede51d
Author
Phil Nash ·
Parents
0bc42c56590b

Files · Download .tar.gz

Changes

 catch_reporter_basic.hpp             |  5 ++++-
 catch_reporter_xml.hpp               |  2 ++
 internal/catch_commandline.hpp       |  8 ++++++++
 internal/catch_config.hpp            | 16 +++++++++++++++-
 internal/catch_interfaces_reporter.h |  3 +++
 5 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/catch_reporter_basic.hpp b/catch_reporter_basic.hpp
index b4ca75b7..9bde2297 100644
--- a/catch_reporter_basic.hpp
+++ b/catch_reporter_basic.hpp
@@ -266,7 +266,10 @@ namespace Catch
         {
             if( !m_testingSpan.emitted )
             {
-                m_config.stream() << "[Started testing]" << std::endl;
+                if( m_config.getName().empty() )
+                    m_config.stream() << "[Started testing]" << std::endl;
+                else
+                    m_config.stream() << "[Started testing: " << m_config.getName() << "]" << std::endl;
                 m_testingSpan.emitted = true;
             }
             
diff --git a/catch_reporter_xml.hpp b/catch_reporter_xml.hpp
index 06639a15..8b26f169 100644
--- a/catch_reporter_xml.hpp
+++ b/catch_reporter_xml.hpp
@@ -46,6 +46,8 @@ namespace Catch
         {
             m_xml = XmlWriter( m_config.stream() );
             m_xml.startElement( "Catch" );
+            if( !m_config.getName().empty() )
+                m_xml.writeAttribute( "name", m_config.getName() );
         }
         
         ///////////////////////////////////////////////////////////////////////////
diff --git a/internal/catch_commandline.hpp b/internal/catch_commandline.hpp
index 76189718..0eedcb00 100644
--- a/internal/catch_commandline.hpp
+++ b/internal/catch_commandline.hpp
@@ -30,6 +30,7 @@ namespace Catch
     // -o, --out filename to write to
     // -s, --success report successful cases too
     // -b, --break breaks into debugger on test failure
+    // -n, --name specifies an optional name for the test run
 	class ArgParser : NonCopyable
     {
         enum Mode
@@ -41,6 +42,7 @@ namespace Catch
             modeOutput,
             modeSuccess,
             modeBreak,
+            modeName,
             modeHelp,
 
             modeError
@@ -74,6 +76,8 @@ namespace Catch
                         changeMode( cmd, modeSuccess );
                     else if( cmd == "-b" || cmd == "--break" )
                         changeMode( cmd, modeBreak );
+                    else if( cmd == "-n" || cmd == "--name" )
+                        changeMode( cmd, modeName );
                     else if( cmd == "-h" || cmd == "-?" || cmd == "--help" )
                         changeMode( cmd, modeHelp );
                 }
@@ -179,6 +183,10 @@ namespace Catch
                     if( m_args.size() != 0 )
                         return setErrorMode( m_command + " does not accept arguments" );
                     m_config.setShouldDebugBreak( true );
+                case modeName:
+                    if( m_args.size() != 1 )
+                        return setErrorMode( m_command + " requires exactly one argument (a name)" );
+                    m_config.setName( m_args[0] );
                     break;
                 case modeHelp:
                     if( m_args.size() != 0 )
diff --git a/internal/catch_config.hpp b/internal/catch_config.hpp
index 9752ba06..e577cacb 100644
--- a/internal/catch_config.hpp
+++ b/internal/catch_config.hpp
@@ -171,6 +171,18 @@ namespace Catch
             m_shouldDebugBreak = shouldDebugBreakFlag;
         }
 
+        ///////////////////////////////////////////////////////////////////////////
+        void setName( const std::string& name )
+        {
+            m_name = name;
+        }
+
+        ///////////////////////////////////////////////////////////////////////////
+        std::string getName() const
+        {
+            return m_name;
+        }
+        
         ///////////////////////////////////////////////////////////////////////////
         bool shouldDebugBreak() const
         {
@@ -228,7 +240,9 @@ namespace Catch
         bool m_showHelp;
         std::streambuf* m_streambuf;
         mutable std::ostream m_os;
-        Include::What m_includeWhat;        
+        Include::What m_includeWhat;
+        std::string m_name;
+        
     };
     
 } // end namespace Catch
diff --git a/internal/catch_interfaces_reporter.h b/internal/catch_interfaces_reporter.h
index f6d4c9af..0861e127 100644
--- a/internal/catch_interfaces_reporter.h
+++ b/internal/catch_interfaces_reporter.h
@@ -33,6 +33,9 @@ namespace Catch
         
         virtual bool includeSuccessfulResults
             () const = 0;
+
+        virtual std::string getName
+            () const = 0;
     };
     
     class TestCaseInfo;