mirror of
https://github.com/catchorg/Catch2.git
synced 2025-01-16 07:08:01 +00:00
Compare commits
6 Commits
4394d3ae65
...
21d284df34
Author | SHA1 | Date | |
---|---|---|---|
|
21d284df34 | ||
|
668454b36b | ||
|
458241cc90 | ||
|
fa160cf3f2 | ||
|
a17b9f754a | ||
|
c2852c9944 |
@ -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>();
|
||||
|
||||
|
@ -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 )
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user