mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 21:05:39 +02:00
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.
This commit is contained in:
@@ -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]"'
|
||||
|
@@ -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]"'
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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"/>
|
||||
|
@@ -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"/>
|
||||
|
@@ -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]" ) {
|
||||
|
Reference in New Issue
Block a user