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

Refactor parsing of shard index/count in cmdline handling

This worsens the message for negative numbers a bit, but
simplifies the code enough that this is still a win.
Commit
a43f67962e632d9596680a7e139df9e0a1423d3a
Author
Martin Hořeňovský ·
Parents
f1361ef6243e

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_commandline.cpp          | 46 ++++++++--------------
 tests/SelfTest/Baselines/compact.sw.approved.txt   |  6 +--
 .../Baselines/compact.sw.multi.approved.txt        |  6 +--
 tests/SelfTest/Baselines/console.sw.approved.txt   | 17 ++++----
 .../Baselines/console.sw.multi.approved.txt        | 17 ++++----
 tests/SelfTest/Baselines/tap.sw.approved.txt       |  6 +--
 tests/SelfTest/Baselines/tap.sw.multi.approved.txt |  6 +--
 tests/SelfTest/Baselines/xml.sw.approved.txt       | 12 +++---
 tests/SelfTest/Baselines/xml.sw.multi.approved.txt | 12 +++---
 .../SelfTest/IntrospectiveTests/CmdLine.tests.cpp  | 13 ++++--
 10 files changed, 65 insertions(+), 76 deletions(-)

diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp
index 20bb07f7..b6b812ec 100644
--- a/src/catch2/internal/catch_commandline.cpp
+++ b/src/catch2/internal/catch_commandline.cpp
@@ -7,7 +7,6 @@
 // SPDX-License-Identifier: BSL-1.0
 #include <catch2/internal/catch_commandline.hpp>
 
-#include <catch2/internal/catch_compiler_capabilities.hpp>
 #include <catch2/catch_config.hpp>
 #include <catch2/internal/catch_string_manip.hpp>
 #include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
@@ -177,42 +176,29 @@ namespace Catch {
             return ParserResult::ok( ParseResultType::Matched );
         };
         auto const setShardCount = [&]( std::string const& shardCount ) {
-            CATCH_TRY{
-                std::size_t parsedTo = 0;
-                int64_t parsedCount = std::stoll(shardCount, &parsedTo, 0);
-                if (parsedTo != shardCount.size()) {
-                    return ParserResult::runtimeError("Could not parse '" + shardCount + "' as shard count");
-                }
-                if (parsedCount <= 0) {
-                    return ParserResult::runtimeError("Shard count must be a positive number");
-                }
-
-                config.shardCount = static_cast<unsigned int>(parsedCount);
-                return ParserResult::ok(ParseResultType::Matched);
-            } CATCH_CATCH_ANON(std::exception const&) {
-                return ParserResult::runtimeError("Could not parse '" + shardCount + "' as shard count");
+            auto parsedCount = parseUInt( shardCount );
+            if ( !parsedCount ) {
+                return ParserResult::runtimeError(
+                    "Could not parse '" + shardCount + "' as shard count" );
             }
+            if ( *parsedCount == 0 ) {
+                return ParserResult::runtimeError(
+                    "Shard count must be positive" );
+            }
+            config.shardCount = *parsedCount;
+            return ParserResult::ok( ParseResultType::Matched );
         };
 
         auto const setShardIndex = [&](std::string const& shardIndex) {
-            CATCH_TRY{
-                std::size_t parsedTo = 0;
-                int64_t parsedIndex = std::stoll(shardIndex, &parsedTo, 0);
-                if (parsedTo != shardIndex.size()) {
-                    return ParserResult::runtimeError("Could not parse '" + shardIndex + "' as shard index");
-                }
-                if (parsedIndex < 0) {
-                    return ParserResult::runtimeError("Shard index must be a non-negative number");
-                }
-
-                config.shardIndex = static_cast<unsigned int>(parsedIndex);
-                return ParserResult::ok(ParseResultType::Matched);
-            } CATCH_CATCH_ANON(std::exception const&) {
-                return ParserResult::runtimeError("Could not parse '" + shardIndex + "' as shard index");
+            auto parsedIndex = parseUInt( shardIndex );
+            if ( !parsedIndex ) {
+                return ParserResult::runtimeError(
+                    "Could not parse '" + shardIndex + "' as shard index" );
             }
+            config.shardIndex = *parsedIndex;
+            return ParserResult::ok( ParseResultType::Matched );
         };
 
-
         auto cli
             = ExeName( config.processName )
             | Help( config.showHelp )
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index 768562ad..0a023565 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -1287,13 +1287,13 @@ TestSpecParser.tests.cpp:<line number>: passed: spec.matches( testCase ) for: tr
 CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--shard-count=8" }) for: {?}
 CmdLine.tests.cpp:<line number>: passed: config.shardCount == 8 for: 8 == 8
 CmdLine.tests.cpp:<line number>: passed: !(result) for: !{?}
-CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring("Shard count must be a positive number") for: "Shard count must be a positive number" contains: "Shard count must be a positive number"
+CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "Could not parse '-1' as shard count" ) for: "Could not parse '-1' as shard count" contains: "Could not parse '-1' as shard count"
 CmdLine.tests.cpp:<line number>: passed: !(result) for: !{?}
-CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring("Shard count must be a positive number") for: "Shard count must be a positive number" contains: "Shard count must be a positive number"
+CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "Shard count must be positive" ) for: "Shard count must be positive" contains: "Shard count must be positive"
 CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--shard-index=2" }) for: {?}
 CmdLine.tests.cpp:<line number>: passed: config.shardIndex == 2 for: 2 == 2
 CmdLine.tests.cpp:<line number>: passed: !(result) for: !{?}
-CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number") for: "Shard index must be a non-negative number" contains: "Shard index must be a non-negative number"
+CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "Could not parse '-12' as shard index" ) for: "Could not parse '-12' as shard index" contains: "Could not parse '-12' as shard index"
 CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--shard-index=0" }) for: {?}
 CmdLine.tests.cpp:<line number>: passed: config.shardIndex == 0 for: 0 == 0
 TestSpecParser.tests.cpp:<line number>: passed: spec.hasFilters() for: true with 1 message: 'tagString := "[tag with spaces]"'
diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
index d8d04130..20d14da1 100644
--- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
@@ -1285,13 +1285,13 @@ TestSpecParser.tests.cpp:<line number>: passed: spec.matches( testCase ) for: tr
 CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--shard-count=8" }) for: {?}
 CmdLine.tests.cpp:<line number>: passed: config.shardCount == 8 for: 8 == 8
 CmdLine.tests.cpp:<line number>: passed: !(result) for: !{?}
-CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring("Shard count must be a positive number") for: "Shard count must be a positive number" contains: "Shard count must be a positive number"
+CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "Could not parse '-1' as shard count" ) for: "Could not parse '-1' as shard count" contains: "Could not parse '-1' as shard count"
 CmdLine.tests.cpp:<line number>: passed: !(result) for: !{?}
-CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring("Shard count must be a positive number") for: "Shard count must be a positive number" contains: "Shard count must be a positive number"
+CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "Shard count must be positive" ) for: "Shard count must be positive" contains: "Shard count must be positive"
 CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--shard-index=2" }) for: {?}
 CmdLine.tests.cpp:<line number>: passed: config.shardIndex == 2 for: 2 == 2
 CmdLine.tests.cpp:<line number>: passed: !(result) for: !{?}
-CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number") for: "Shard index must be a non-negative number" contains: "Shard index must be a non-negative number"
+CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "Could not parse '-12' as shard index" ) for: "Could not parse '-12' as shard index" contains: "Could not parse '-12' as shard index"
 CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--shard-index=0" }) for: {?}
 CmdLine.tests.cpp:<line number>: passed: config.shardIndex == 0 for: 0 == 0
 TestSpecParser.tests.cpp:<line number>: passed: spec.hasFilters() for: true with 1 message: 'tagString := "[tag with spaces]"'
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index 8bd2dc0c..929c746d 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -9175,10 +9175,10 @@ with expansion:
   !{?}
 
 CmdLine.tests.cpp:<line number>: PASSED:
-  REQUIRE_THAT( result.errorMessage(), ContainsSubstring("Shard count must be a positive number") )
+  REQUIRE_THAT( result.errorMessage(), ContainsSubstring( "Could not parse '-1' as shard count" ) )
 with expansion:
