From 8b3c09c137b532ca1480d267ae9dc367b889a408 Mon Sep 17 00:00:00 2001 From: Maciej Patro Date: Mon, 22 Oct 2018 15:59:01 +0200 Subject: [PATCH] Catch's CLI now checks whether requested reporter exists Fixes #1351 --- include/internal/catch_commandline.cpp | 17 +++++++++++- .../Baselines/compact.sw.approved.txt | 2 ++ .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 23 +++++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 3 ++- .../SelfTest/Baselines/xml.sw.approved.txt | 26 +++++++++++++++++-- .../IntrospectiveTests/CmdLine.tests.cpp | 10 +++++-- 7 files changed, 75 insertions(+), 8 deletions(-) diff --git a/include/internal/catch_commandline.cpp b/include/internal/catch_commandline.cpp index c57b7ed7..66759ebb 100644 --- a/include/internal/catch_commandline.cpp +++ b/include/internal/catch_commandline.cpp @@ -10,6 +10,9 @@ #include "catch_string_manip.h" +#include "catch_interfaces_registry_hub.h" +#include "catch_interfaces_reporter.h" + #include #include @@ -105,6 +108,18 @@ namespace Catch { return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" ); return ParserResult::ok( ParseResultType::Matched ); }; + auto const setReporter = [&]( std::string const& reporter ) { + IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); + + auto lcReporter = toLower( reporter ); + auto result = factories.find( lcReporter ); + + if( factories.end() != result ) + config.reporterName = lcReporter; + else + return ParserResult::runtimeError( "Unrecognized reporter, '" + reporter + "'. Check available with --list-reporters" ); + return ParserResult::ok( ParseResultType::Matched ); + }; auto cli = ExeName( config.processName ) @@ -130,7 +145,7 @@ namespace Catch { | Opt( config.outputFilename, "filename" ) ["-o"]["--out"] ( "output filename" ) - | Opt( config.reporterName, "name" ) + | Opt( setReporter, "name" ) ["-r"]["--reporter"] ( "reporter to use (defaults to console)" ) | Opt( config.name, "name" ) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 767cb567..2b1b917a 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -707,6 +707,8 @@ CmdLine.tests.cpp:: passed: config.reporterName == "xml" for: "xml" CmdLine.tests.cpp:: passed: cli.parse({"test", "--reporter", "junit"}) for: {?} CmdLine.tests.cpp:: passed: config.reporterName == "junit" for: "junit" == "junit" CmdLine.tests.cpp:: passed: !(cli.parse({ "test", "-r", "xml", "-r", "junit" })) for: !{?} +CmdLine.tests.cpp:: passed: !result for: true +CmdLine.tests.cpp:: passed: result.errorMessage(), Contains("Unrecognized reporter") for: "Unrecognized reporter, 'unsupported'. Check available with --list-reporters" contains: "Unrecognized reporter" CmdLine.tests.cpp:: passed: cli.parse({"test", "-b"}) for: {?} CmdLine.tests.cpp:: passed: config.shouldDebugBreak == true for: true == true CmdLine.tests.cpp:: passed: cli.parse({"test", "--break"}) for: {?} diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 525a193c..7d3a4db4 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1099,5 +1099,5 @@ due to unexpected exception with message: =============================================================================== test cases: 215 | 162 passed | 49 failed | 4 failed as expected -assertions: 1231 | 1102 passed | 108 failed | 21 failed as expected +assertions: 1233 | 1104 passed | 108 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 6642a06e..3085960e 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -5977,6 +5977,27 @@ PASSED: with expansion: !{?} +------------------------------------------------------------------------------- +Process can be configured on command line + reporter + must match one of the available ones +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: +PASSED: + CHECK( !result ) +with expansion: + true + +CmdLine.tests.cpp:: +PASSED: + REQUIRE_THAT( result.errorMessage(), Contains("Unrecognized reporter") ) +with expansion: + "Unrecognized reporter, 'unsupported'. Check available with --list-reporters" + contains: "Unrecognized reporter" + ------------------------------------------------------------------------------- Process can be configured on command line debugger @@ -10865,5 +10886,5 @@ PASSED: =============================================================================== test cases: 215 | 149 passed | 62 failed | 4 failed as expected -assertions: 1245 | 1102 passed | 122 failed | 21 failed as expected +assertions: 1247 | 1104 passed | 122 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index f3644485..0b726c8d 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -489,6 +489,7 @@ Message.tests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 02509e08..f573f585 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -6237,6 +6237,28 @@ +
+
+ + + !result + + + true + + + + + result.errorMessage(), Contains("Unrecognized reporter") + + + "Unrecognized reporter, 'unsupported'. Check available with --list-reporters" contains: "Unrecognized reporter" + + + +
+ +
@@ -11336,7 +11358,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index cb635ead..9b5b0ed7 100644 --- a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -280,7 +280,6 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]" CHECK(config.processName == ""); } - SECTION("default - no arguments") { auto result = cli.parse({"test"}); CHECK(result); @@ -345,8 +344,15 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]" SECTION("Only one reporter is accepted") { REQUIRE_FALSE(cli.parse({ "test", "-r", "xml", "-r", "junit" })); } - } + SECTION("must match one of the available ones") { + auto result = cli.parse({"test", "--reporter", "unsupported"}); + CHECK(!result); +#ifndef CATCH_CONFIG_DISABLE_MATCHERS + REQUIRE_THAT(result.errorMessage(), Contains("Unrecognized reporter")); +#endif + } + } SECTION("debugger") { SECTION("-b") {