1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-16 07:08:01 +00:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Martin Hořeňovský
21d284df34
Session now holds Config in unique_ptr instead of shared_ptr 2020-05-20 20:25:51 +02:00
Martin Hořeňovský
668454b36b
Do not share ownership of Config in RunContext 2020-05-20 20:25:49 +02:00
Martin Hořeňovský
458241cc90
Do not use shared_ptr<Config> when listing things 2020-05-20 20:25:48 +02:00
Martin Hořeňovský
fa160cf3f2
Keep reporter pointer around in TestGroup 2020-05-20 20:25:45 +02:00
Martin Hořeňovský
a17b9f754a
Remove unused function 2020-05-20 20:25:43 +02:00
Martin Hořeňovský
c2852c9944
Remove some uses of std::shared_ptr 2020-05-20 20:25:40 +02:00
10 changed files with 40 additions and 48 deletions

View File

@ -51,7 +51,7 @@ namespace Catch {
template <typename Clock = default_clock>
void run() {
IConfigPtr cfg = getCurrentContext().getConfig();
auto const* cfg = getCurrentContext().getConfig();
auto env = Detail::measure_environment<Clock>();

View File

@ -61,10 +61,11 @@ namespace Catch {
class TestGroup {
public:
explicit TestGroup(IStreamingReporterPtr&& reporter, std::shared_ptr<Config> const& config)
: m_config{config}
, m_context{config, std::move(reporter)}
{
explicit TestGroup(IStreamingReporterPtr&& reporter, Config const* config):
m_reporter(reporter.get()),
m_config{config},
m_context{config, std::move(reporter)} {
auto const& allTestCases = getAllTestCasesSorted(*m_config);
m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config);
auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
@ -87,19 +88,19 @@ namespace Catch {
if (!m_context.aborting())
totals += m_context.runTest(*testCase);
else
m_context.reporter().skipTest(testCase->getTestCaseInfo());
m_reporter->skipTest(testCase->getTestCaseInfo());
}
for (auto const& match : m_matches) {
if (match.tests.empty()) {
m_context.reporter().noMatchingTestCases(match.name);
m_reporter->noMatchingTestCases(match.name);
totals.error = -1;
}
}
if (!invalidArgs.empty()) {
for (auto const& invalidArg: invalidArgs)
m_context.reporter().reportInvalidArguments(invalidArg);
m_reporter->reportInvalidArguments(invalidArg);
}
m_context.testGroupEnded(m_config->name(), totals, 1, 1);
@ -109,7 +110,8 @@ namespace Catch {
private:
using Tests = std::set<TestCaseHandle const*>;
std::shared_ptr<Config> m_config;
IStreamingReporter* m_reporter;
Config const* m_config;
RunContext m_context;
Tests m_tests;
TestSpec::Matches m_matches;
@ -135,7 +137,7 @@ namespace Catch {
const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
if ( !exceptions.empty() ) {
config();
getCurrentMutableContext().setConfig(m_config);
getCurrentMutableContext().setConfig(m_config.get());
m_startupExceptions = true;
Colour colourGuard( Colour::Red );
@ -179,7 +181,7 @@ namespace Catch {
auto result = m_cli.parse( clara::Args( argc, argv ) );
if( !result ) {
config();
getCurrentMutableContext().setConfig(m_config);
getCurrentMutableContext().setConfig(m_config.get());
Catch::cerr()
<< Colour( Colour::Red )
<< "\nError(s) in input:\n"
@ -250,7 +252,7 @@ namespace Catch {
}
Config& Session::config() {
if( !m_config )
m_config = std::make_shared<Config>( m_configData );
m_config = std::make_unique<Config>( m_configData );
return *m_config;
}
@ -271,15 +273,18 @@ namespace Catch {
applyFilenamesAsTags();
}
// Set up global config instance before we start calling into other functions
getCurrentMutableContext().setConfig(m_config.get());
// Create reporter(s) so we can route listings through them
auto reporter = makeReporter(m_config.get());
// Handle list request
if (list(*reporter, m_config)) {
if (list(*reporter, *m_config)) {
return 0;
}
TestGroup tests { std::move(reporter), m_config };
TestGroup tests { std::move(reporter), m_config.get() };
auto const totals = tests.execute();
if( m_config->warnAboutNoTests() && totals.error == -1 )

View File

@ -53,7 +53,7 @@ namespace Catch {
clara::Parser m_cli;
ConfigData m_configData;
std::shared_ptr<Config> m_config;
std::unique_ptr<Config> m_config;
bool m_startupExceptions = false;
};

View File

@ -105,10 +105,9 @@ namespace {
IColourImpl* platformColourInstance() {
static Win32ColourImpl s_instance;
IConfigPtr config = getCurrentContext().getConfig();
UseColour::YesOrNo colourMode = config
? config->useColour()
: UseColour::Auto;
auto const* config = getCurrentContext().getConfig();
UseColour::YesOrNo colourMode = config?
config->useColour() : UseColour::Auto;
if( colourMode == UseColour::Auto )
colourMode = UseColour::Yes;
return colourMode == UseColour::Yes
@ -179,7 +178,7 @@ namespace {
}
IColourImpl* platformColourInstance() {
ErrnoGuard guard;
IConfigPtr config = getCurrentContext().getConfig();
auto const* config = getCurrentContext().getConfig();
UseColour::YesOrNo colourMode = config
? config->useColour()
: UseColour::Auto;

View File

@ -21,7 +21,7 @@ namespace Catch {
return m_runner;
}
IConfigPtr const& getConfig() const override {
IConfig const* getConfig() const override {
return m_config;
}
@ -34,14 +34,14 @@ namespace Catch {
void setRunner( IRunner* runner ) override {
m_runner = runner;
}
void setConfig( IConfigPtr const& config ) override {
void setConfig( IConfig const* config ) override {
m_config = config;
}
friend IMutableContext& getCurrentMutableContext();
private:
IConfigPtr m_config;
IConfig const* m_config = nullptr;
IRunner* m_runner = nullptr;
IResultCapture* m_resultCapture = nullptr;
};

View File

@ -25,7 +25,7 @@ namespace Catch {
virtual IResultCapture* getResultCapture() = 0;
virtual IRunner* getRunner() = 0;
virtual IConfigPtr const& getConfig() const = 0;
virtual IConfig const* getConfig() const = 0;
};
struct IMutableContext : IContext
@ -33,7 +33,7 @@ namespace Catch {
virtual ~IMutableContext();
virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
virtual void setRunner( IRunner* runner ) = 0;
virtual void setConfig( IConfigPtr const& config ) = 0;
virtual void setConfig( IConfig const* config ) = 0;
private:
static IMutableContext *currentContext;

View File

@ -90,20 +90,19 @@ namespace Catch {
return out;
}
bool list( IStreamingReporter& reporter, std::shared_ptr<Config> const& config ) {
bool list( IStreamingReporter& reporter, Config const& config ) {
bool listed = false;
getCurrentMutableContext().setConfig( config );
if (config->listTests()) {
if (config.listTests()) {
listed = true;
listTests(reporter, *config);
listTests(reporter, config);
}
if (config->listTags()) {
if (config.listTags()) {
listed = true;
listTags(reporter, *config);
listTags(reporter, config);
}
if (config->listReporters()) {
if (config.listReporters()) {
listed = true;
listReporters(reporter, *config);
listReporters(reporter, config);
}
return listed;
}

View File

@ -31,7 +31,7 @@ namespace Catch {
std::size_t count = 0;
};
bool list( IStreamingReporter& reporter, std::shared_ptr<Config> const& config );
bool list( IStreamingReporter& reporter, Config const& config );
} // end namespace Catch

View File

@ -69,7 +69,7 @@ namespace Catch {
GeneratorTracker::~GeneratorTracker() {}
}
RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter)
RunContext::RunContext(IConfig const* _config, IStreamingReporterPtr&& reporter)
: m_runInfo(_config->name()),
m_context(getCurrentMutableContext()),
m_config(_config),
@ -78,7 +78,6 @@ namespace Catch {
m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions )
{
m_context.setRunner(this);
m_context.setConfig(m_config);
m_context.setResultCapture(this);
m_reporter->testRunStarting(m_runInfo);
}
@ -136,13 +135,6 @@ namespace Catch {
return deltaTotals;
}
IConfigPtr RunContext::config() const {
return m_config;
}
IStreamingReporter& RunContext::reporter() const {
return *m_reporter;
}
void RunContext::assertionEnded(AssertionResult const & result) {
if (result.getResultType() == ResultWas::Ok) {

View File

@ -36,7 +36,7 @@ namespace Catch {
RunContext( RunContext const& ) = delete;
RunContext& operator =( RunContext const& ) = delete;
explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter );
explicit RunContext( IConfig const* _config, IStreamingReporterPtr&& reporter );
~RunContext() override;
@ -45,9 +45,6 @@ namespace Catch {
Totals runTest(TestCaseHandle const& testCase);
IConfigPtr config() const;
IStreamingReporter& reporter() const;
public: // IResultCapture
// Assertion handlers
@ -134,7 +131,7 @@ namespace Catch {
ITracker* m_testCaseTracker = nullptr;
Option<AssertionResult> m_lastResult;
IConfigPtr m_config;
IConfig const* m_config;
Totals m_totals;
IStreamingReporterPtr m_reporter;
std::vector<MessageInfo> m_messages;