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

Improved error handling for --abort as per #108

Commit
b084562b3bd213da3cd9e422a2343073d8e34d11
Author
Phil Nash ·
Parents
6f220863cf7d

Files · Download .tar.gz

Changes

 include/internal/catch_commandline.hpp |  4 +++-
 projects/SelfTest/TestMain.cpp         | 11 ++++++++++-
 single_include/catch.hpp               |  4 +++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index 49928f4c..d25e33e2 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -153,7 +153,7 @@ namespace Catch {
                 cmd.raiseError( "Expected a name" );
             config.name = cmd[0];
         }
-        
+
         if( Command cmd = parser.find( "-a", "--abort" ) ) {
             if( cmd.argsCount() > 1 )
                 cmd.raiseError( "Only accepts 0-1 arguments" );
@@ -162,6 +162,8 @@ namespace Catch {
                 std::stringstream ss;
                 ss << cmd[0];
                 ss >> threshold;
+                if( ss.fail() || threshold <= 0 )
+                    cmd.raiseError( "threshold must be a number greater than zero" );
             }
             config.cutoff = threshold;
         }
diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp
index 599edf4f..15616ee3 100644
--- a/projects/SelfTest/TestMain.cpp
+++ b/projects/SelfTest/TestMain.cpp
@@ -68,6 +68,7 @@ template<size_t size>
 std::string parseIntoConfigAndReturnError( const char * (&argv)[size], Catch::ConfigData& config ) {
     try {
         Catch::parseIntoConfig( Catch::CommandParser( size, argv ), config );
+        FAIL( "expected exception" );
     }
     catch( std::exception& ex ) {
         return ex.what();
@@ -179,7 +180,15 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
 
             REQUIRE( config.cutoff == 2 );
         }
-        SECTION( "-a/error", "cutoff only takes one argument" ) {
+        SECTION( "-a/error/0", "" ) {
+            const char* argv[] = { "test", "-a", "0" };
+            REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "greater than zero" ) );
+        }
+        SECTION( "-a/error/non numeric", "" ) {
+            const char* argv[] = { "test", "-a", "oops" };
+            REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "greater than zero" ) );
+        }
+        SECTION( "-a/error/two args", "cutoff only takes one argument" ) {
             const char* argv[] = { "test", "-a", "1", "2" };
             REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "accepts" ) );
         }
diff --git a/single_include/catch.hpp b/single_include/catch.hpp
index c2cb354a..69a58735 100644
--- a/single_include/catch.hpp
+++ b/single_include/catch.hpp
@@ -1,5 +1,5 @@
 /*
- *  Generated: 2012-07-23 08:24:23.434402
+ *  Generated: 2012-07-28 20:22:25.519628
  *  ----------------------------------------------------------
  *  This file has been merged from multiple headers. Please don't edit it directly
  *  Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@@ -3650,6 +3650,8 @@ namespace Catch {
                 std::stringstream ss;
                 ss << cmd[0];
                 ss >> threshold;
+                if( ss.fail() || threshold <= 0 )
+                    cmd.raiseError( "threshold must be a number greater than zero" );
             }
             config.cutoff = threshold;
         }