mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-29 16:53:30 +01:00
Removed "singleton" method from context
There is now a global "currentContext" - but Context itself is not aware of it
This commit is contained in:
parent
61319a9bc1
commit
9fa9d4279c
@ -51,10 +51,6 @@ namespace Catch {
|
|||||||
Context( const Context& );
|
Context( const Context& );
|
||||||
void operator=( const Context& );
|
void operator=( const Context& );
|
||||||
|
|
||||||
public: // friends
|
|
||||||
friend IContext& getCurrentContext() { return Context::getCurrent(); }
|
|
||||||
friend IMutableContext& getCurrentMutableContext() { return Context::getCurrent(); }
|
|
||||||
|
|
||||||
public: // IContext
|
public: // IContext
|
||||||
virtual IResultCapture& getResultCapture();
|
virtual IResultCapture& getResultCapture();
|
||||||
virtual IRunner& getRunner();
|
virtual IRunner& getRunner();
|
||||||
@ -72,9 +68,9 @@ namespace Catch {
|
|||||||
static std::streambuf* createStreamBuf( const std::string& streamName );
|
static std::streambuf* createStreamBuf( const std::string& streamName );
|
||||||
static void cleanUp();
|
static void cleanUp();
|
||||||
|
|
||||||
|
friend IMutableContext& getCurrentMutableContext();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Context& getCurrent();
|
|
||||||
static Context*& singleInstance();
|
|
||||||
GeneratorsForTest* findGeneratorsForCurrentTest();
|
GeneratorsForTest* findGeneratorsForCurrentTest();
|
||||||
GeneratorsForTest& getGeneratorsForCurrentTest();
|
GeneratorsForTest& getGeneratorsForCurrentTest();
|
||||||
|
|
||||||
|
@ -17,7 +17,17 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
Context* currentHub = NULL;
|
||||||
|
}
|
||||||
|
IMutableContext& getCurrentMutableContext() {
|
||||||
|
if( !currentHub )
|
||||||
|
currentHub = new Context();
|
||||||
|
return *currentHub;
|
||||||
|
}
|
||||||
|
IContext& getCurrentContext() {
|
||||||
|
return getCurrentMutableContext();
|
||||||
|
}
|
||||||
|
|
||||||
Context::Context()
|
Context::Context()
|
||||||
: m_reporterRegistry( new ReporterRegistry ),
|
: m_reporterRegistry( new ReporterRegistry ),
|
||||||
@ -25,22 +35,9 @@ namespace Catch {
|
|||||||
m_exceptionTranslatorRegistry( new ExceptionTranslatorRegistry )
|
m_exceptionTranslatorRegistry( new ExceptionTranslatorRegistry )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Context*& Context::singleInstance() {
|
|
||||||
static Context* hub = NULL;
|
|
||||||
return hub;
|
|
||||||
}
|
|
||||||
|
|
||||||
Context& Context::getCurrent() {
|
|
||||||
Context*& hub = singleInstance();
|
|
||||||
if( !hub )
|
|
||||||
hub = new Context();
|
|
||||||
return *hub;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Context::cleanUp() {
|
void Context::cleanUp() {
|
||||||
Context*& hub = singleInstance();
|
delete currentHub;
|
||||||
delete hub;
|
currentHub = NULL;
|
||||||
hub = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::setRunner( IRunner* runner ) {
|
void Context::setRunner( IRunner* runner ) {
|
||||||
@ -80,7 +77,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GeneratorsForTest* Context::findGeneratorsForCurrentTest() {
|
GeneratorsForTest* Context::findGeneratorsForCurrentTest() {
|
||||||
std::string testName = getCurrentContext().getResultCapture().getCurrentTestName();
|
std::string testName = getResultCapture().getCurrentTestName();
|
||||||
|
|
||||||
std::map<std::string, GeneratorsForTest*>::const_iterator it =
|
std::map<std::string, GeneratorsForTest*>::const_iterator it =
|
||||||
m_generatorsByTestName.find( testName );
|
m_generatorsByTestName.find( testName );
|
||||||
@ -92,7 +89,7 @@ namespace Catch {
|
|||||||
GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
|
GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
|
||||||
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
||||||
if( !generators ) {
|
if( !generators ) {
|
||||||
std::string testName = getCurrentContext().getResultCapture().getCurrentTestName();
|
std::string testName = getResultCapture().getCurrentTestName();
|
||||||
generators = new GeneratorsForTest();
|
generators = new GeneratorsForTest();
|
||||||
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user