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 parseInto( std::vector 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:: warning: toString(p): 0x +------------------------------------------------------------------------------- +Process can be configured on command line + empty args don't cause a crash +------------------------------------------------------------------------------- +TestMain.cpp: +............................................................................... + +TestMain.cpp:: +PASSED: + CHECK_NOTHROW( parser.parseInto( std::vector(), config ) ) + +TestMain.cpp:: +PASSED: + CHECK( config.processName == "" ) +with expansion: + "" == "" + ------------------------------------------------------------------------------- Process can be configured on command line default - no arguments @@ -5882,6 +5899,12 @@ TestMain.cpp:: PASSED: CHECK_NOTHROW( parseIntoConfig( argv, config ) ) +TestMain.cpp:: +PASSED: + CHECK( config.processName == "test" ) +with expansion: + "test" == "test" + TestMain.cpp:: 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 @@ - + @@ -400,6 +400,7 @@ MessageTests.cpp: + 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>" +
+ + + parser.parseInto( std::vector<std::string>(), config ) + + + parser.parseInto( std::vector<std::string>(), config ) + + + + + config.processName == "" + + + "" == "" + + + +
@@ -6224,6 +6243,14 @@ re>" parseIntoConfig( argv, config ) + + + config.processName == "test" + + + "test" == "test" + + config.shouldDebugBreak == false @@ -6256,7 +6283,7 @@ re>" true - +
@@ -10016,7 +10043,7 @@ spanner
- + - + 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 parser = Catch::makeCommandLineParser(); + CHECK_NOTHROW( parser.parseInto( std::vector(), 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 );