Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
diff options
context:
space:
mode:
authorMartin Jeřábek2021-02-06 20:12:07 +0100
committerMartin Hořeňovský2022-01-01 14:02:23 +0100
commitccd67b293d7595a0cf2dc6c4bfb2017fc18c1f14 (patch)
treeba5f166d1cf867ad97617656083354fbddfc5d9f /tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
parent6b55f5d780c5d8e935720f9d7d8ed28a3ba8617f (diff)
downloadcatch3-ccd67b293d7595a0cf2dc6c4bfb2017fc18c1f14.tar.gz
Add support for multiple parallel reporters
This requires a bunch of different changes across the reporter subsystem. * We need to handle multiple reporters and their differing preferences in `ListeningReporter`, e.g. what to do when we mix reporters that capture and don't capture stdout. * We need to change how the reporter is given output and how we parse reporter's output destination from CLI. * Approval tests need to handle multireporter option
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp')
-rw-r--r--tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp64
1 files changed, 51 insertions, 13 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
index 16a77bc1..2210a3a4 100644
--- a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
@@ -3,12 +3,12 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
+#include <catch2/catch_config.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <catch2/internal/catch_test_spec_parser.hpp>
#include <catch2/catch_test_case_info.hpp>
-#include <catch2/catch_config.hpp>
#include <catch2/internal/catch_commandline.hpp>
#include <catch2/generators/catch_generators.hpp>
@@ -345,7 +345,7 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
CHECK(config.shouldDebugBreak == false);
CHECK(config.abortAfter == -1);
CHECK(config.noThrow == false);
- CHECK(config.reporterName == "console");
+ CHECK(config.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} });
Catch::Config cfg(config);
CHECK_FALSE(cfg.hasTestFilters());
@@ -384,23 +384,28 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
}
SECTION("reporter") {
+ using vec_ReporterAndFile = std::vector<Catch::ConfigData::ReporterAndFile>;
+ using namespace std::string_literals;
SECTION("-r/console") {
- CHECK(cli.parse({"test", "-r", "console"}));
+ auto result = cli.parse({"test", "-r", "console"});
+ CAPTURE(result.errorMessage());
+ CHECK(result);
- REQUIRE(config.reporterName == "console");
+ REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"console", {}} });
}
SECTION("-r/xml") {
- CHECK(cli.parse({"test", "-r", "xml"}));
+ auto result = cli.parse({"test", "-r", "xml"});
+ CAPTURE(result.errorMessage());
+ CHECK(result);
- REQUIRE(config.reporterName == "xml");
+ REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"xml", {}} });
}
SECTION("--reporter/junit") {
- CHECK(cli.parse({"test", "--reporter", "junit"}));
+ auto result = cli.parse({"test", "--reporter", "junit"});
+ CAPTURE(result.errorMessage());
+ CHECK(result);
- REQUIRE(config.reporterName == "junit");
- }
- SECTION("Only one reporter is accepted") {
- REQUIRE_FALSE(cli.parse({ "test", "-r", "xml", "-r", "junit" }));
+ REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"junit", {}} });
}
SECTION("must match one of the available ones") {
auto result = cli.parse({"test", "--reporter", "unsupported"});
@@ -408,6 +413,39 @@ 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" });
+ CAPTURE(result.errorMessage());
+ CHECK(result);
+ REQUIRE(config.reporterSpecifications == vec_ReporterAndFile{ {"console", "out.txt"s} });
+ }
+ SECTION("With Windows-like absolute path as output file") {
+ auto result = cli.parse({ "test", "-r", "console::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"));
+ }
+ 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} });
+ }
+ 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", {}} });
+ }
+ SECTION("cannot have multiple reporters with default output") {
+ auto result = cli.parse({ "test", "-r", "console", "-r", "xml::output.xml", "-r", "junit" });
+ CHECK(!result);
+ REQUIRE_THAT(result.errorMessage(), ContainsSubstring("Only one reporter may have unspecified output file."));
+ }
+ }
}
SECTION("debugger") {
@@ -483,12 +521,12 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
SECTION("-o filename") {
CHECK(cli.parse({"test", "-o", "filename.ext"}));
- REQUIRE(config.outputFilename == "filename.ext");
+ REQUIRE(config.defaultOutputFilename == "filename.ext");
}
SECTION("--out") {
CHECK(cli.parse({"test", "--out", "filename.ext"}));
- REQUIRE(config.outputFilename == "filename.ext");
+ REQUIRE(config.defaultOutputFilename == "filename.ext");
}
}