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

Added help option

Commit
27fdf01b763659684723e4cbf9362a6d5836136e
Author
Phil Nash ·
Parents
c60156ad1133

Files · Download .tar.gz

Changes

 catch_runner.hpp                | 21 +++++++++++++++++++++
 internal/catch_commandline.hpp  | 16 ++++++++++++----
 internal/catch_runnerconfig.hpp | 13 ++++++++++++-
 3 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/catch_runner.hpp b/catch_runner.hpp
index b89ddfec..37060b99 100644
--- a/catch_runner.hpp
+++ b/catch_runner.hpp
@@ -36,6 +36,27 @@ namespace Catch
             return std::numeric_limits<int>::max();
         }
         
+        // Handle help
+        if( config.showHelp() )
+        {
+            std::string exeName( argv[0] );
+            std::string::size_type pos = exeName.find_last_of( "/\\" );
+            if( pos != std::string::npos )
+            {
+                exeName = exeName.substr( pos+1 );
+            }
+            
+            std::cout   << exeName << " is a CATCH host application. Options are as follows:\n\n"
+                        << "\t-l, --list <tests | reporters> [xml]\n"
+                        << "\t-t, --test <testspec> [<testspec>...]\n"
+                        << "\t-r, --reporter <reporter name>\n"
+                        << "\t-o, --out <file name>\n"
+                        << "\t-s, --success\n"
+                        << "\t-b, --break\n\n"
+                        << "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
+            return 0;
+        }
+        
         // Handle list request
         if( config.listWhat() != RunnerConfig::listNone )
             return List( config );
diff --git a/internal/catch_commandline.hpp b/internal/catch_commandline.hpp
index 3c297316..3e80603a 100644
--- a/internal/catch_commandline.hpp
+++ b/internal/catch_commandline.hpp
@@ -19,10 +19,10 @@
 namespace Catch
 {
     // -l, --list tests [xml] lists available tests (optionally in xml)
-    // -l, --list reports [xml] lists available reports (optionally in xml)
+    // -l, --list reporters [xml] lists available reports (optionally in xml)
     // -l, --list all [xml] lists available tests and reports (optionally in xml)
     // -t, --test "testspec" ["testspec", ...]
-    // -r, --report <type>
+    // -r, --reporter <type>
     // -o, --out filename to write to
     // -s, --success report successful cases too
     // -b, --break breaks into debugger on test failure
@@ -37,6 +37,7 @@ namespace Catch
             modeOutput,
             modeSuccess,
             modeBreak,
+            modeHelp,
 
             modeError
         };
@@ -55,7 +56,7 @@ namespace Catch
                         changeMode( cmd, modeList );
                     else if( cmd == "-t" || cmd == "--test" )
                         changeMode( cmd, modeTest );
-                    else if( cmd == "-r" || cmd == "--report" )
+                    else if( cmd == "-r" || cmd == "--reporter" )
                         changeMode( cmd, modeReport );
                     else if( cmd == "-o" || cmd == "--out" )
                         changeMode( cmd, modeOutput );
@@ -63,6 +64,8 @@ namespace Catch
                         changeMode( cmd, modeSuccess );
                     else if( cmd == "-b" || cmd == "--break" )
                         changeMode( cmd, modeBreak );
+                    else if( cmd == "-h" || cmd == "-?" || cmd == "--help" )
+                        changeMode( cmd, modeHelp );
                 }
                 else
                 {
@@ -157,7 +160,12 @@ namespace Catch
                         return setErrorMode( m_command + " does not accept arguments" );
                     m_config.setShouldDebugBreak( true );
                     break;
-            default:
+                case modeHelp:
+                    if( m_args.size() != 0 )
+                        return setErrorMode( m_command + " does not accept arguments" );
+                    m_config.setShowHelp( true );
+                    break;
+                default:
                 break;
             }
             m_args.clear();
diff --git a/internal/catch_runnerconfig.hpp b/internal/catch_runnerconfig.hpp
index cf750e26..4d5b174c 100644
--- a/internal/catch_runnerconfig.hpp
+++ b/internal/catch_runnerconfig.hpp
@@ -45,7 +45,8 @@ namespace Catch
         RunnerConfig()
         :   m_reporter( NULL ),
             m_listSpec( listNone ),
-            m_shouldDebugBreak( false )
+            m_shouldDebugBreak( false ),
+            m_showHelp( false )
         {}
         
         void setReporterInfo( const std::string& reporterName )
@@ -122,6 +123,15 @@ namespace Catch
         {
             return m_shouldDebugBreak;
         }
+        void setShowHelp( bool showHelp )
+        {
+            m_showHelp = showHelp;
+        }
+        bool showHelp() const
+        {
+            return m_showHelp;
+        }
+        
         
         std::auto_ptr<ITestReporter> m_reporter;
         std::string m_filename;
@@ -130,6 +140,7 @@ namespace Catch
         ListInfo m_listSpec;
         std::vector<std::string> m_testSpecs;
         bool m_shouldDebugBreak;
+        bool m_showHelp;
     };
     
 } // end namespace Catch