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

Cleanup ColourMode parsing in CLI

Commit
8ac86495de5bf249fd50775335f62eedb77815d6
Author
Martin Hořeňovský ·
Parents
d750da13a8ca

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_commandline.cpp          | 41 ++++++----------------
 tests/SelfTest/Baselines/compact.sw.approved.txt   |  2 +-
 .../Baselines/compact.sw.multi.approved.txt        |  2 +-
 tests/SelfTest/Baselines/console.sw.approved.txt   |  2 +-
 .../Baselines/console.sw.multi.approved.txt        |  2 +-
 tests/SelfTest/Baselines/tap.sw.approved.txt       |  2 +-
 tests/SelfTest/Baselines/tap.sw.multi.approved.txt |  2 +-
 tests/SelfTest/Baselines/xml.sw.approved.txt       |  2 +-
 tests/SelfTest/Baselines/xml.sw.multi.approved.txt |  2 +-
 9 files changed, 19 insertions(+), 38 deletions(-)

diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp
index 6363e47a..5095f1db 100644
--- a/src/catch2/internal/catch_commandline.cpp
+++ b/src/catch2/internal/catch_commandline.cpp
@@ -14,6 +14,7 @@
 #include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
 #include <catch2/interfaces/catch_interfaces_reporter.hpp>
 #include <catch2/internal/catch_console_colour.hpp>
+#include <catch2/internal/catch_reporter_spec_parser.hpp>
 
 #include <algorithm>
 #include <fstream>
@@ -98,40 +99,20 @@ namespace Catch {
             };
         auto const setColourMode = [&]( std::string const&
                                              colourMode ) {
-            auto mode = toLower( colourMode );
-
-            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 {
+            Optional<ColourMode> maybeMode = Catch::Detail::stringToColourMode(toLower( colourMode ));
+            if ( !maybeMode ) {
                 return ParserResult::runtimeError(
                     "colour mode must be one of: default, ansi, win32, "
                     "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 );
         };
         auto const setWaitForKeypress = [&]( std::string const& keypress ) {
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index f8c74732..e2ac5551 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -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: config.colourMode == ColourMode::None for: 3 == 3
 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: config.benchmarkSamples == 200 for: 200 == 200
 CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-resamples=20000" }) for: {?}
diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
index b9bfabd0..b46512ed 100644
--- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt
@@ -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: config.colourMode == ColourMode::None for: 3 == 3
 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: config.benchmarkSamples == 200 for: 200 == 200
 CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--benchmark-resamples=20000" }) for: {?}
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index d3476456..3091da60 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -10124,7 +10124,7 @@ with expansion:
 CmdLine.tests.cpp:<line number>: PASSED:
   CHECK_THAT( result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) )
 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"
 
 -------------------------------------------------------------------------------
diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt
index 3cfef5e2..3847cfc9 100644
--- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt
@@ -10122,7 +10122,7 @@ with expansion:
 CmdLine.tests.cpp:<line number>: PASSED:
   CHECK_THAT( result.errorMessage(), ContainsSubstring( "colour mode must be one of" ) )
 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"
 
 -------------------------------------------------------------------------------
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index d7d9a9cf..1cb2209b 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -2629,7 +2629,7 @@ ok {test-number} - config.colourMode == ColourMode::None for: 3 == 3
 # Process can be configured on command line
 ok {test-number} - !result for: true
 # 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
 ok {test-number} - cli.parse({ "test", "--benchmark-samples=200" }) for: {?}
 # Process can be configured on command line
diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
index cf36b3d9..f3e52353 100644
--- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt
@@ -2627,7 +2627,7 @@ ok {test-number} - config.colourMode == ColourMode::None for: 3 == 3
 # Process can be configured on command line
 ok {test-number} - !result for: true
 # 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
 ok {test-number} - cli.parse({ "test", "--benchmark-samples=200" }) for: {?}
 # Process can be configured on command line
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index 79245e38..434f8dbe 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -12337,7 +12337,7 @@ C
             result.errorMessage(), ContainsSubstring( "colour mode must be one of" )
           </Original>
           <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>
         </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 2daf4989..781d986c 100644
--- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt
@@ -12337,7 +12337,7 @@ C
             result.errorMessage(), ContainsSubstring( "colour mode must be one of" )
           </Original>
           <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>
         </Expression>
         <OverallResults successes="2" failures="0" expectedFailures="0"/>