diff options
| author | Martin Hořeňovský | 2022-04-04 17:06:47 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-04-05 15:45:54 +0200 |
| commit | a51fd07bd006101c90662317c98de0ebe9e97312 (patch) | |
| tree | 7c732c3a6e8df9ab6593dbd551aecc09a782080b /tests | |
| parent | 8ac86495de5bf249fd50775335f62eedb77815d6 (diff) | |
| download | catch3-a51fd07bd006101c90662317c98de0ebe9e97312.tar.gz | |
Add helper for parsing the new reporter specs
The new reporter spec generalizes key-value options that can be
passed to the reporter, looking like this
`reporterName[::key=value]*`. A key can be either Catch2-recognized,
which currently means either `out` or `colour`, or reporter-specific
which is anything prefixed with `X`, e.g. `Xfoo`.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/CmdLineHelpers.tests.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/CmdLineHelpers.tests.cpp b/tests/SelfTest/IntrospectiveTests/CmdLineHelpers.tests.cpp index 0eacfdf3..9045ad2a 100644 --- a/tests/SelfTest/IntrospectiveTests/CmdLineHelpers.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/CmdLineHelpers.tests.cpp @@ -62,3 +62,50 @@ TEST_CASE( "Parsing colour mode", "[cli][colour][approvals]" ) { REQUIRE_FALSE( stringToColourMode( "asdbjsdb kasbd" ) ); } } + + +TEST_CASE("Parsing reporter specs", "[cli][reporter-spec][approvals]") { + using Catch::parseReporterSpec; + using Catch::ReporterSpec; + using namespace std::string_literals; + + SECTION( "Correct specs" ) { + REQUIRE( parseReporterSpec( "someReporter" ) == + ReporterSpec( "someReporter"s, {}, {}, {} ) ); + REQUIRE( parseReporterSpec( "otherReporter::Xk=v::out=c:\\blah" ) == + ReporterSpec( + "otherReporter"s, "c:\\blah"s, {}, { { "Xk"s, "v"s } } ) ); + REQUIRE( parseReporterSpec( "diffReporter::Xk1=v1::Xk2==v2" ) == + ReporterSpec( "diffReporter", + {}, + {}, + { { "Xk1"s, "v1"s }, { "Xk2"s, "=v2"s } } ) ); + REQUIRE( parseReporterSpec( + "Foo:bar:reporter::colour=ansi::Xk 1=v 1::Xk2=v:3" ) == + ReporterSpec( "Foo:bar:reporter", + {}, + Catch::ColourMode::ANSI, + { { "Xk 1"s, "v 1"s }, { "Xk2"s, "v:3"s } } ) ); + } + + SECTION( "Bad specs" ) { + REQUIRE_FALSE( parseReporterSpec( "::" ) ); + // Unknown Catch2 arg (should be "out") + REQUIRE_FALSE( parseReporterSpec( "reporter::output=filename" ) ); + // Wrong colour spec + REQUIRE_FALSE( parseReporterSpec( "reporter::colour=custom" ) ); + // Duplicated colour spec + REQUIRE_FALSE( parseReporterSpec( "reporter::colour=ansi::colour=ansi" ) ); + // Duplicated out arg + REQUIRE_FALSE( parseReporterSpec( "reporter::out=f.txt::out=z.txt" ) ); + // Duplicated custom arg + REQUIRE_FALSE( parseReporterSpec( "reporter::Xa=foo::Xa=bar" ) ); + // Empty key + REQUIRE_FALSE( parseReporterSpec( "reporter::X=foo" ) ); + REQUIRE_FALSE( parseReporterSpec( "reporter::=foo" ) ); + // Empty value + REQUIRE_FALSE( parseReporterSpec( "reporter::Xa=" ) ); + // non-key value later field + REQUIRE_FALSE( parseReporterSpec( "reporter::Xab" ) ); + } +} |