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

Don’t assume first CL arg (exe name) is present

Fixes #729
Commit
38b05f140003811f15345ec498b15b0e882e562e
Author
Phil Nash ·
Parents
db9866677ebe

Files · Download .tar.gz

Changes

 include/external/clara.h                           |  2 +-
 .../SelfTest/Baselines/console.std.approved.txt    |  2 +-
 .../SelfTest/Baselines/console.sw.approved.txt     | 25 +++++++++++++++-
 projects/SelfTest/Baselines/junit.sw.approved.txt  |  3 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 33 ++++++++++++++++++++--
 projects/SelfTest/TestMain.cpp                     |  8 ++++++
 6 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/include/external/clara.h b/include/external/clara.h
index 4200d58f..bf758eb5 100644
--- a/include/external/clara.h
+++ b/include/external/clara.h
@@ -927,7 +927,7 @@ namespace Clara {
         }
 
         std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const {
-            std::string processName = args[0];
+            std::string processName = args.empty() ? std::string() : args[0];
             std::size_t lastSlash = processName.find_last_of( "/\\" );
             if( lastSlash != std::string::npos )
                 processName = processName.substr( lastSlash+1 );
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index ef6948d2..a7d9e2a3 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -916,5 +916,5 @@ with expansion:
 
 ===============================================================================
 test cases: 166 | 119 passed | 44 failed |  3 failed as expected
-assertions: 958 | 852 passed | 87 failed | 19 failed as expected
+assertions: 961 | 855 passed | 87 failed | 19 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index 7558e0c3..b8b3cb47 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -5871,6 +5871,23 @@ MessageTests.cpp:<line number>:
 warning:
   toString(p): 0x<hex digits>
 
+-------------------------------------------------------------------------------
+Process can be configured on command line
+  empty args don't cause a crash
+-------------------------------------------------------------------------------
+TestMain.cpp:<line number>
+...............................................................................
+
+TestMain.cpp:<line number>:
+PASSED:
+  CHECK_NOTHROW( parser.parseInto( std::vector<std::string>(), config ) )
+
+TestMain.cpp:<line number>:
+PASSED:
+  CHECK( config.processName == "" )
+with expansion:
+  "" == ""
+
 -------------------------------------------------------------------------------
 Process can be configured on command line
   default - no arguments
@@ -5882,6 +5899,12 @@ TestMain.cpp:<line number>:
 PASSED:
   CHECK_NOTHROW( parseIntoConfig( argv, config ) )
 
+TestMain.cpp:<line number>:
+PASSED:
+  CHECK( config.processName == "test" )
+with expansion:
+  "test" == "test"
+
 TestMain.cpp:<line number>:
 PASSED:
   CHECK( config.shouldDebugBreak == false )
@@ -9382,5 +9405,5 @@ PASSED:
 
 ===============================================================================
 test cases: 166 | 118 passed | 45 failed |  3 failed as expected
-assertions: 960 | 852 passed | 89 failed | 19 failed as expected
+assertions: 963 | 855 passed | 89 failed | 19 failed as expected
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index 44a6e56a..bb088e50 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuitesspanner>
-  <testsuite name="<exe-name>" errors="13" failures="77" tests="961" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="13" failures="77" tests="964" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
     <testcase classname="global" name="#542" time="{duration}"/>
     <testcase classname="global" name="#809" time="{duration}"/>
@@ -400,6 +400,7 @@ MessageTests.cpp:<line number>
     <testcase classname="global" name="Parsing a std::pair" time="{duration}"/>
     <testcase classname="global" name="Pointers can be compared to null" time="{duration}"/>
     <testcase classname="global" name="Pointers can be converted to strings" time="{duration}"/>
+    <testcase classname="Process can be configured on command line" name="empty args don't cause a crash" time="{duration}"/>
     <testcase classname="Process can be configured on command line" name="default - no arguments" time="{duration}"/>
     <testcase classname="Process can be configured on command line" name="test lists/1 test" time="{duration}"/>
     <testcase classname="Process can be configured on command line" name="test lists/Specify one test case exclusion using exclude:" time="{duration}"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index 5db8eff2..e7f3c4bb 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -6215,6 +6215,25 @@ re>"
       <OverallResult success="true"/>
     </TestCase>
     <TestCase name="Process can be configured on command line" tags="[command-line][config]" filename="projects/<exe-name>/TestMain.cpp" >
+      <Section name="empty args don't cause a crash" filename="projects/<exe-name>/TestMain.cpp" >
+        <Expression success="true" type="CHECK_NOTHROW" filename="projects/<exe-name>/TestMain.cpp" >
+          <Original>
+            parser.parseInto( std::vector&lt;std::string>(), config )
+          </Original>
+          <Expanded>
+            parser.parseInto( std::vector&lt;std::string>(), config )
+          </Expanded>
+        </Expression>
+        <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
+          <Original>
+            config.processName == ""
+          </Original>
+          <Expanded>
+            "" == ""
+          </Expanded>
+        </Expression>
+        <OverallResults successes="2" failures="0" expectedFailures="0"/>
+      </Section>
       <Section name="default - no arguments" filename="projects/<exe-name>/TestMain.cpp" >
         <Expression success="true" type="CHECK_NOTHROW" filename="projects/<exe-name>/TestMain.cpp" >
           <Original>
@@ -6224,6 +6243,14 @@ re>"
             parseIntoConfig( argv, config )
           </Expanded>
         </Expression>
+        <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
+          <Original>
+            config.processName == "test"
+          </Original>
+          <Expanded>
+            "test" == "test"
+          </Expanded>
+        </Expression>
         <Expression success="true" type="CHECK" filename="projects/<exe-name>/TestMain.cpp" >
           <Original>
             config.shouldDebugBreak == false
@@ -6256,7 +6283,7 @@ re>"
             true
           </Expanded>
         </Expression>
-        <OverallResults successes="5" failures="0" expectedFailures="0"/>
+        <OverallResults successes="6" failures="0" expectedFailures="0"/>
       </Section>
       <Section name="test lists" filename="projects/<exe-name>/TestMain.cpp" >
         <Section name="1 test" description="Specify one test case using" filename="projects/<exe-name>/TestMain.cpp" >
@@ -10016,7 +10043,7 @@ spanner      <OverallResult success="true"/>
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="852" failures="90" expectedFailures="19"/>
+    <OverallResults successes="855" failures="90" expectedFailures="19"/>
   </Group>
-  <OverallResults successes="852" failures="89" expectedFailures="19"/>
+  <OverallResults successes="855" failures="89" expectedFailures="19"/>
 </Catch>
diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp
index e00966a8..e03a9e44 100644
--- a/projects/SelfTest/TestMain.cpp
+++ b/projects/SelfTest/TestMain.cpp
@@ -51,10 +51,18 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
 
     Catch::ConfigData config;
 
+    SECTION( "empty args don't cause a crash" ) {
+        Catch::Clara::CommandLine<Catch::ConfigData> parser = Catch::makeCommandLineParser();
+        CHECK_NOTHROW( parser.parseInto( std::vector<std::string>(), config ) );
+
+        CHECK( config.processName == "" );
+    }
+
     SECTION( "default - no arguments", "" ) {
         const char* argv[] = { "test" };
         CHECK_NOTHROW( parseIntoConfig( argv, config ) );
 
+        CHECK( config.processName == "test" );
         CHECK( config.shouldDebugBreak == false );
         CHECK( config.abortAfter == -1 );
         CHECK( config.noThrow == false );