-  "Shard count must be a positive number" contains: "Shard count must be a
-  positive number"
+  "Could not parse '-1' as shard count" contains: "Could not parse '-1' as
+  shard count"
 
 -------------------------------------------------------------------------------
 Parsing sharding-related cli flags
@@ -9193,10 +9193,9 @@ with expansion:
   !{?}
 
 CmdLine.tests.cpp:<line number>: PASSED:
-  REQUIRE_THAT( result.errorMessage(), ContainsSubstring("Shard count must be a positive number") )
+  REQUIRE_THAT( result.errorMessage(), ContainsSubstring( "Shard count must be positive" ) )
 with expansion:
-  "Shard count must be a positive number" contains: "Shard count must be a
-  positive number"
+  "Shard count must be positive" contains: "Shard count must be positive"
 
 -------------------------------------------------------------------------------
 Parsing sharding-related cli flags
@@ -9228,10 +9227,10 @@ with expansion:
   !{?}
 
 CmdLine.tests.cpp:<line number>: PASSED:
-  REQUIRE_THAT( result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number") )
+  REQUIRE_THAT( result.errorMessage(), ContainsSubstring( "Could not parse '-12' as shard index" ) )
 with expansion:
-  "Shard index must be a non-negative number" contains: "Shard index must be a
-  non-negative number"
+  "Could not parse '-12' as shard index" contains: "Could not parse '-12' as
+  shard index"
 
 -------------------------------------------------------------------------------
 Parsing sharding-related cli flags
diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt
index 0f565560..685f57e7 100644
--- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt
@@ -9173,10 +9173,10 @@ with expansion:
   !{?}
 
 CmdLine.tests.cpp:<line number>: PASSED:
-  REQUIRE_THAT( result.errorMessage(), ContainsSubstring("Shard count must be a positive number") )
+  REQUIRE_THAT( result.errorMessage(), ContainsSubstring( "Could not parse '-1' as shard count" ) )
 with expansion:
-  "Shard count must be a positive number" contains: "Shard count must be a
-  positive number"
+  "Could not parse '-1' as shard count" contains: "Could not parse '-1' as
+  shard count"
 
 -------------------------------------------------------------------------------
 Parsing sharding-related cli flags
@@ -9191,10 +9191,9 @@ with expansion:
   !{?}
 
 CmdLine.tests.cpp:<line number>: PASSED:
-  REQUIRE_THAT( result.errorMessage(), ContainsSubstring("Shard count must be a positive number") )
+  REQUIRE_THAT( result.errorMessage(), ContainsSubstring( "Shard count must be positive" ) )
 with expansion:
-  "Shard count must be a positive number" contains: "Shard count must be a
-  positive number"
+  "Shard count must be positive" contains: "Shard count must be positive"
 
 -------------------------------------------------------------------------------
 Parsing sharding-related cli flags
@@ -9226,10 +9225,10 @@ with expansion:
   !{?}
 
 CmdLine.tests.cpp:<line number>: PASSED:
-  REQUIRE_THAT( result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number") )
+  REQUIRE_THAT( result.errorMessage(), ContainsSubstring( "Could not parse '-12' as shard index" ) )
 with expansion:
-  "Shard index must be a non-negative number" contains: "Shard index must be a
-  non-negative number"
+  "Could not parse '-12' as shard index" contains: "Could not parse '-12' as
+  shard index"
 
 -------------------------------------------------------------------------------
 Parsing sharding-related cli flags
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index cae94b24..53f1c437 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -2418,11 +2418,11 @@ ok {test-number} - config.shardCount == 8 for: 8 == 8
 # Parsing sharding-related cli flags
 ok {test-number} - !(result) for: !{?}
 # Parsing sharding-related cli flags
-ok {test-number} - result.errorMessage(), ContainsSubstring("Shard count must be a positive number") for: "Shard count must be a positive number" contains: "Shard count must be a positive number"
+ok {test-number} - result.errorMessage(), ContainsSubstring( "Could not parse '-1' as shard count" ) for: "Could not parse '-1' as shard count" contains: "Could not parse '-1' as shard count"
 # Parsing sharding-related cli flags
 ok {test-number} - !(result) for: !{?}
 # Parsing sharding-related cli flags
-ok {test-number} - result.errorMessage(), ContainsSubstring("Shard count must be a positive number") for: "Shard count must be a positive number" contains: "Shard count must be a positive number"
+ok {test-number} - result.errorMessage(), ContainsSubstring( "Shard count must be positive" ) for: "Shard count must be positive" contains: "Shard count must be positive"
 # Parsing sharding-related cli flags
 ok {test-number} - cli.parse({ "test", "--shard-index=2" }) for: {?}
 # Parsing sharding-related cli flags
@@ -2430,7 +2430,7 @@ ok {test-number} - config.shardIndex == 2 for: 2 == 2
 # Parsing sharding-related cli flags
 ok {test-number} - !(result) for: !{?}
 # Parsing sharding-related cli flags
-ok {test-number} - result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number") for: "Shard index must be a non-negative number" contains: "Shard index must be a non-negative number"
+ok {test-number} - result.errorMessage(), ContainsSubstring( "Could not parse '-12' as shard index" ) for: "Could not parse '-12' as shard index" contains: "Could not parse '-12' as shard index"
 # Parsing sharding-related cli flags
 ok {test-number} - cli.parse({ "test", "--shard-index=0" }) for: {?}
 # Parsing sharding-related cli flags
diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
index 15942bb6..303ba842 100644
--- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
@@ -2416,11 +2416,11 @@ ok {test-number} - config.shardCount == 8 for: 8 == 8
 # Parsing sharding-related cli flags
 ok {test-number} - !(result) for: !{?}
 # Parsing sharding-related cli flags
-ok {test-number} - result.errorMessage(), ContainsSubstring("Shard count must be a positive number") for: "Shard count must be a positive number" contains: "Shard count must be a positive number"
+ok {test-number} - result.errorMessage(), ContainsSubstring( "Could not parse '-1' as shard count" ) for: "Could not parse '-1' as shard count" contains: "Could not parse '-1' as shard count"
 # Parsing sharding-related cli flags
 ok {test-number} - !(result) for: !{?}
 # Parsing sharding-related cli flags
-ok {test-number} - result.errorMessage(), ContainsSubstring("Shard count must be a positive number") for: "Shard count must be a positive number" contains: "Shard count must be a positive number"
+ok {test-number} - result.errorMessage(), ContainsSubstring( "Shard count must be positive" ) for: "Shard count must be positive" contains: "Shard count must be positive"
 # Parsing sharding-related cli flags
 ok {test-number} - cli.parse({ "test", "--shard-index=2" }) for: {?}
 # Parsing sharding-related cli flags
@@ -2428,7 +2428,7 @@ ok {test-number} - config.shardIndex == 2 for: 2 == 2
 # Parsing sharding-related cli flags
 ok {test-number} - !(result) for: !{?}
 # Parsing sharding-related cli flags
-ok {test-number} - result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number") for: "Shard index must be a non-negative number" contains: "Shard index must be a non-negative number"
+ok {test-number} - result.errorMessage(), ContainsSubstring( "Could not parse '-12' as shard index" ) for: "Could not parse '-12' as shard index" contains: "Could not parse '-12' as shard index"
 # Parsing sharding-related cli flags
 ok {test-number} - cli.parse({ "test", "--shard-index=0" }) for: {?}
 # Parsing sharding-related cli flags
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index 4358597c..acaee5b3 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -11160,10 +11160,10 @@ C
       </Expression>
       <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
         <Original>
-          result.errorMessage(), ContainsSubstring("Shard count must be a positive number")
+          result.errorMessage(), ContainsSubstring( "Could not parse '-1' as shard count" )
         </Original>
         <Expanded>
-          "Shard count must be a positive number" contains: "Shard count must be a positive number"
+          "Could not parse '-1' as shard count" contains: "Could not parse '-1' as shard count"
         </Expanded>
       </Expression>
       <OverallResults successes="2" failures="0" expectedFailures="0"/>
@@ -11179,10 +11179,10 @@ C
       </Expression>
       <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
         <Original>
-          result.errorMessage(), ContainsSubstring("Shard count must be a positive number")
+          result.errorMessage(), ContainsSubstring( "Shard count must be positive" )
         </Original>
         <Expanded>
-          "Shard count must be a positive number" contains: "Shard count must be a positive number"
+          "Shard count must be positive" contains: "Shard count must be positive"
         </Expanded>
       </Expression>
       <OverallResults successes="2" failures="0" expectedFailures="0"/>
@@ -11217,10 +11217,10 @@ C
       </Expression>
       <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
         <Original>
-          result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number")
+          result.errorMessage(), ContainsSubstring( "Could not parse '-12' as shard index" )
         </Original>
         <Expanded>
-          "Shard index must be a non-negative number" contains: "Shard index must be a non-negative number"
+          "Could not parse '-12' as shard index" contains: "Could not parse '-12' as shard index"
         </Expanded>
       </Expression>
       <OverallResults successes="2" failures="0" expectedFailures="0"/>
diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
index 9af9db43..75b38706 100644
--- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
@@ -11160,10 +11160,10 @@ C
       </Expression>
       <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
         <Original>
-          result.errorMessage(), ContainsSubstring("Shard count must be a positive number")
+          result.errorMessage(), ContainsSubstring( "Could not parse '-1' as shard count" )
         </Original>
         <Expanded>
-          "Shard count must be a positive number" contains: "Shard count must be a positive number"
+          "Could not parse '-1' as shard count" contains: "Could not parse '-1' as shard count"
         </Expanded>
       </Expression>
       <OverallResults successes="2" failures="0" expectedFailures="0"/>
@@ -11179,10 +11179,10 @@ C
       </Expression>
       <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
         <Original>
-          result.errorMessage(), ContainsSubstring("Shard count must be a positive number")
+          result.errorMessage(), ContainsSubstring( "Shard count must be positive" )
         </Original>
         <Expanded>
-          "Shard count must be a positive number" contains: "Shard count must be a positive number"
+          "Shard count must be positive" contains: "Shard count must be positive"
         </Expanded>
       </Expression>
       <OverallResults successes="2" failures="0" expectedFailures="0"/>
@@ -11217,10 +11217,10 @@ C
       </Expression>
       <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
         <Original>
-          result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number")
+          result.errorMessage(), ContainsSubstring( "Could not parse '-12' as shard index" )
         </Original>
         <Expanded>
-          "Shard index must be a non-negative number" contains: "Shard index must be a non-negative number"
+          "Could not parse '-12' as shard index" contains: "Could not parse '-12' as shard index"
         </Expanded>
       </Expression>
       <OverallResults successes="2" failures="0" expectedFailures="0"/>
diff --git a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
index cbb0a988..abb873f2 100644
--- a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
@@ -649,14 +649,18 @@ TEST_CASE("Parsing sharding-related cli flags", "[sharding]") {
         auto result = cli.parse({ "test", "--shard-count=-1" });
 
         CHECK_FALSE(result);
-        REQUIRE_THAT(result.errorMessage(), ContainsSubstring("Shard count must be a positive number"));
+        REQUIRE_THAT(
+            result.errorMessage(),
+            ContainsSubstring( "Could not parse '-1' as shard count" ) );
     }
 
     SECTION("Zero shard count reports error") {
         auto result = cli.parse({ "test", "--shard-count=0" });
 
         CHECK_FALSE(result);
-        REQUIRE_THAT(result.errorMessage(), ContainsSubstring("Shard count must be a positive number"));
+        REQUIRE_THAT(
+            result.errorMessage(),
+            ContainsSubstring( "Shard count must be positive" ) );
     }
 
     SECTION("shard-index") {
@@ -669,7 +673,9 @@ TEST_CASE("Parsing sharding-related cli flags", "[sharding]") {
         auto result = cli.parse({ "test", "--shard-index=-12" });
 
         CHECK_FALSE(result);
-        REQUIRE_THAT(result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number"));
+        REQUIRE_THAT(
+            result.errorMessage(),
+            ContainsSubstring( "Could not parse '-12' as shard index" ) );
     }
 
     SECTION("Shard index 0 is accepted") {
@@ -677,7 +683,6 @@ TEST_CASE("Parsing sharding-related cli flags", "[sharding]") {
 
         REQUIRE(config.shardIndex == 0);
     }
-
 }
 
 TEST_CASE( "Parsing warnings", "[cli][warnings]" ) {