mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Push down handling of default reporter to Config's constructor
This simplifies the handling of default reporter in console parsing, at the cost of making `Config`'s constructor responsible for more things.
This commit is contained in:
parent
7cf2f88e50
commit
fc5552d27b
@ -6,6 +6,7 @@
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
#include <catch2/catch_config.hpp>
|
||||
#include <catch2/catch_user_config.hpp>
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
#include <catch2/internal/catch_stream.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
@ -57,6 +58,7 @@ namespace Catch {
|
||||
elem = trim(elem);
|
||||
}
|
||||
|
||||
|
||||
TestSpecParser parser(ITagAliasRegistry::get());
|
||||
if (!m_data.testsOrTags.empty()) {
|
||||
m_hasTestFilters = true;
|
||||
@ -66,6 +68,19 @@ namespace Catch {
|
||||
}
|
||||
m_testSpec = parser.testSpec();
|
||||
|
||||
|
||||
// Insert the default reporter if user hasn't asked for a specfic one
|
||||
if ( m_data.reporterSpecifications.empty() ) {
|
||||
m_data.reporterSpecifications.push_back( {
|
||||
#if defined( CATCH_CONFIG_DEFAULT_REPORTER )
|
||||
CATCH_CONFIG_DEFAULT_REPORTER,
|
||||
#else
|
||||
"console",
|
||||
#endif
|
||||
{}
|
||||
} );
|
||||
}
|
||||
|
||||
m_reporterStreams.reserve( m_data.reporterSpecifications.size() );
|
||||
for ( auto const& reporterAndFile : m_data.reporterSpecifications ) {
|
||||
if ( reporterAndFile.outputFileName.none() ) {
|
||||
|
@ -71,15 +71,7 @@ namespace Catch {
|
||||
std::string defaultOutputFilename;
|
||||
std::string name;
|
||||
std::string processName;
|
||||
#ifndef CATCH_CONFIG_DEFAULT_REPORTER
|
||||
#define CATCH_CONFIG_DEFAULT_REPORTER "console"
|
||||
#endif
|
||||
std::vector<ReporterAndFile> reporterSpecifications = {
|
||||
{CATCH_CONFIG_DEFAULT_REPORTER, {}}
|
||||
};
|
||||
// Internal: used as parser state
|
||||
bool _nonDefaultReporterSpecifications = false;
|
||||
#undef CATCH_CONFIG_DEFAULT_REPORTER
|
||||
std::vector<ReporterAndFile> reporterSpecifications;
|
||||
|
||||
std::vector<std::string> testsOrTags;
|
||||
std::vector<std::string> sectionsToRun;
|
||||
|
@ -139,15 +139,6 @@ namespace Catch {
|
||||
return ParserResult::runtimeError( "Received empty reporter spec." );
|
||||
}
|
||||
|
||||
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
|
||||
|
||||
// clear the default reporter
|
||||
if (!config._nonDefaultReporterSpecifications) {
|
||||
config.reporterSpecifications.clear();
|
||||
config._nonDefaultReporterSpecifications = true;
|
||||
}
|
||||
|
||||
|
||||
// Exactly one of the reporters may be specified without an output
|
||||
// file, in which case it defaults to the output specified by "-o"
|
||||
// (or standard output).
|
||||
@ -176,6 +167,8 @@ namespace Catch {
|
||||
fileNameSeparatorPos + separatorSize, reporterSpec.size() );
|
||||
}
|
||||
|
||||
IReporterRegistry::FactoryMap const& factories =
|
||||
getRegistryHub().getReporterRegistry().getFactories();
|
||||
auto result = factories.find( reporterName );
|
||||
|
||||
if( result == factories.end() )
|
||||
|
@ -1267,10 +1267,12 @@ 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.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} } for: { { console, <default-output> } }
|
||||
==
|
||||
{ { console, <default-output> } }
|
||||
CmdLine.tests.cpp:<line number>: passed: config.reporterSpecifications.empty() for: true
|
||||
CmdLine.tests.cpp:<line number>: passed: !(cfg.hasTestFilters()) for: !false
|
||||
CmdLine.tests.cpp:<line number>: passed: cfg.getReportersAndOutputFiles().size() == 1 for: 1 == 1
|
||||
CmdLine.tests.cpp:<line number>: passed: cfg.getReportersAndOutputFiles()[0] == Catch::ConfigData::ReporterAndFile{ expectedReporter, {} } for: { console, <default-output> }
|
||||
==
|
||||
{ console, <default-output> }
|
||||
CmdLine.tests.cpp:<line number>: passed: result for: {?}
|
||||
CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true
|
||||
CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(*fakeTestCase("notIncluded")) == false for: false == false
|
||||
|
@ -1265,10 +1265,12 @@ 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.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} } for: { { console, <default-output> } }
|
||||
==
|
||||
{ { console, <default-output> } }
|
||||
CmdLine.tests.cpp:<line number>: passed: config.reporterSpecifications.empty() for: true
|
||||
CmdLine.tests.cpp:<line number>: passed: !(cfg.hasTestFilters()) for: !false
|
||||
CmdLine.tests.cpp:<line number>: passed: cfg.getReportersAndOutputFiles().size() == 1 for: 1 == 1
|
||||
CmdLine.tests.cpp:<line number>: passed: cfg.getReportersAndOutputFiles()[0] == Catch::ConfigData::ReporterAndFile{ expectedReporter, {} } for: { console, <default-output> }
|
||||
==
|
||||
{ console, <default-output> }
|
||||
CmdLine.tests.cpp:<line number>: passed: result for: {?}
|
||||
CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true
|
||||
CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(*fakeTestCase("notIncluded")) == false for: false == false
|
||||
|
@ -1396,5 +1396,5 @@ due to unexpected exception with message:
|
||||
|
||||
===============================================================================
|
||||
test cases: 381 | 305 passed | 69 failed | 7 failed as expected
|
||||
assertions: 2209 | 2054 passed | 128 failed | 27 failed as expected
|
||||
assertions: 2211 | 2056 passed | 128 failed | 27 failed as expected
|
||||
|
||||
|
@ -9260,17 +9260,27 @@ with expansion:
|
||||
false == false
|
||||
|
||||
CmdLine.tests.cpp:<line number>: PASSED:
|
||||
CHECK( config.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} } )
|
||||
CHECK( config.reporterSpecifications.empty() )
|
||||
with expansion:
|
||||
{ { console, <default-output> } }
|
||||
==
|
||||
{ { console, <default-output> } }
|
||||
true
|
||||
|
||||
CmdLine.tests.cpp:<line number>: PASSED:
|
||||
CHECK_FALSE( cfg.hasTestFilters() )
|
||||
with expansion:
|
||||
!false
|
||||
|
||||
CmdLine.tests.cpp:<line number>: PASSED:
|
||||
CHECK( cfg.getReportersAndOutputFiles().size() == 1 )
|
||||
with expansion:
|
||||
1 == 1
|
||||
|
||||
CmdLine.tests.cpp:<line number>: PASSED:
|
||||
CHECK( cfg.getReportersAndOutputFiles()[0] == Catch::ConfigData::ReporterAndFile{ expectedReporter, {} } )
|
||||
with expansion:
|
||||
{ console, <default-output> }
|
||||
==
|
||||
{ console, <default-output> }
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Process can be configured on command line
|
||||
test lists
|
||||
@ -17755,5 +17765,5 @@ Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 381 | 291 passed | 83 failed | 7 failed as expected
|
||||
assertions: 2224 | 2054 passed | 143 failed | 27 failed as expected
|
||||
assertions: 2226 | 2056 passed | 143 failed | 27 failed as expected
|
||||
|
||||
|
@ -9258,17 +9258,27 @@ with expansion:
|
||||
false == false
|
||||
|
||||
CmdLine.tests.cpp:<line number>: PASSED:
|
||||
CHECK( config.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} } )
|
||||
CHECK( config.reporterSpecifications.empty() )
|
||||
with expansion:
|
||||
{ { console, <default-output> } }
|
||||
==
|
||||
{ { console, <default-output> } }
|
||||
true
|
||||
|
||||
CmdLine.tests.cpp:<line number>: PASSED:
|
||||
CHECK_FALSE( cfg.hasTestFilters() )
|
||||
with expansion:
|
||||
!false
|
||||
|
||||
CmdLine.tests.cpp:<line number>: PASSED:
|
||||
CHECK( cfg.getReportersAndOutputFiles().size() == 1 )
|
||||
with expansion:
|
||||
1 == 1
|
||||
|
||||
CmdLine.tests.cpp:<line number>: PASSED:
|
||||
CHECK( cfg.getReportersAndOutputFiles()[0] == Catch::ConfigData::ReporterAndFile{ expectedReporter, {} } )
|
||||
with expansion:
|
||||
{ console, <default-output> }
|
||||
==
|
||||
{ console, <default-output> }
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Process can be configured on command line
|
||||
test lists
|
||||
@ -17747,5 +17757,5 @@ Misc.tests.cpp:<line number>: PASSED:
|
||||
|
||||
===============================================================================
|
||||
test cases: 381 | 291 passed | 83 failed | 7 failed as expected
|
||||
assertions: 2224 | 2054 passed | 143 failed | 27 failed as expected
|
||||
assertions: 2226 | 2056 passed | 143 failed | 27 failed as expected
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuitesloose text artifact
|
||||
>
|
||||
<testsuite name="<exe-name>" errors="17" failures="126" tests="2224" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="126" tests="2226" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="random-seed" value="1"/>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites>
|
||||
<testsuite name="<exe-name>" errors="17" failures="126" tests="2224" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<testsuite name="<exe-name>" errors="17" failures="126" tests="2226" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
|
||||
<properties>
|
||||
<property name="random-seed" value="1"/>
|
||||
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
|
||||
|
@ -2453,10 +2453,14 @@ ok {test-number} - config.abortAfter == -1 for: -1 == -1
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - config.noThrow == false for: false == false
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - config.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} } for: { { console, <default-output> } } == { { console, <default-output> } }
|
||||
ok {test-number} - config.reporterSpecifications.empty() for: true
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - !(cfg.hasTestFilters()) for: !false
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - cfg.getReportersAndOutputFiles().size() == 1 for: 1 == 1
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - cfg.getReportersAndOutputFiles()[0] == Catch::ConfigData::ReporterAndFile{ expectedReporter, {} } for: { console, <default-output> } == { console, <default-output> }
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - result for: {?}
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - cfg.hasTestFilters() for: true
|
||||
@ -4450,5 +4454,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
|
||||
ok {test-number} -
|
||||
# xmlentitycheck
|
||||
ok {test-number} -
|
||||
1..2224
|
||||
1..2226
|
||||
|
||||
|
@ -2451,10 +2451,14 @@ ok {test-number} - config.abortAfter == -1 for: -1 == -1
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - config.noThrow == false for: false == false
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - config.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} } for: { { console, <default-output> } } == { { console, <default-output> } }
|
||||
ok {test-number} - config.reporterSpecifications.empty() for: true
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - !(cfg.hasTestFilters()) for: !false
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - cfg.getReportersAndOutputFiles().size() == 1 for: 1 == 1
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - cfg.getReportersAndOutputFiles()[0] == Catch::ConfigData::ReporterAndFile{ expectedReporter, {} } for: { console, <default-output> } == { console, <default-output> }
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - result for: {?}
|
||||
# Process can be configured on command line
|
||||
ok {test-number} - cfg.hasTestFilters() for: true
|
||||
@ -4442,5 +4446,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
|
||||
ok {test-number} -
|
||||
# xmlentitycheck
|
||||
ok {test-number} -
|
||||
1..2224
|
||||
1..2226
|
||||
|
||||
|
@ -11289,12 +11289,10 @@ Nor would this
|
||||
</Expression>
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
<Original>
|
||||
config.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} }
|
||||
config.reporterSpecifications.empty()
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { console, <default-output> } }
|
||||
==
|
||||
{ { console, <default-output> } }
|
||||
true
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="CHECK_FALSE" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
@ -11305,7 +11303,25 @@ Nor would this
|
||||
!false
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="7" failures="0" expectedFailures="0"/>
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
<Original>
|
||||
cfg.getReportersAndOutputFiles().size() == 1
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 == 1
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
<Original>
|
||||
cfg.getReportersAndOutputFiles()[0] == Catch::ConfigData::ReporterAndFile{ expectedReporter, {} }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ console, <default-output> }
|
||||
==
|
||||
{ console, <default-output> }
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="9" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="test lists" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
<Section name="Specify one test case using" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
@ -20863,6 +20879,6 @@ loose text artifact
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="2054" failures="143" expectedFailures="27"/>
|
||||
<OverallResults successes="2056" failures="143" expectedFailures="27"/>
|
||||
<OverallResultsCases successes="291" failures="83" expectedFailures="7"/>
|
||||
</Catch2TestRun>
|
||||
|
@ -11289,12 +11289,10 @@ Nor would this
|
||||
</Expression>
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
<Original>
|
||||
config.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} }
|
||||
config.reporterSpecifications.empty()
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ { console, <default-output> } }
|
||||
==
|
||||
{ { console, <default-output> } }
|
||||
true
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="CHECK_FALSE" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
@ -11305,7 +11303,25 @@ Nor would this
|
||||
!false
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="7" failures="0" expectedFailures="0"/>
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
<Original>
|
||||
cfg.getReportersAndOutputFiles().size() == 1
|
||||
</Original>
|
||||
<Expanded>
|
||||
1 == 1
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
<Original>
|
||||
cfg.getReportersAndOutputFiles()[0] == Catch::ConfigData::ReporterAndFile{ expectedReporter, {} }
|
||||
</Original>
|
||||
<Expanded>
|
||||
{ console, <default-output> }
|
||||
==
|
||||
{ console, <default-output> }
|
||||
</Expanded>
|
||||
</Expression>
|
||||
<OverallResults successes="9" failures="0" expectedFailures="0"/>
|
||||
</Section>
|
||||
<Section name="test lists" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
<Section name="Specify one test case using" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
|
||||
@ -20862,6 +20878,6 @@ There is no extra whitespace here
|
||||
</Section>
|
||||
<OverallResult success="true"/>
|
||||
</TestCase>
|
||||
<OverallResults successes="2054" failures="143" expectedFailures="27"/>
|
||||
<OverallResults successes="2056" failures="143" expectedFailures="27"/>
|
||||
<OverallResultsCases successes="291" failures="83" expectedFailures="7"/>
|
||||
</Catch2TestRun>
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
||||
#include <catch2/catch_user_config.hpp>
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <catch2/internal/catch_commandline.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
@ -348,10 +349,23 @@ 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.reporterSpecifications == std::vector<Catch::ConfigData::ReporterAndFile>{ {"console", {}} });
|
||||
CHECK( config.reporterSpecifications.empty() );
|
||||
|
||||
Catch::Config cfg(config);
|
||||
CHECK_FALSE(cfg.hasTestFilters());
|
||||
|
||||
// The Config is responsible for mixing in the default reporter
|
||||
auto expectedReporter =
|
||||
#if defined( CATCH_CONFIG_DEFAULT_REPORTER )
|
||||
CATCH_CONFIG_DEFAULT_REPORTER
|
||||
#else
|
||||
"console"
|
||||
#endif
|
||||
;
|
||||
|
||||
CHECK( cfg.getReportersAndOutputFiles().size() == 1 );
|
||||
CHECK( cfg.getReportersAndOutputFiles()[0] ==
|
||||
Catch::ConfigData::ReporterAndFile{ expectedReporter, {} } );
|
||||
}
|
||||
|
||||
SECTION("test lists") {
|
||||
|
Loading…
Reference in New Issue
Block a user