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

Split Main impl into layered functions to offer more customisation points

Commit
0571f797c023fcebd49142acbf2f0b389ef4d28f
Author
Phil Nash ·
Parents
18553e09fdc4

Files · Download .tar.gz

Changes

 catch_runner.hpp | 89 ++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 57 insertions(+), 32 deletions(-)

diff --git a/catch_runner.hpp b/catch_runner.hpp
index 1d0014aa..40f7456b 100644
--- a/catch_runner.hpp
+++ b/catch_runner.hpp
@@ -27,38 +27,12 @@
 
 namespace Catch
 {
-    inline int Main( int argc, char * const argv[] )
-    {
-        Config config;
-        ArgParser( argc, argv, config );
-        
-        if( !config.getMessage().empty() )
-        {
-            std::cerr << config.getMessage() << std::endl;
-            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>|<%stream 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;
-        }
-        
+    //////////////////////////////////////////////////////////////////////////
+    inline int Main
+    (
+        Config& config
+    )
+    {        
         // Handle list request
         if( config.listWhat() != Config::List::None )
             return List( config );
@@ -107,6 +81,57 @@ namespace Catch
         return static_cast<int>( runner.getFailureCount() );
     }
     
+    //////////////////////////////////////////////////////////////////////////
+    inline int Main
+    (
+        int argc, 
+        char* const argv[],
+        Config& config
+    )
+    {
+        ArgParser( argc, argv, config );
+        
+        if( !config.getMessage().empty() )
+        {
+            std::cerr << config.getMessage() << std::endl;
+            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>|<%stream 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;
+        }
+        
+        return Main( config );
+    }
+    
+    //////////////////////////////////////////////////////////////////////////
+    inline int Main
+    (
+        int argc, 
+        char* const argv[]
+    )
+    {
+        Config config;
+        return Main( argc, argv, config );
+    }
+    
 } // end namespace Catch
 
 #endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED