Cleanup ColourMode parsing in CLI

This commit is contained in:
Martin Hořeňovský 2022-04-04 15:38:25 +02:00
parent d750da13a8
commit 8ac86495de
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
9 changed files with 19 additions and 38 deletions

View File

@ -14,6 +14,7 @@
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp> #include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
#include <catch2/interfaces/catch_interfaces_reporter.hpp> #include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/internal/catch_console_colour.hpp> #include <catch2/internal/catch_console_colour.hpp>
#include <catch2/internal/catch_reporter_spec_parser.hpp>
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
@ -98,40 +99,20 @@ namespace Catch {
}; };
auto const setColourMode = [&]( std::string const& auto const setColourMode = [&]( std::string const&
colourMode ) { colourMode ) {
auto mode = toLower( colourMode ); Optional<ColourMode> maybeMode = Catch::Detail::stringToColourMode(toLower( colourMode ));
if ( !maybeMode ) {
if ( mode == "default" ) {
if ( !isColourImplAvailable( ColourMode::PlatformDefault ) ) {
return ParserResult::runtimeError(
"colour mode 'default' is not supported in this "
"binary" );
}
config.colourMode = ColourMode::PlatformDefault;
} else if ( mode == "ansi" ) {
if ( !isColourImplAvailable( ColourMode::ANSI ) ) {
return ParserResult::runtimeError(
"colour mode 'ansi' is not supported in this binary" );
}
config.colourMode = ColourMode::ANSI;
} else if ( mode == "win32" ) {
if ( !isColourImplAvailable( ColourMode::Win32 ) ) {
return ParserResult::runtimeError(
"colour mode 'win32' is not supported in this "
"binary" );
}
config.colourMode = ColourMode::Win32;
} else if ( mode == "none" ) {
if ( !isColourImplAvailable( ColourMode::None ) ) {
return ParserResult::runtimeError(
"colour mode 'none' is not supported in this binary" );
}
config.colourMode = ColourMode::None;
} else {
return ParserResult::runtimeError( return ParserResult::runtimeError(
"colour mode must be one of: default, ansi, win32, " "colour mode must be one of: default, ansi, win32, "
"or none. '" + "or none. '" +
colourMode + "' not recognised" ); colourMode + "' is not recognised" );
} }
auto mode = *maybeMode;
if ( !isColourImplAvailable( mode ) ) {
return ParserResult::runtimeError(
"colour mode '" + colourMode +
"' is not supported in this binary" );
}
config.colourMode = mode;
return ParserResult::ok( ParseResultType::Matched ); return ParserResult::ok( ParseResultType::Matched );
}; };
auto const setWaitForKeypress = [&]( std::string const& keypress ) { auto const setWaitForKeypress = [&]( std::string const& keypress ) {

View File

@ -1407,7 +1407,7 @@ CmdLine.tests.cpp:<line number>: passed: config.colourMode == ColourMode::ANSI f
CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "--colour-mode", "none"}) for: {?} CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "--colour-mode", "none"}) for: {?}
CmdLine.tests.cpp:<line number>: passed: config.colourMode == ColourMode::None for: 3 == 3 CmdLine.tests.cpp:<line number>: passed: config.colourMode == ColourMode::None for: 3 == 3
CmdLine.tests.cpp:<line number>: passed: !result for: true CmdLine.tests.cpp:<line number>: passed: !result for: true
CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) for: "colour mode must be one of: default, ansi, win32, or none. 'wrong' not recognised" contains: "colour mode must be one of" CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) for: "colour mode must be one of: default, ansi, win32, or none. 'wrong' is not recognised" contains: "colour mode must be one of"
CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-samples=200" }) for: {?} CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-samples=200" }) for: {?}
CmdLine.tests.cpp:<line number>: passed: config.benchmarkSamples == 200 for: 200 == 200 CmdLine.tests.cpp:<line number>: passed: config.benchmarkSamples == 200 for: 200 == 200
CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-resamples=20000" }) for: {?} CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-resamples=20000" }) for: {?}

View File

@ -1405,7 +1405,7 @@ CmdLine.tests.cpp:<line number>: passed: config.colourMode == ColourMode::ANSI f
CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "--colour-mode", "none"}) for: {?} CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "--colour-mode", "none"}) for: {?}
CmdLine.tests.cpp:<line number>: passed: config.colourMode == ColourMode::None for: 3 == 3 CmdLine.tests.cpp:<line number>: passed: config.colourMode == ColourMode::None for: 3 == 3
CmdLine.tests.cpp:<line number>: passed: !result for: true CmdLine.tests.cpp:<line number>: passed: !result for: true
CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) for: "colour mode must be one of: default, ansi, win32, or none. 'wrong' not recognised" contains: "colour mode must be one of" CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) for: "colour mode must be one of: default, ansi, win32, or none. 'wrong' is not recognised" contains: "colour mode must be one of"
CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-samples=200" }) for: {?} CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-samples=200" }) for: {?}
CmdLine.tests.cpp:<line number>: passed: config.benchmarkSamples == 200 for: 200 == 200 CmdLine.tests.cpp:<line number>: passed: config.benchmarkSamples == 200 for: 200 == 200
CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-resamples=20000" }) for: {?} CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-resamples=20000" }) for: {?}

View File

@ -10124,7 +10124,7 @@ with expansion:
CmdLine.tests.cpp:<line number>: PASSED: CmdLine.tests.cpp:<line number>: PASSED:
CHECK_THAT( result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) ) CHECK_THAT( result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) )
with expansion: with expansion:
"colour mode must be one of: default, ansi, win32, or none. 'wrong' not "colour mode must be one of: default, ansi, win32, or none. 'wrong' is not
recognised" contains: "colour mode must be one of" recognised" contains: "colour mode must be one of"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View File

@ -10122,7 +10122,7 @@ with expansion:
CmdLine.tests.cpp:<line number>: PASSED: CmdLine.tests.cpp:<line number>: PASSED:
CHECK_THAT( result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) ) CHECK_THAT( result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) )
with expansion: with expansion:
"colour mode must be one of: default, ansi, win32, or none. 'wrong' not "colour mode must be one of: default, ansi, win32, or none. 'wrong' is not
recognised" contains: "colour mode must be one of" recognised" contains: "colour mode must be one of"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View File

@ -2629,7 +2629,7 @@ ok {test-number} - config.colourMode == ColourMode::None for: 3 == 3
# Process can be configured on command line # Process can be configured on command line
ok {test-number} - !result for: true ok {test-number} - !result for: true
# Process can be configured on command line # Process can be configured on command line
ok {test-number} - result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) for: "colour mode must be one of: default, ansi, win32, or none. 'wrong' not recognised" contains: "colour mode must be one of" ok {test-number} - result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) for: "colour mode must be one of: default, ansi, win32, or none. 'wrong' is not recognised" contains: "colour mode must be one of"
# Process can be configured on command line # Process can be configured on command line
ok {test-number} - cli.parse({ "test", "--benchmark-samples=200" }) for: {?} ok {test-number} - cli.parse({ "test", "--benchmark-samples=200" }) for: {?}
# Process can be configured on command line # Process can be configured on command line

View File

@ -2627,7 +2627,7 @@ ok {test-number} - config.colourMode == ColourMode::None for: 3 == 3
# Process can be configured on command line # Process can be configured on command line
ok {test-number} - !result for: true ok {test-number} - !result for: true
# Process can be configured on command line # Process can be configured on command line
ok {test-number} - result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) for: "colour mode must be one of: default, ansi, win32, or none. 'wrong' not recognised" contains: "colour mode must be one of" ok {test-number} - result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) for: "colour mode must be one of: default, ansi, win32, or none. 'wrong' is not recognised" contains: "colour mode must be one of"
# Process can be configured on command line # Process can be configured on command line
ok {test-number} - cli.parse({ "test", "--benchmark-samples=200" }) for: {?} ok {test-number} - cli.parse({ "test", "--benchmark-samples=200" }) for: {?}
# Process can be configured on command line # Process can be configured on command line

View File

@ -12337,7 +12337,7 @@ C
result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) result.errorMessage(), ContainsSubstring( "colour mode must be one of" )
</Original> </Original>
<Expanded> <Expanded>
"colour mode must be one of: default, ansi, win32, or none. 'wrong' not recognised" contains: "colour mode must be one of" "colour mode must be one of: default, ansi, win32, or none. 'wrong' is not recognised" contains: "colour mode must be one of"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/> <OverallResults successes="2" failures="0" expectedFailures="0"/>

View File

@ -12337,7 +12337,7 @@ C
result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) result.errorMessage(), ContainsSubstring( "colour mode must be one of" )
</Original> </Original>
<Expanded> <Expanded>
"colour mode must be one of: default, ansi, win32, or none. 'wrong' not recognised" contains: "colour mode must be one of" "colour mode must be one of: default, ansi, win32, or none. 'wrong' is not recognised" contains: "colour mode must be one of"
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/> <OverallResults successes="2" failures="0" expectedFailures="0"/>