catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Allow only 1 reporter at a time
- Commit
414dcae34a374ab21aff03822f0aed30ee49c425- Author
- Martin Hořeňovský ·
- Parents
d2d8455b571b
Changes
include/internal/catch_commandline.cpp | 2 +- include/internal/catch_config.cpp | 2 +- include/internal/catch_config.hpp | 10 +++- include/internal/catch_session.cpp | 13 +---- .../SelfTest/Baselines/compact.sw.approved.txt | 13 ++--- .../SelfTest/Baselines/console.std.approved.txt | 2 +- .../SelfTest/Baselines/console.sw.approved.txt | 40 ++++----------- projects/SelfTest/Baselines/junit.sw.approved.txt | 4 +- projects/SelfTest/Baselines/xml.sw.approved.txt | 58 +++++++--------------- .../SelfTest/IntrospectiveTests/CmdLine.tests.cpp | 18 +++---- 10 files changed, 54 insertions(+), 108 deletions(-) diff --git a/include/internal/catch_commandline.cpp b/include/internal/catch_commandline.cpp index 85af1085..c57b7ed7 100644 --- a/include/internal/catch_commandline.cpp +++ b/include/internal/catch_commandline.cpp @@ -130,7 +130,7 @@ namespace Catch { | Opt( config.outputFilename, "filename" ) ["-o"]["--out"] ( "output filename" ) - | Opt( config.reporterNames, "name" ) + | Opt( config.reporterName, "name" ) ["-r"]["--reporter"] ( "reporter to use (defaults to console)" ) | Opt( config.name, "name" ) diff --git a/include/internal/catch_config.cpp b/include/internal/catch_config.cpp index 1db94119..e8ad2a81 100644 --- a/include/internal/catch_config.cpp +++ b/include/internal/catch_config.cpp @@ -37,8 +37,8 @@ namespace Catch { bool Config::listReporters() const { return m_data.listReporters; } std::string Config::getProcessName() const { return m_data.processName; } + std::string const& Config::getReporterName() const { return m_data.reporterName; } - std::vector<std::string> const& Config::getReporterNames() const { return m_data.reporterNames; } std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; } std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; } diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index 3afdff5e..9d5e772e 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -55,7 +55,13 @@ namespace Catch { std::string name; std::string processName; - std::vector<std::string> reporterNames; +#ifndef CATCH_CONFIG_DEFAULT_REPORTER +#define CATCH_CONFIG_DEFAULT_REPORTER "console" +#endif + std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER; +#undef CATCH_CONFIG_DEFAULT_REPORTER + + std::vector<std::string> testsOrTags; std::vector<std::string> sectionsToRun; }; @@ -76,8 +82,8 @@ namespace Catch { bool listReporters() const; std::string getProcessName() const; + std::string const& getReporterName() const; - std::vector<std::string> const& getReporterNames() const; std::vector<std::string> const& getTestsOrTags() const; std::vector<std::string> const& getSectionsToRun() const override; diff --git a/include/internal/catch_session.cpp b/include/internal/catch_session.cpp index a5f8946e..a7ae19db 100644 --- a/include/internal/catch_session.cpp +++ b/include/internal/catch_session.cpp @@ -36,22 +36,11 @@ namespace Catch { return reporter; } -#ifndef CATCH_CONFIG_DEFAULT_REPORTER -#define CATCH_CONFIG_DEFAULT_REPORTER "console" -#endif IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) { - auto const& reporterNames = config->getReporterNames(); - if (reporterNames.empty()) - return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config); - - IStreamingReporterPtr reporter; - for (auto const& name : reporterNames) - addReporter(reporter, createReporter(name, config)); - return reporter; + return createReporter(config->getReporterName(), config); } -#undef CATCH_CONFIG_DEFAULT_REPORTER void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) { auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index dbf34fd4..12b4f730 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -528,7 +528,7 @@ CmdLine.tests.cpp:<line number>: passed: config.processName == "test" for: "test CmdLine.tests.cpp:<line number>: passed: config.shouldDebugBreak == false for: false == false CmdLine.tests.cpp:<line number>: passed: config.abortAfter == -1 for: -1 == -1 CmdLine.tests.cpp:<line number>: passed: config.noThrow == false for: false == false -CmdLine.tests.cpp:<line number>: passed: config.reporterNames.empty() for: true +CmdLine.tests.cpp:<line number>: passed: config.reporterName == "console" for: "console" == "console" CmdLine.tests.cpp:<line number>: passed: !(cfg.hasTestFilters()) for: !false CmdLine.tests.cpp:<line number>: passed: result for: {?} CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true @@ -543,15 +543,12 @@ CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(fakeTestCase("test1")) == false for: false == false CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(fakeTestCase("alwaysIncluded")) for: true CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "-r", "console"}) for: {?} -CmdLine.tests.cpp:<line number>: passed: config.reporterNames[0] == "console" for: "console" == "console" +CmdLine.tests.cpp:<line number>: passed: config.reporterName == "console" for: "console" == "console" CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "-r", "xml"}) for: {?} -CmdLine.tests.cpp:<line number>: passed: config.reporterNames[0] == "xml" for: "xml" == "xml" -CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "-r", "xml", "-r", "junit"}) for: {?} -CmdLine.tests.cpp:<line number>: passed: config.reporterNames.size() == 2 for: 2 == 2 -CmdLine.tests.cpp:<line number>: passed: config.reporterNames[0] == "xml" for: "xml" == "xml" -CmdLine.tests.cpp:<line number>: passed: config.reporterNames[1] == "junit" for: "junit" == "junit" +CmdLine.tests.cpp:<line number>: passed: config.reporterName == "xml" for: "xml" == "xml" CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "--reporter", "junit"}) for: {?} -CmdLine.tests.cpp:<line number>: passed: config.reporterNames[0] == "junit" for: "junit" == "junit" +CmdLine.tests.cpp:<line number>: passed: config.reporterName == "junit" for: "junit" == "junit" +CmdLine.tests.cpp:<line number>: passed: !(cli.parse({ "test", "-r", "xml", "-r", "junit" })) for: !{?} CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "-b"}) for: {?} CmdLine.tests.cpp:<line number>: passed: config.shouldDebugBreak == true for: true == true CmdLine.tests.cpp:<line number>: 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 8bef5356..b4dd6129 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1085,5 +1085,5 @@ due to unexpected exception with message: =============================================================================== test cases: 205 | 152 passed | 49 failed | 4 failed as expected -assertions: 1063 | 935 passed | 107 failed | 21 failed as expected +assertions: 1060 | 932 passed | 107 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 1e67fd94..085b2ea8 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -4080,9 +4080,9 @@ with expansion: CmdLine.tests.cpp:<line number>: PASSED: - CHECK( config.reporterNames.empty() ) + CHECK( config.reporterName == "console" ) with expansion: - true + "console" == "console" CmdLine.tests.cpp:<line number>: PASSED: @@ -4202,7 +4202,7 @@ with expansion: CmdLine.tests.cpp:<line number>: PASSED: - REQUIRE( config.reporterNames[0] == "console" ) + REQUIRE( config.reporterName == "console" ) with expansion: "console" == "console" @@ -4222,61 +4222,43 @@ with expansion: CmdLine.tests.cpp:<line number>: PASSED: - REQUIRE( config.reporterNames[0] == "xml" ) + REQUIRE( config.reporterName == "xml" ) with expansion: "xml" == "xml" ------------------------------------------------------------------------------- Process can be configured on command line reporter - -r xml and junit + --reporter/junit ------------------------------------------------------------------------------- CmdLine.tests.cpp:<line number> ............................................................................... CmdLine.tests.cpp:<line number>: PASSED: - CHECK( cli.parse({"test", "-r", "xml", "-r", "junit"}) ) + CHECK( cli.parse({"test", "--reporter", "junit"}) ) with expansion: {?} CmdLine.tests.cpp:<line number>: PASSED: - REQUIRE( config.reporterNames.size() == 2 ) -with expansion: - 2 == 2 - -CmdLine.tests.cpp:<line number>: -PASSED: - REQUIRE( config.reporterNames[0] == "xml" ) -with expansion: - "xml" == "xml" - -CmdLine.tests.cpp:<line number>: -PASSED: - REQUIRE( config.reporterNames[1] == "junit" ) + REQUIRE( config.reporterName == "junit" ) with expansion: "junit" == "junit" ------------------------------------------------------------------------------- Process can be configured on command line reporter - --reporter/junit + Only one reporter is accepted ------------------------------------------------------------------------------- CmdLine.tests.cpp:<line number> ............................................................................... CmdLine.tests.cpp:<line number>: PASSED: - CHECK( cli.parse({"test", "--reporter", "junit"}) ) + REQUIRE_FALSE( cli.parse({ "test", "-r", "xml", "-r", "junit" }) ) with expansion: - {?} - -CmdLine.tests.cpp:<line number>: -PASSED: - REQUIRE( config.reporterNames[0] == "junit" ) -with expansion: - "junit" == "junit" + !{?} ------------------------------------------------------------------------------- Process can be configured on command line @@ -8960,5 +8942,5 @@ PASSED: =============================================================================== test cases: 205 | 139 passed | 62 failed | 4 failed as expected -assertions: 1077 | 935 passed | 121 failed | 21 failed as expected +assertions: 1074 | 932 passed | 121 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 63424efe..2691a27e 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesloose text artifact > - <testsuite name="<exe-name>" errors="17" failures="105" tests="1078" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="105" tests="1075" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/> <testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/> <testcase classname="<exe-name>.global" name="#1027" time="{duration}"/> @@ -474,8 +474,8 @@ Message.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Process can be configured on command line/test lists/Specify one test case exclusion using ~" time="{duration}"/> <testcase classname="<exe-name>.global" name="Process can be configured on command line/reporter/-r/console" time="{duration}"/> <testcase classname="<exe-name>.global" name="Process can be configured on command line/reporter/-r/xml" time="{duration}"/> - <testcase classname="<exe-name>.global" name="Process can be configured on command line/reporter/-r xml and junit" time="{duration}"/> <testcase classname="<exe-name>.global" name="Process can be configured on command line/reporter/--reporter/junit" time="{duration}"/> + <testcase classname="<exe-name>.global" name="Process can be configured on command line/reporter/Only one reporter is accepted" time="{duration}"/> <testcase classname="<exe-name>.global" name="Process can be configured on command line/debugger/-b" time="{duration}"/> <testcase classname="<exe-name>.global" name="Process can be configured on command line/debugger/--break" time="{duration}"/> <testcase classname="<exe-name>.global" name="Process can be configured on command line/abort/-a aborts after first failure" time="{duration}"/> diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index e2fdb2a4..0c5747ac 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -4757,10 +4757,10 @@ </Expression> <Expression success="true" type="CHECK" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Original> - config.reporterNames.empty() + config.reporterName == "console" </Original> <Expanded> - true + "console" == "console" </Expanded> </Expression> <Expression success="true" type="CHECK_FALSE" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > @@ -4899,7 +4899,7 @@ </Expression> <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Original> - config.reporterNames[0] == "console" + config.reporterName == "console" </Original> <Expanded> "console" == "console" @@ -4921,7 +4921,7 @@ </Expression> <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Original> - config.reporterNames[0] == "xml" + config.reporterName == "xml" </Original> <Expanded> "xml" == "xml" @@ -4932,10 +4932,10 @@ <OverallResults successes="2" failures="0" expectedFailures="0"/> </Section> <Section name="reporter" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > - <Section name="-r xml and junit" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > + <Section name="--reporter/junit" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Expression success="true" type="CHECK" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Original> - cli.parse({"test", "-r", "xml", "-r", "junit"}) + cli.parse({"test", "--reporter", "junit"}) </Original> <Expanded> {?} @@ -4943,53 +4943,29 @@ </Expression> <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Original> - config.reporterNames.size() == 2 - </Original> - <Expanded> - 2 == 2 - </Expanded> - </Expression> - <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > - <Original> - config.reporterNames[0] == "xml" - </Original> - <Expanded> - "xml" == "xml" - </Expanded> - </Expression> - <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > - <Original> - config.reporterNames[1] == "junit" + config.reporterName == "junit" </Original> <Expanded> "junit" == "junit" </Expanded> </Expression> - <OverallResults successes="4" failures="0" expectedFailures="0"/> + <OverallResults successes="2" failures="0" expectedFailures="0"/> </Section> - <OverallResults successes="4" failures="0" expectedFailures="0"/> + <OverallResults successes="2" failures="0" expectedFailures="0"/> </Section> <Section name="reporter" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > - <Section name="--reporter/junit" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > - <Expression success="true" type="CHECK" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > - <Original> - cli.parse({"test", "--reporter", "junit"}) - </Original> - <Expanded> - {?} - </Expanded> - </Expression> - <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > + <Section name="Only one reporter is accepted" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > + <Expression success="true" type="REQUIRE_FALSE" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Original> - config.reporterNames[0] == "junit" + !(cli.parse({ "test", "-r", "xml", "-r", "junit" })) </Original> <Expanded> - "junit" == "junit" + !{?} </Expanded> </Expression> - <OverallResults successes="2" failures="0" expectedFailures="0"/> + <OverallResults successes="1" failures="0" expectedFailures="0"/> </Section> - <OverallResults successes="2" failures="0" expectedFailures="0"/> + <OverallResults successes="1" failures="0" expectedFailures="0"/> </Section> <Section name="debugger" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Section name="-b" filename="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > @@ -9913,7 +9889,7 @@ loose text artifact </Section> <OverallResult success="true"/> </TestCase> - <OverallResults successes="935" failures="122" expectedFailures="21"/> + <OverallResults successes="932" failures="122" expectedFailures="21"/> </Group> - <OverallResults successes="935" failures="121" expectedFailures="21"/> + <OverallResults successes="932" failures="121" expectedFailures="21"/> </Catch> diff --git a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index 7bc4a367..1da3fa08 100644 --- a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -288,7 +288,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.reporterNames.empty()); + CHECK(config.reporterName == "console"); Catch::Config cfg(config); CHECK_FALSE(cfg.hasTestFilters()); @@ -330,24 +330,20 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]" SECTION("-r/console") { CHECK(cli.parse({"test", "-r", "console"})); - REQUIRE(config.reporterNames[0] == "console"); + REQUIRE(config.reporterName == "console"); } SECTION("-r/xml") { CHECK(cli.parse({"test", "-r", "xml"})); - REQUIRE(config.reporterNames[0] == "xml"); - } - SECTION("-r xml and junit") { - CHECK(cli.parse({"test", "-r", "xml", "-r", "junit"})); - - REQUIRE(config.reporterNames.size() == 2); - REQUIRE(config.reporterNames[0] == "xml"); - REQUIRE(config.reporterNames[1] == "junit"); + REQUIRE(config.reporterName == "xml"); } SECTION("--reporter/junit") { CHECK(cli.parse({"test", "--reporter", "junit"})); - REQUIRE(config.reporterNames[0] == "junit"); + REQUIRE(config.reporterName == "junit"); + } + SECTION("Only one reporter is accepted") { + REQUIRE_FALSE(cli.parse({ "test", "-r", "xml", "-r", "junit" })); } }