mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-03 13:55:39 +02:00
Introduce type to handle reporter specs with defaults filled-in
This commit is contained in:
@@ -18,6 +18,14 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
bool operator==( ProcessedReporterSpec const& lhs,
|
||||
ProcessedReporterSpec const& rhs ) {
|
||||
return lhs.name == rhs.name &&
|
||||
lhs.outputFilename == rhs.outputFilename &&
|
||||
lhs.colourMode == rhs.colourMode &&
|
||||
lhs.customOptions == rhs.customOptions;
|
||||
}
|
||||
|
||||
Config::Config( ConfigData const& data ):
|
||||
m_data( data ) {
|
||||
// We need to trim filter specs to avoid trouble with superfluous
|
||||
@@ -80,25 +88,23 @@ namespace Catch {
|
||||
// We now fixup the reporter specs to handle default output spec,
|
||||
// default colour spec, etc
|
||||
bool defaultOutputUsed = false;
|
||||
for ( auto& reporterSpec : m_data.reporterSpecifications ) {
|
||||
for ( auto const& reporterSpec : m_data.reporterSpecifications ) {
|
||||
// We do the default-output check separately, while always
|
||||
// using the default output below to make the code simpler
|
||||
// and avoid superfluous copies.
|
||||
if ( reporterSpec.outputFile().none() ) {
|
||||
CATCH_ENFORCE( !defaultOutputUsed,
|
||||
"Internal error: cannot use default output for "
|
||||
"multiple reporters" );
|
||||
defaultOutputUsed = true;
|
||||
|
||||
reporterSpec = ReporterSpec{ reporterSpec.name(),
|
||||
data.defaultOutputFilename,
|
||||
reporterSpec.colourMode(),
|
||||
reporterSpec.customOptions() };
|
||||
}
|
||||
|
||||
if ( reporterSpec.colourMode().none() ) {
|
||||
reporterSpec = ReporterSpec{ reporterSpec.name(),
|
||||
reporterSpec.outputFile(),
|
||||
data.defaultColourMode,
|
||||
reporterSpec.customOptions() };
|
||||
}
|
||||
m_processedReporterSpecs.push_back( ProcessedReporterSpec{
|
||||
reporterSpec.name(),
|
||||
reporterSpec.outputFile() ? *reporterSpec.outputFile()
|
||||
: data.defaultOutputFilename,
|
||||
reporterSpec.colourMode().valueOr( data.defaultColourMode ),
|
||||
reporterSpec.customOptions() } );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +122,11 @@ namespace Catch {
|
||||
return m_data.reporterSpecifications;
|
||||
}
|
||||
|
||||
std::vector<ProcessedReporterSpec> const&
|
||||
Config::getProcessedReporterSpecs() const {
|
||||
return m_processedReporterSpecs;
|
||||
}
|
||||
|
||||
TestSpec const& Config::testSpec() const { return m_testSpec; }
|
||||
bool Config::hasTestFilters() const { return m_hasTestFilters; }
|
||||
|
||||
|
@@ -24,6 +24,24 @@ namespace Catch {
|
||||
|
||||
class IStream;
|
||||
|
||||
/**
|
||||
* `ReporterSpec` but with the defaults filled in.
|
||||
*
|
||||
* Like `ReporterSpec`, the semantics are unchecked.
|
||||
*/
|
||||
struct ProcessedReporterSpec {
|
||||
std::string name;
|
||||
std::string outputFilename;
|
||||
ColourMode colourMode;
|
||||
std::map<std::string, std::string> customOptions;
|
||||
friend bool operator==( ProcessedReporterSpec const& lhs,
|
||||
ProcessedReporterSpec const& rhs );
|
||||
friend bool operator!=( ProcessedReporterSpec const& lhs,
|
||||
ProcessedReporterSpec const& rhs ) {
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
};
|
||||
|
||||
struct ConfigData {
|
||||
|
||||
bool listTests = false;
|
||||
@@ -81,6 +99,8 @@ namespace Catch {
|
||||
bool listReporters() const;
|
||||
|
||||
std::vector<ReporterSpec> const& getReporterSpecs() const;
|
||||
std::vector<ProcessedReporterSpec> const&
|
||||
getProcessedReporterSpecs() const;
|
||||
|
||||
std::vector<std::string> const& getTestsOrTags() const override;
|
||||
std::vector<std::string> const& getSectionsToRun() const override;
|
||||
@@ -116,6 +136,7 @@ namespace Catch {
|
||||
|
||||
private:
|
||||
ConfigData m_data;
|
||||
std::vector<ProcessedReporterSpec> m_processedReporterSpecs;
|
||||
TestSpec m_testSpec;
|
||||
bool m_hasTestFilters = false;
|
||||
};
|
||||
|
@@ -43,15 +43,14 @@ namespace Catch {
|
||||
|
||||
IEventListenerPtr prepareReporters(Config const* config) {
|
||||
if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()
|
||||
&& config->getReporterSpecs().size() == 1) {
|
||||
auto const& spec = config->getReporterSpecs()[0];
|
||||
&& config->getProcessedReporterSpecs().size() == 1) {
|
||||
auto const& spec = config->getProcessedReporterSpecs()[0];
|
||||
return createReporter(
|
||||
spec.name(),
|
||||
ReporterConfig(
|
||||
config,
|
||||
makeStream(*spec.outputFile()),
|
||||
*spec.colourMode(),
|
||||
spec.customOptions() ) );
|
||||
spec.name,
|
||||
ReporterConfig( config,
|
||||
makeStream( spec.outputFilename ),
|
||||
spec.colourMode,
|
||||
spec.customOptions ) );
|
||||
}
|
||||
|
||||
auto multi = Detail::make_unique<MultiReporter>(config);
|
||||
@@ -62,13 +61,13 @@ namespace Catch {
|
||||
}
|
||||
|
||||
std::size_t reporterIdx = 0;
|
||||
for (auto const& reporterSpec : config->getReporterSpecs()) {
|
||||
for ( auto const& reporterSpec : config->getProcessedReporterSpecs() ) {
|
||||
multi->addReporter( createReporter(
|
||||
reporterSpec.name(),
|
||||
reporterSpec.name,
|
||||
ReporterConfig( config,
|
||||
makeStream( *reporterSpec.outputFile() ),
|
||||
*reporterSpec.colourMode(),
|
||||
reporterSpec.customOptions() ) ) );
|
||||
makeStream( reporterSpec.outputFilename ),
|
||||
reporterSpec.colourMode,
|
||||
reporterSpec.customOptions ) ) );
|
||||
reporterIdx++;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user