Removed the "part" component of the tracker names

This commit is contained in:
Phil Nash 2015-10-29 19:41:50 +00:00
parent 73a140fb9e
commit 3deb3e010f

View File

@ -20,8 +20,8 @@
namespace Catch namespace Catch
{ {
struct IPartTracker : SharedImpl<> { struct ITracker : SharedImpl<> {
virtual ~IPartTracker() {} virtual ~ITracker() {}
// static queries // static queries
virtual std::string name() const = 0; virtual std::string name() const = 0;
@ -31,15 +31,15 @@ namespace Catch
virtual bool isSuccessfullyCompleted() const = 0; virtual bool isSuccessfullyCompleted() const = 0;
virtual bool isOpen() const = 0; // Started but not complete virtual bool isOpen() const = 0; // Started but not complete
virtual IPartTracker& parent() = 0; virtual ITracker& parent() = 0;
// actions // actions
virtual void close() = 0; // Successfully complete virtual void close() = 0; // Successfully complete
virtual void fail() = 0; virtual void fail() = 0;
virtual void markAsNeedingAnotherRun() = 0; virtual void markAsNeedingAnotherRun() = 0;
virtual void addChild( Ptr<IPartTracker> const& child ) = 0; virtual void addChild( Ptr<ITracker> const& child ) = 0;
virtual IPartTracker* findChild( std::string const& name ) = 0; virtual ITracker* findChild( std::string const& name ) = 0;
virtual void openChild() = 0; virtual void openChild() = 0;
}; };
@ -52,8 +52,8 @@ namespace Catch
CompletedCycle CompletedCycle
}; };
Ptr<IPartTracker> m_rootPart; Ptr<ITracker> m_rootTracker;
IPartTracker* m_currentPart; ITracker* m_currentTracker;
RunState m_runState; RunState m_runState;
public: public:
@ -64,21 +64,21 @@ namespace Catch
} }
TrackerContext() TrackerContext()
: m_currentPart( CATCH_NULL ), : m_currentTracker( CATCH_NULL ),
m_runState( NotStarted ) m_runState( NotStarted )
{} {}
IPartTracker& startRun(); ITracker& startRun();
void endRun() { void endRun() {
m_rootPart.reset(); m_rootTracker.reset();
m_currentPart = CATCH_NULL; m_currentTracker = CATCH_NULL;
m_runState = NotStarted; m_runState = NotStarted;
} }
void startCycle() { void startCycle() {
m_currentPart = m_rootPart.get(); m_currentTracker = m_rootTracker.get();
m_runState = Executing; m_runState = Executing;
} }
void completeCycle() { void completeCycle() {
@ -89,20 +89,15 @@ namespace Catch
return m_runState == CompletedCycle; return m_runState == CompletedCycle;
} }
IPartTracker& currentPart() { ITracker& currentTracker() {
return *m_currentPart; return *m_currentTracker;
} }
void setCurrentPart( IPartTracker* part ) { void setCurrentTracker( ITracker* tracker ) {
m_currentPart = part; m_currentTracker = tracker;
} }
IPartTracker* findPart( std::string const& name ) {
return m_currentPart->findChild( name );
}
}; };
class PartTrackerBase : public IPartTracker { class TrackerBase : public ITracker {
protected: protected:
enum CycleState { enum CycleState {
NotStarted, NotStarted,
@ -116,18 +111,18 @@ namespace Catch
std::string m_name; std::string m_name;
public: public:
TrackerHasName( std::string const& name ) : m_name( name ) {} TrackerHasName( std::string const& name ) : m_name( name ) {}
bool operator ()( Ptr<IPartTracker> const& tracker ) { bool operator ()( Ptr<ITracker> const& tracker ) {
return tracker->name() == m_name; return tracker->name() == m_name;
} }
}; };
typedef std::vector<Ptr<IPartTracker> > Children; typedef std::vector<Ptr<ITracker> > Children;
std::string m_name; std::string m_name;
TrackerContext& m_ctx; TrackerContext& m_ctx;
IPartTracker* m_parent; ITracker* m_parent;
Children m_children; Children m_children;
CycleState m_runState; CycleState m_runState;
public: public:
PartTrackerBase( std::string const& name, TrackerContext& ctx, IPartTracker* parent ) TrackerBase( std::string const& name, TrackerContext& ctx, ITracker* parent )
: m_name( name ), : m_name( name ),
m_ctx( ctx ), m_ctx( ctx ),
m_parent( parent ), m_parent( parent ),
@ -148,18 +143,18 @@ namespace Catch
} }
virtual void addChild( Ptr<IPartTracker> const& child ) CATCH_OVERRIDE { virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {
m_children.push_back( child ); m_children.push_back( child );
size_t childCount = m_children.size(); size_t childCount = m_children.size();
} }
virtual IPartTracker* findChild( std::string const& name ) CATCH_OVERRIDE { virtual ITracker* findChild( std::string const& name ) CATCH_OVERRIDE {
Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( name ) ); Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( name ) );
return( it != m_children.end() ) return( it != m_children.end() )
? it->get() ? it->get()
: CATCH_NULL; : CATCH_NULL;
} }
virtual IPartTracker& parent() CATCH_OVERRIDE { virtual ITracker& parent() CATCH_OVERRIDE {
assert( m_parent ); // Should always be non-null except for root assert( m_parent ); // Should always be non-null except for root
return *m_parent; return *m_parent;
} }
@ -181,8 +176,8 @@ namespace Catch
virtual void close() CATCH_OVERRIDE { virtual void close() CATCH_OVERRIDE {
// Close any still open children (e.g. generators) // Close any still open children (e.g. generators)
while( &m_ctx.currentPart() != this ) while( &m_ctx.currentTracker() != this )
m_ctx.currentPart().close(); m_ctx.currentTracker().close();
switch( m_runState ) { switch( m_runState ) {
case CompletedSuccessfully: case CompletedSuccessfully:
@ -219,31 +214,31 @@ namespace Catch
private: private:
void moveToParent() { void moveToParent() {
assert( m_parent ); assert( m_parent );
m_ctx.setCurrentPart( m_parent ); m_ctx.setCurrentTracker( m_parent );
} }
void moveToThis() { void moveToThis() {
m_ctx.setCurrentPart( this ); m_ctx.setCurrentTracker( this );
} }
}; };
class SectionTracker : public PartTrackerBase { class SectionTracker : public TrackerBase {
public: public:
SectionTracker( std::string const& name, TrackerContext& ctx, IPartTracker* parent ) SectionTracker( std::string const& name, TrackerContext& ctx, ITracker* parent )
: PartTrackerBase( name, ctx, parent ) : TrackerBase( name, ctx, parent )
{} {}
static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) { static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) {
SectionTracker* section = CATCH_NULL; SectionTracker* section = CATCH_NULL;
IPartTracker& currentPart = ctx.currentPart(); ITracker& currentTracker = ctx.currentTracker();
if( IPartTracker* part = currentPart.findChild( name ) ) { if( ITracker* childTracker = currentTracker.findChild( name ) ) {
section = dynamic_cast<SectionTracker*>( part ); section = dynamic_cast<SectionTracker*>( childTracker );
assert( section ); assert( section );
} }
else { else {
section = new SectionTracker( name, ctx, &currentPart ); section = new SectionTracker( name, ctx, &currentTracker );
currentPart.addChild( section ); currentTracker.addChild( section );
} }
if( !ctx.completedCycle() && !section->isComplete() ) { if( !ctx.completedCycle() && !section->isComplete() ) {
@ -253,12 +248,12 @@ namespace Catch
} }
}; };
class IndexTracker : public PartTrackerBase { class IndexTracker : public TrackerBase {
int m_size; int m_size;
int m_index; int m_index;
public: public:
IndexTracker( std::string const& name, TrackerContext& ctx, IPartTracker* parent, int size ) IndexTracker( std::string const& name, TrackerContext& ctx, ITracker* parent, int size )
: PartTrackerBase( name, ctx, parent ), : TrackerBase( name, ctx, parent ),
m_size( size ), m_size( size ),
m_index( -1 ) m_index( -1 )
{} {}
@ -266,14 +261,14 @@ namespace Catch
static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) { static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) {
IndexTracker* tracker = CATCH_NULL; IndexTracker* tracker = CATCH_NULL;
IPartTracker& currentPart = ctx.currentPart(); ITracker& currentTracker = ctx.currentTracker();
if( IPartTracker* part = currentPart.findChild( name ) ) { if( ITracker* childTracker = currentTracker.findChild( name ) ) {
tracker = dynamic_cast<IndexTracker*>( part ); tracker = dynamic_cast<IndexTracker*>( childTracker );
assert( tracker ); assert( tracker );
} }
else { else {
tracker = new IndexTracker( name, ctx, &currentPart, size ); tracker = new IndexTracker( name, ctx, &currentTracker, size );
currentPart.addChild( tracker ); currentTracker.addChild( tracker );
} }
if( !ctx.completedCycle() && !tracker->isComplete() ) { if( !ctx.completedCycle() && !tracker->isComplete() ) {
@ -293,18 +288,18 @@ namespace Catch
} }
virtual void close() CATCH_OVERRIDE { virtual void close() CATCH_OVERRIDE {
PartTrackerBase::close(); TrackerBase::close();
if( m_runState == CompletedSuccessfully ) if( m_runState == CompletedSuccessfully )
if( m_index < m_size-1 ) if( m_index < m_size-1 )
m_runState = Executing; m_runState = Executing;
} }
}; };
IPartTracker& TrackerContext::startRun() { ITracker& TrackerContext::startRun() {
m_rootPart = new SectionTracker( "{root}", *this, CATCH_NULL ); m_rootTracker = new SectionTracker( "{root}", *this, CATCH_NULL );
m_currentPart = CATCH_NULL; m_currentTracker = CATCH_NULL;
m_runState = Executing; m_runState = Executing;
return *m_rootPart; return *m_rootTracker;
} }
class LocalContext { class LocalContext {
@ -332,16 +327,16 @@ inline void testCase( Catch::LocalContext const& C_A_T_C_H_Context ) {
// REQUIRE( C_A_T_C_H_Context().i() == 42 ); // REQUIRE( C_A_T_C_H_Context().i() == 42 );
} }
TEST_CASE( "PartTracker" ) { TEST_CASE( "Tracker" ) {
TrackerContext ctx; TrackerContext ctx;
ctx.startRun(); ctx.startRun();
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase.isOpen() ); REQUIRE( testCase.isOpen() );
IPartTracker& s1 = SectionTracker::acquire( ctx, "S1" ); ITracker& s1 = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1.isOpen() ); REQUIRE( s1.isOpen() );
SECTION( "successfully close one section" ) { SECTION( "successfully close one section" ) {
@ -366,10 +361,10 @@ TEST_CASE( "PartTracker" ) {
SECTION( "re-enter after failed section" ) { SECTION( "re-enter after failed section" ) {
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase2.isOpen() ); REQUIRE( testCase2.isOpen() );
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" ); ITracker& s1b = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1b.isOpen() == false ); REQUIRE( s1b.isOpen() == false );
testCase2.close(); testCase2.close();
@ -379,13 +374,13 @@ TEST_CASE( "PartTracker" ) {
} }
SECTION( "re-enter after failed section and find next section" ) { SECTION( "re-enter after failed section and find next section" ) {
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase2.isOpen() ); REQUIRE( testCase2.isOpen() );
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" ); ITracker& s1b = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1b.isOpen() == false ); REQUIRE( s1b.isOpen() == false );
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" ); ITracker& s2 = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2.isOpen() ); REQUIRE( s2.isOpen() );
s2.close(); s2.close();
@ -400,7 +395,7 @@ TEST_CASE( "PartTracker" ) {
SECTION( "successfully close one section, then find another" ) { SECTION( "successfully close one section, then find another" ) {
s1.close(); s1.close();
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" ); ITracker& s2 = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2.isOpen() == false ); REQUIRE( s2.isOpen() == false );
testCase.close(); testCase.close();
@ -408,13 +403,13 @@ TEST_CASE( "PartTracker" ) {
SECTION( "Re-enter - skips S1 and enters S2" ) { SECTION( "Re-enter - skips S1 and enters S2" ) {
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase2.isOpen() ); REQUIRE( testCase2.isOpen() );
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" ); ITracker& s1b = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1b.isOpen() == false ); REQUIRE( s1b.isOpen() == false );
IPartTracker& s2b = SectionTracker::acquire( ctx, "S2" ); ITracker& s2b = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2b.isOpen() ); REQUIRE( s2b.isOpen() );
REQUIRE( ctx.completedCycle() == false ); REQUIRE( ctx.completedCycle() == false );
@ -441,13 +436,13 @@ TEST_CASE( "PartTracker" ) {
// Need a final cycle // Need a final cycle
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase3 = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase3 = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase3.isOpen() ); REQUIRE( testCase3.isOpen() );
IPartTracker& s1c = SectionTracker::acquire( ctx, "S1" ); ITracker& s1c = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1c.isOpen() == false ); REQUIRE( s1c.isOpen() == false );
IPartTracker& s2c = SectionTracker::acquire( ctx, "S2" ); ITracker& s2c = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2c.isOpen() == false ); REQUIRE( s2c.isOpen() == false );
testCase3.close(); testCase3.close();
@ -457,7 +452,7 @@ TEST_CASE( "PartTracker" ) {
} }
SECTION( "open a nested section" ) { SECTION( "open a nested section" ) {
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" ); ITracker& s2 = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2.isOpen() ); REQUIRE( s2.isOpen() );
s2.close(); s2.close();
@ -489,10 +484,10 @@ TEST_CASE( "PartTracker" ) {
SECTION( "Re-enter for second generation" ) { SECTION( "Re-enter for second generation" ) {
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase2.isOpen() ); REQUIRE( testCase2.isOpen() );
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" ); ITracker& s1b = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1b.isOpen() ); REQUIRE( s1b.isOpen() );
@ -510,7 +505,7 @@ TEST_CASE( "PartTracker" ) {
} }
} }
SECTION( "Start a new inner section" ) { SECTION( "Start a new inner section" ) {
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" ); ITracker& s2 = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2.isOpen() ); REQUIRE( s2.isOpen() );
s2.close(); s2.close();
@ -524,10 +519,10 @@ TEST_CASE( "PartTracker" ) {
SECTION( "Re-enter for second generation" ) { SECTION( "Re-enter for second generation" ) {
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase2.isOpen() ); REQUIRE( testCase2.isOpen() );
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" ); ITracker& s1b = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1b.isOpen() ); REQUIRE( s1b.isOpen() );
// generator - next value // generator - next value
@ -536,7 +531,7 @@ TEST_CASE( "PartTracker" ) {
REQUIRE( g1b.index() == 1 ); REQUIRE( g1b.index() == 1 );
// inner section again // inner section again
IPartTracker& s2b = SectionTracker::acquire( ctx, "S2" ); ITracker& s2b = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2b.isOpen() ); REQUIRE( s2b.isOpen() );
s2b.close(); s2b.close();
@ -552,7 +547,7 @@ TEST_CASE( "PartTracker" ) {
} }
SECTION( "Fail an inner section" ) { SECTION( "Fail an inner section" ) {
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" ); ITracker& s2 = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2.isOpen() ); REQUIRE( s2.isOpen() );
s2.fail(); s2.fail();
@ -567,10 +562,10 @@ TEST_CASE( "PartTracker" ) {
SECTION( "Re-enter for second generation" ) { SECTION( "Re-enter for second generation" ) {
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase2.isOpen() ); REQUIRE( testCase2.isOpen() );
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" ); ITracker& s1b = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1b.isOpen() ); REQUIRE( s1b.isOpen() );
// generator - still same value // generator - still same value
@ -579,7 +574,7 @@ TEST_CASE( "PartTracker" ) {
REQUIRE( g1b.index() == 0 ); REQUIRE( g1b.index() == 0 );
// inner section again - this time won't open // inner section again - this time won't open
IPartTracker& s2b = SectionTracker::acquire( ctx, "S2" ); ITracker& s2b = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2b.isOpen() == false ); REQUIRE( s2b.isOpen() == false );
s1b.close(); s1b.close();
@ -591,10 +586,10 @@ TEST_CASE( "PartTracker" ) {
// Another cycle - now should complete // Another cycle - now should complete
ctx.startCycle(); ctx.startCycle();
IPartTracker& testCase3 = SectionTracker::acquire( ctx, "Testcase" ); ITracker& testCase3 = SectionTracker::acquire( ctx, "Testcase" );
REQUIRE( testCase3.isOpen() ); REQUIRE( testCase3.isOpen() );
IPartTracker& s1c = SectionTracker::acquire( ctx, "S1" ); ITracker& s1c = SectionTracker::acquire( ctx, "S1" );
REQUIRE( s1c.isOpen() ); REQUIRE( s1c.isOpen() );
// generator - now next value // generator - now next value
@ -603,7 +598,7 @@ TEST_CASE( "PartTracker" ) {
REQUIRE( g1c.index() == 1 ); REQUIRE( g1c.index() == 1 );
// inner section - now should open again // inner section - now should open again
IPartTracker& s2c = SectionTracker::acquire( ctx, "S2" ); ITracker& s2c = SectionTracker::acquire( ctx, "S2" );
REQUIRE( s2c.isOpen() ); REQUIRE( s2c.isOpen() );
s2c.close(); s2c.close();