Introduce type to handle reporter specs with defaults filled-in

This commit is contained in:
Martin Hořeňovský
2022-04-13 15:02:25 +02:00
parent 79d1e82381
commit a243cbae52
15 changed files with 146 additions and 48 deletions
+23 -12
View File
@@ -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; }