diff options
| author | Martin Jeřábek | 2021-02-06 20:12:07 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-01-01 14:02:23 +0100 |
| commit | ccd67b293d7595a0cf2dc6c4bfb2017fc18c1f14 (patch) | |
| tree | ba5f166d1cf867ad97617656083354fbddfc5d9f /src/catch2/catch_session.cpp | |
| parent | 6b55f5d780c5d8e935720f9d7d8ed28a3ba8617f (diff) | |
| download | catch3-ccd67b293d7595a0cf2dc6c4bfb2017fc18c1f14.tar.gz | |
Add support for multiple parallel reporters
This requires a bunch of different changes across the reporter
subsystem.
* We need to handle multiple reporters and their differing
preferences in `ListeningReporter`, e.g. what to do when
we mix reporters that capture and don't capture stdout.
* We need to change how the reporter is given output and
how we parse reporter's output destination from CLI.
* Approval tests need to handle multireporter option
Diffstat (limited to 'src/catch2/catch_session.cpp')
| -rw-r--r-- | src/catch2/catch_session.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp index 38111fe8..2325bf2f 100644 --- a/src/catch2/catch_session.cpp +++ b/src/catch2/catch_session.cpp @@ -34,7 +34,7 @@ namespace Catch { namespace { const int MaxExitCode = 255; - IStreamingReporterPtr createReporter(std::string const& reporterName, IConfig const* config) { + IStreamingReporterPtr createReporter(std::string const& reporterName, ReporterConfig const& config) { auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config); CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << '\''); @@ -42,16 +42,26 @@ namespace Catch { } IStreamingReporterPtr makeReporter(Config const* config) { - if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) { - return createReporter(config->getReporterName(), config); + if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty() + && config->getReportersAndOutputFiles().size() == 1) { + auto& stream = config->getReporterOutputStream(0); + return createReporter(config->getReportersAndOutputFiles()[0].reporterName, ReporterConfig(config, stream)); } auto multi = Detail::make_unique<ListeningReporter>(config); + auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); for (auto const& listener : listeners) { - multi->addListener(listener->create(Catch::ReporterConfig(config))); + multi->addListener(listener->create(Catch::ReporterConfig(config, config->defaultStream()))); + } + + std::size_t reporterIdx = 0; + for (auto const& reporterAndFile : config->getReportersAndOutputFiles()) { + auto& stream = config->getReporterOutputStream(reporterIdx); + multi->addReporter(createReporter(reporterAndFile.reporterName, ReporterConfig(config, stream))); + reporterIdx++; } - multi->addReporter(createReporter(config->getReporterName(), config)); + return multi; } |