Call listeners before calling reporters

Catch2's documentation promises that listeners are called _before_
reporters, but because of the previous implementation, they were
called _after_ reporters. This commit fixes that.

Closes #1234
This commit is contained in:
Martin Hořeňovský 2018-04-07 11:42:24 +02:00
parent 414dcae34a
commit f00257e374
8 changed files with 157 additions and 143 deletions

View file

@ -20,6 +20,7 @@
#include "catch_text.h"
#include "catch_stream.h"
#include "catch_windows_h_proxy.h"
#include "../reporters/catch_reporter_listening.h"
#include <cstdlib>
#include <iomanip>
@ -36,22 +37,26 @@ namespace Catch {
return reporter;
}
IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
return createReporter(config->getReporterName(), config);
}
if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) {
return createReporter(config->getReporterName(), config);
}
auto multi = std::unique_ptr<ListeningReporter>(new ListeningReporter);
void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) {
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
for (auto const& listener : listeners)
addReporter(reporters, listener->create(Catch::ReporterConfig(config)));
for (auto const& listener : listeners) {
multi->addListener(listener->create(Catch::ReporterConfig(config)));
}
multi->addReporter(createReporter(config->getReporterName(), config));
return std::move(multi);
}
Catch::Totals runTests(std::shared_ptr<Config> const& config) {
IStreamingReporterPtr reporter = makeReporter(config);
addListeners(reporter, config);
// FixMe: Add listeners in order first, then add reporters.
auto reporter = makeReporter(config);
RunContext context(config, std::move(reporter));