Integrate the new reporter specs into Catch2

This means that the CLI interface now uses the new key-value oriented
reporter spec, the common reporter base creates the colour implementation
based on the reporter-specific configuration, and it also stores the
custom configuration options for each reporter instance.

Closes #339 as it allows per-reporter forcing of ansi colour codes.
This commit is contained in:
Martin Hořeňovský
2022-04-04 21:07:04 +02:00
parent 3c06bcb374
commit 423e1d2ebb
29 changed files with 395 additions and 448 deletions

View File

@@ -361,9 +361,9 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
#endif
;
CHECK( cfg.getReportersAndOutputFiles().size() == 1 );
CHECK( cfg.getReportersAndOutputFiles()[0] ==
Catch::ConfigData::ReporterAndFile{ expectedReporter, {} } );
CHECK( cfg.getReporterSpecs().size() == 1 );
CHECK( cfg.getReporterSpecs()[0] ==
Catch::ReporterSpec{ expectedReporter, {}, {}, {} } );
}
SECTION("test lists") {
@@ -399,28 +399,31 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
}
SECTION("reporter") {
using vec_ReporterAndFile = std::vector<Catch::ConfigData::ReporterAndFile>;
using vec_Specs = std::vector<Catch::ReporterSpec>;
using namespace std::string_literals;
SECTION("-r/console") {
auto result = cli.parse({"test", "-r", "console"});
CAPTURE(result.errorMessage());
CHECK(result);
REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"console", {}} });
REQUIRE( config.reporterSpecifications ==
vec_Specs{ { "console", {}, {}, {} } } );
}
SECTION("-r/xml") {
auto result = cli.parse({"test", "-r", "xml"});
CAPTURE(result.errorMessage());
CHECK(result);
REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"xml", {}} });
REQUIRE( config.reporterSpecifications ==
vec_Specs{ { "xml", {}, {}, {} } } );
}
SECTION("--reporter/junit") {
auto result = cli.parse({"test", "--reporter", "junit"});
CAPTURE(result.errorMessage());
CHECK(result);
REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"junit", {}} });
REQUIRE( config.reporterSpecifications ==
vec_Specs{ { "junit", {}, {}, {} } } );
}
SECTION("must match one of the available ones") {
auto result = cli.parse({"test", "--reporter", "unsupported"});
@@ -429,34 +432,34 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
REQUIRE_THAT(result.errorMessage(), ContainsSubstring("Unrecognized reporter"));
}
SECTION("With output file") {
auto result = cli.parse({ "test", "-r", "console::out.txt" });
auto result = cli.parse({ "test", "-r", "console::out=out.txt" });
CAPTURE(result.errorMessage());
CHECK(result);
REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"console", "out.txt"s} });
REQUIRE( config.reporterSpecifications ==
vec_Specs{ { "console", "out.txt"s, {}, {} } } );
}
SECTION("With Windows-like absolute path as output file") {
auto result = cli.parse({ "test", "-r", "console::C:\\Temp\\out.txt" });
auto result = cli.parse({ "test", "-r", "console::out=C:\\Temp\\out.txt" });
CAPTURE(result.errorMessage());
CHECK(result);
REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"console", "C:\\Temp\\out.txt"s} });
}
SECTION("Output file cannot be empty") {
auto result = cli.parse({"test", "--reporter", "console::"});
CHECK(!result);
REQUIRE_THAT(result.errorMessage(), ContainsSubstring("empty filename"));
REQUIRE( config.reporterSpecifications ==
vec_Specs{ { "console", "C:\\Temp\\out.txt"s, {}, {} } } );
}
SECTION("Multiple reporters") {
SECTION("All with output files") {
CHECK(cli.parse({ "test", "-r", "xml::output.xml", "-r", "junit::output-junit.xml" }));
REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"xml", "output.xml"s}, {"junit", "output-junit.xml"s} });
CHECK(cli.parse({ "test", "-r", "xml::out=output.xml", "-r", "junit::out=output-junit.xml" }));
REQUIRE( config.reporterSpecifications ==
vec_Specs{ { "xml", "output.xml"s, {}, {} },
{ "junit", "output-junit.xml"s, {}, {} } } );
}
SECTION("Mixed output files and default output") {
CHECK(cli.parse({ "test", "-r", "xml::output.xml", "-r", "console" }));
REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"xml", "output.xml"s}, {"console", {}} });
CHECK(cli.parse({ "test", "-r", "xml::out=output.xml", "-r", "console" }));
REQUIRE( config.reporterSpecifications ==
vec_Specs{ { "xml", "output.xml"s, {}, {} },
{ "console", {}, {}, {} } } );
}
SECTION("cannot have multiple reporters with default output") {
auto result = cli.parse({ "test", "-r", "console", "-r", "xml::output.xml", "-r", "junit" });
auto result = cli.parse({ "test", "-r", "console", "-r", "xml::out=output.xml", "-r", "junit" });
CHECK(!result);
REQUIRE_THAT(result.errorMessage(), ContainsSubstring("Only one reporter may have unspecified output file."));
}

View File

@@ -89,7 +89,8 @@ TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) {
Catch::ConfigData config_data;
Catch::Config config( config_data );
Catch::ReporterConfig rep_config( &config, &sstream );
Catch::ReporterConfig rep_config(
&config, &sstream, Catch::ColourMode::None, {} );
auto reporter = factory.second->create( rep_config );
DYNAMIC_SECTION( factory.first << " reporter lists tags" ) {
@@ -176,7 +177,8 @@ TEST_CASE("Multireporter calls reporters and listeners in correct order",
Catch::ConfigData config_data;
Catch::Config config( config_data );
StringIStream sstream;
Catch::ReporterConfig rep_config( &config, &sstream );
Catch::ReporterConfig rep_config(
&config, &sstream, Catch::ColourMode::None, {} );
// We add reporters before listeners, to check that internally they
// get sorted properly, and listeners are called first anyway.
@@ -229,7 +231,8 @@ TEST_CASE("Multireporter updates ReporterPreferences properly",
Catch::ConfigData config_data;
Catch::Config config( config_data );
StringIStream sstream;
Catch::ReporterConfig rep_config( &config, &sstream );
Catch::ReporterConfig rep_config(
&config, &sstream, Catch::ColourMode::None, {} );
Catch::MultiReporter multiReporter( &config );
// Post init defaults