mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-04 06:15:41 +02: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:
@@ -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() )
|
||||
|
Reference in New Issue
Block a user