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 Hořeňovský2022-01-01 16:19:31 +0100
committerGitHub2022-01-01 16:19:31 +0100
commitf2f585b4788b61ed202e78b73b105f099d9cce7b (patch)
tree174f72ba09e22e564a571f96c21a175a68d85103 /tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
parent6b55f5d780c5d8e935720f9d7d8ed28a3ba8617f (diff)
parentb5547f2ef6be18f70d2e9638d8f1eb0d8d42d2ba (diff)
downloadcatch3-f2f585b4788b61ed202e78b73b105f099d9cce7b.tar.gz
Merge pull request #2183 from mjerabek/dev-multiple-reporters
Add support for multiple reporters
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp')
-rw-r--r--tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp81
1 files changed, 68 insertions, 13 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp
index 16a77bc1..53fc08b8 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");
}
}
@@ -644,3 +682,20 @@ TEST_CASE("Test with special, characters \"in name", "[cli][regression]") {
// This test case succeeds if we can invoke it from the CLI
SUCCEED();
}
+
+TEST_CASE("Various suspicious reporter specs are rejected",
+ "[cli][reporter-spec][approvals]") {
+ Catch::ConfigData config;
+ auto cli = Catch::makeCommandLineParser( config );
+
+ auto spec = GENERATE( as<std::string>{},
+ "",
+ "::console",
+ "console::",
+ "console::some-file::",
+ "::console::some-file::" );
+ CAPTURE( spec );
+
+ auto result = cli.parse( { "test", "--reporter", spec } );
+ REQUIRE_FALSE( result );
+}