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

@@ -54,14 +54,12 @@ namespace Catch {
std::string outputFilename;
std::string name;
std::string processName;
#ifndef CATCH_CONFIG_DEFAULT_REPORTER
#define CATCH_CONFIG_DEFAULT_REPORTER "console"
#endif
std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER;
#undef CATCH_CONFIG_DEFAULT_REPORTER
std::vector<std::string> testsOrTags;
std::vector<std::string> sectionsToRun;
};

View File

@@ -6,7 +6,7 @@
*/
#include "catch_interfaces_reporter.h"
#include "../reporters/catch_reporter_multi.h"
#include "../reporters/catch_reporter_listening.h"
namespace Catch {
@@ -111,25 +111,4 @@ namespace Catch {
IReporterFactory::~IReporterFactory() = default;
IReporterRegistry::~IReporterRegistry() = default;
void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) {
if( !existingReporter ) {
existingReporter = std::move( additionalReporter );
return;
}
MultipleReporters* multi = nullptr;
if( existingReporter->isMulti() ) {
multi = static_cast<MultipleReporters*>( existingReporter.get() );
}
else {
auto newMulti = std::unique_ptr<MultipleReporters>( new MultipleReporters );
newMulti->add( std::move( existingReporter ) );
multi = newMulti.get();
existingReporter = std::move( newMulti );
}
multi->add( std::move( additionalReporter ) );
}
} // end namespace Catch

View File

@@ -226,8 +226,6 @@ namespace Catch {
virtual Listeners const& getListeners() const = 0;
};
void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter );
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED

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));