mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
More name changes
This commit is contained in:
parent
2c6411e70a
commit
9a6a0865f2
@ -20,24 +20,24 @@
|
|||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
struct ITrackedPart : SharedImpl<> {
|
struct IPartTracker : SharedImpl<> {
|
||||||
virtual ~ITrackedPart() {}
|
virtual ~IPartTracker() {}
|
||||||
|
|
||||||
// queries
|
// queries
|
||||||
virtual std::string name() const = 0;
|
virtual std::string name() const = 0;
|
||||||
virtual bool hasStarted() const = 0; // true even if ended
|
virtual bool hasStarted() const = 0; // true even if ended
|
||||||
virtual bool hasEnded() const = 0;
|
virtual bool hasEnded() const = 0;
|
||||||
virtual bool didCompleteSuccessfully() const = 0;
|
virtual bool isSuccessfullyCompleted() const = 0;
|
||||||
virtual bool isOpen() const = 0;
|
virtual bool isOpen() const = 0;
|
||||||
|
|
||||||
virtual ITrackedPart& parent() = 0;
|
virtual IPartTracker& parent() = 0;
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
virtual void close() = 0;
|
virtual void close() = 0;
|
||||||
virtual void fail() = 0;
|
virtual void fail() = 0;
|
||||||
|
|
||||||
virtual void addChild( Ptr<ITrackedPart> const& child ) = 0;
|
virtual void addChild( Ptr<IPartTracker> const& child ) = 0;
|
||||||
virtual ITrackedPart* findChild( std::string const& name ) = 0;
|
virtual IPartTracker* findChild( std::string const& name ) = 0;
|
||||||
virtual void openChild() = 0;
|
virtual void openChild() = 0;
|
||||||
virtual void childFailed() = 0;
|
virtual void childFailed() = 0;
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ namespace Catch
|
|||||||
CompletedCycle
|
CompletedCycle
|
||||||
};
|
};
|
||||||
|
|
||||||
Ptr<ITrackedPart> m_rootPart;
|
Ptr<IPartTracker> m_rootPart;
|
||||||
ITrackedPart* m_currentPart;
|
IPartTracker* m_currentPart;
|
||||||
RunState m_runState;
|
RunState m_runState;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -69,7 +69,7 @@ namespace Catch
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
ITrackedPart& startRun();
|
IPartTracker& startRun();
|
||||||
|
|
||||||
void endRun() {
|
void endRun() {
|
||||||
m_rootPart.reset();
|
m_rootPart.reset();
|
||||||
@ -89,21 +89,20 @@ namespace Catch
|
|||||||
return m_runState == CompletedCycle;
|
return m_runState == CompletedCycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITrackedPart& currentPart() {
|
IPartTracker& currentPart() {
|
||||||
return *m_currentPart;
|
return *m_currentPart;
|
||||||
}
|
}
|
||||||
void setCurrentPart( ITrackedPart* part ) {
|
void setCurrentPart( IPartTracker* part ) {
|
||||||
m_currentPart = part;
|
m_currentPart = part;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITrackedPart* findPart( std::string const& name ) {
|
IPartTracker* findPart( std::string const& name ) {
|
||||||
return m_currentPart->findChild( name );
|
return m_currentPart->findChild( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class SectionTracker : public ITrackedPart {
|
class PartTrackerBase : public IPartTracker {
|
||||||
enum RunState {
|
enum RunState {
|
||||||
NotStarted,
|
NotStarted,
|
||||||
Executing,
|
Executing,
|
||||||
@ -116,18 +115,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<ITrackedPart> const& tracker ) {
|
bool operator ()( Ptr<IPartTracker> const& tracker ) {
|
||||||
return tracker->name() == m_name;
|
return tracker->name() == m_name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
typedef std::vector<Ptr<ITrackedPart> > Children;
|
typedef std::vector<Ptr<IPartTracker> > Children;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
TrackerContext& m_ctx;
|
TrackerContext& m_ctx;
|
||||||
ITrackedPart* m_parent;
|
IPartTracker* m_parent;
|
||||||
Children m_children;
|
Children m_children;
|
||||||
RunState m_runState;
|
RunState m_runState;
|
||||||
public:
|
public:
|
||||||
SectionTracker( std::string const& name, TrackerContext& ctx, ITrackedPart* parent )
|
PartTrackerBase( std::string const& name, TrackerContext& ctx, IPartTracker* parent )
|
||||||
: m_name( name ),
|
: m_name( name ),
|
||||||
m_ctx( ctx ),
|
m_ctx( ctx ),
|
||||||
m_parent( parent ),
|
m_parent( parent ),
|
||||||
@ -140,7 +139,7 @@ namespace Catch
|
|||||||
virtual bool hasEnded() const CATCH_OVERRIDE {
|
virtual bool hasEnded() const CATCH_OVERRIDE {
|
||||||
return m_runState == CompletedSuccessfully || m_runState == Failed;
|
return m_runState == CompletedSuccessfully || m_runState == Failed;
|
||||||
}
|
}
|
||||||
virtual bool didCompleteSuccessfully() const CATCH_OVERRIDE {
|
virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE {
|
||||||
return m_runState == CompletedSuccessfully;
|
return m_runState == CompletedSuccessfully;
|
||||||
}
|
}
|
||||||
virtual bool hasStarted() const CATCH_OVERRIDE {
|
virtual bool hasStarted() const CATCH_OVERRIDE {
|
||||||
@ -151,18 +150,18 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void addChild( Ptr<ITrackedPart> const& child ) CATCH_OVERRIDE {
|
virtual void addChild( Ptr<IPartTracker> 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 ITrackedPart* findChild( std::string const& name ) CATCH_OVERRIDE {
|
virtual IPartTracker* 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 ITrackedPart& parent() CATCH_OVERRIDE {
|
virtual IPartTracker& 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;
|
||||||
}
|
}
|
||||||
@ -225,37 +224,24 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ITrackedPart& TrackerContext::startRun() {
|
|
||||||
m_rootPart = new SectionTracker( "{root}", *this, CATCH_NULL );
|
|
||||||
m_currentPart = CATCH_NULL;
|
|
||||||
m_runState = Executing;
|
|
||||||
return *m_rootPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
class LocalContext {
|
|
||||||
|
|
||||||
public:
|
|
||||||
TrackerContext& operator()() const {
|
|
||||||
return TrackerContext::instance();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class SectionPart : public SectionTracker {
|
class SectionTracker : public PartTrackerBase {
|
||||||
public:
|
public:
|
||||||
SectionPart( std::string const& name, TrackerContext& ctx, ITrackedPart* parent )
|
SectionTracker( std::string const& name, TrackerContext& ctx, IPartTracker* parent )
|
||||||
: SectionTracker( name, ctx, parent )
|
: PartTrackerBase( name, ctx, parent )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
static SectionPart& acquire( TrackerContext& ctx, std::string const& name ) {
|
static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) {
|
||||||
SectionPart* section = CATCH_NULL;
|
SectionTracker* section = CATCH_NULL;
|
||||||
|
|
||||||
ITrackedPart& currentPart = ctx.currentPart();
|
IPartTracker& currentPart = ctx.currentPart();
|
||||||
if( ITrackedPart* part = currentPart.findChild( name ) ) {
|
if( IPartTracker* part = currentPart.findChild( name ) ) {
|
||||||
section = dynamic_cast<SectionPart*>( part );
|
section = dynamic_cast<SectionTracker*>( part );
|
||||||
assert( section );
|
assert( section );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
section = new SectionPart( name, ctx, ¤tPart );
|
section = new SectionTracker( name, ctx, ¤tPart );
|
||||||
currentPart.addChild( section );
|
currentPart.addChild( section );
|
||||||
}
|
}
|
||||||
if( !ctx.completedCycle() && !section->hasEnded() ) {
|
if( !ctx.completedCycle() && !section->hasEnded() ) {
|
||||||
@ -265,6 +251,21 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IPartTracker& TrackerContext::startRun() {
|
||||||
|
m_rootPart = new SectionTracker( "{root}", *this, CATCH_NULL );
|
||||||
|
m_currentPart = CATCH_NULL;
|
||||||
|
m_runState = Executing;
|
||||||
|
return *m_rootPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocalContext {
|
||||||
|
|
||||||
|
public:
|
||||||
|
TrackerContext& operator()() const {
|
||||||
|
return TrackerContext::instance();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
inline Catch::TrackerContext& C_A_T_C_H_Context() {
|
inline Catch::TrackerContext& C_A_T_C_H_Context() {
|
||||||
@ -288,62 +289,63 @@ TEST_CASE( "PartTracker" ) {
|
|||||||
ctx.startRun();
|
ctx.startRun();
|
||||||
ctx.startCycle();
|
ctx.startCycle();
|
||||||
|
|
||||||
SectionPart& testCase = SectionPart::acquire( ctx, "Testcase" );
|
IPartTracker& testCase = SectionTracker::acquire( ctx, "Testcase" );
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == false );
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
SectionPart& s1 = SectionPart::acquire( ctx, "S1" );
|
IPartTracker& s1 = SectionTracker::acquire( ctx, "S1" );
|
||||||
REQUIRE( s1.didCompleteSuccessfully() == false );
|
REQUIRE( s1.isOpen() == true );
|
||||||
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
SECTION( "successfully close one section" ) {
|
SECTION( "successfully close one section" ) {
|
||||||
s1.close();
|
s1.close();
|
||||||
REQUIRE( s1.didCompleteSuccessfully() == true );
|
REQUIRE( s1.isSuccessfullyCompleted() == true );
|
||||||
REQUIRE( testCase.hasEnded() == false );
|
REQUIRE( testCase.hasEnded() == false );
|
||||||
|
|
||||||
testCase.close();
|
testCase.close();
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == true );
|
REQUIRE( testCase.isSuccessfullyCompleted() == true );
|
||||||
|
|
||||||
REQUIRE( ctx.completedCycle() == true );
|
REQUIRE( ctx.completedCycle() == true );
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "fail one section" ) {
|
SECTION( "fail one section" ) {
|
||||||
s1.fail();
|
s1.fail();
|
||||||
REQUIRE( s1.didCompleteSuccessfully() == false );
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
||||||
REQUIRE( s1.hasEnded() == true );
|
REQUIRE( s1.hasEnded() == true );
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == false );
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
||||||
REQUIRE( testCase.hasEnded() == false );
|
REQUIRE( testCase.hasEnded() == false );
|
||||||
|
|
||||||
testCase.close();
|
testCase.close();
|
||||||
REQUIRE( ctx.completedCycle() == true );
|
REQUIRE( ctx.completedCycle() == true );
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == false );
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
SECTION( "re-enter after failed section" ) {
|
SECTION( "re-enter after failed section" ) {
|
||||||
ctx.startCycle();
|
ctx.startCycle();
|
||||||
SectionPart& testCase2 = SectionPart::acquire( ctx, "Testcase" );
|
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
|
||||||
REQUIRE( testCase2.didCompleteSuccessfully() == false );
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
SectionPart& s1b = SectionPart::acquire( ctx, "S1" );
|
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" );
|
||||||
REQUIRE( s1b.didCompleteSuccessfully() == false );
|
REQUIRE( s1b.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
testCase2.close();
|
testCase2.close();
|
||||||
REQUIRE( ctx.completedCycle() == true );
|
REQUIRE( ctx.completedCycle() == true );
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == true );
|
REQUIRE( testCase.isSuccessfullyCompleted() == true );
|
||||||
REQUIRE( testCase.hasEnded() == true );
|
REQUIRE( testCase.hasEnded() == true );
|
||||||
}
|
}
|
||||||
SECTION( "re-enter after failed section and find next section" ) {
|
SECTION( "re-enter after failed section and find next section" ) {
|
||||||
ctx.startCycle();
|
ctx.startCycle();
|
||||||
SectionPart& testCase2 = SectionPart::acquire( ctx, "Testcase" );
|
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
|
||||||
REQUIRE( testCase2.didCompleteSuccessfully() == false );
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
SectionPart& s1b = SectionPart::acquire( ctx, "S1" );
|
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" );
|
||||||
REQUIRE( s1b.didCompleteSuccessfully() == false );
|
REQUIRE( s1b.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
SectionPart& s2 = SectionPart::acquire( ctx, "S2" );
|
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" );
|
||||||
REQUIRE( s2.isOpen() );
|
REQUIRE( s2.isOpen() );
|
||||||
s2.close();
|
s2.close();
|
||||||
REQUIRE( ctx.completedCycle() == true );
|
REQUIRE( ctx.completedCycle() == true );
|
||||||
|
|
||||||
testCase2.close();
|
testCase2.close();
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == true );
|
REQUIRE( testCase.isSuccessfullyCompleted() == true );
|
||||||
REQUIRE( testCase.hasEnded() == true );
|
REQUIRE( testCase.hasEnded() == true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,24 +354,25 @@ TEST_CASE( "PartTracker" ) {
|
|||||||
s1.close();
|
s1.close();
|
||||||
REQUIRE( ctx.completedCycle() == true );
|
REQUIRE( ctx.completedCycle() == true );
|
||||||
|
|
||||||
SectionPart& s2 = SectionPart::acquire( ctx, "S2" );
|
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" );
|
||||||
REQUIRE( s2.didCompleteSuccessfully() == false );
|
|
||||||
REQUIRE( s2.isOpen() == false );
|
REQUIRE( s2.isOpen() == false );
|
||||||
|
REQUIRE( s2.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
testCase.close();
|
testCase.close();
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == false );
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
SECTION( "Re-enter - skip S1 and enter S2" ) {
|
SECTION( "Re-enter - skips S1 and enters S2" ) {
|
||||||
ctx.startCycle();
|
ctx.startCycle();
|
||||||
SectionPart& testCase2 = SectionPart::acquire( ctx, "Testcase" );
|
IPartTracker& testCase2 = SectionTracker::acquire( ctx, "Testcase" );
|
||||||
REQUIRE( testCase2.didCompleteSuccessfully() == false );
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
||||||
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
SectionPart& s1b = SectionPart::acquire( ctx, "S1" );
|
IPartTracker& s1b = SectionTracker::acquire( ctx, "S1" );
|
||||||
REQUIRE( s1b.didCompleteSuccessfully() == true );
|
REQUIRE( s1b.isOpen() == false );
|
||||||
|
|
||||||
SectionPart& s2b = SectionPart::acquire( ctx, "S2" );
|
IPartTracker& s2b = SectionTracker::acquire( ctx, "S2" );
|
||||||
REQUIRE( s2b.didCompleteSuccessfully() == false );
|
|
||||||
REQUIRE( s2b.isOpen() );
|
REQUIRE( s2b.isOpen() );
|
||||||
|
REQUIRE( s2b.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
REQUIRE( ctx.completedCycle() == false );
|
REQUIRE( ctx.completedCycle() == false );
|
||||||
|
|
||||||
@ -377,40 +380,40 @@ TEST_CASE( "PartTracker" ) {
|
|||||||
s2b.close();
|
s2b.close();
|
||||||
REQUIRE( ctx.completedCycle() == true );
|
REQUIRE( ctx.completedCycle() == true );
|
||||||
|
|
||||||
REQUIRE( s2b.didCompleteSuccessfully() == true );
|
REQUIRE( s2b.isSuccessfullyCompleted() == true );
|
||||||
REQUIRE( testCase2.hasEnded() == false );
|
REQUIRE( testCase2.hasEnded() == false );
|
||||||
|
|
||||||
testCase2.close();
|
testCase2.close();
|
||||||
REQUIRE( testCase2.didCompleteSuccessfully() == true );
|
REQUIRE( testCase2.isSuccessfullyCompleted() == true );
|
||||||
}
|
}
|
||||||
SECTION ("fail S2") {
|
SECTION ("fail S2") {
|
||||||
s2b.fail();
|
s2b.fail();
|
||||||
REQUIRE( ctx.completedCycle() == true );
|
REQUIRE( ctx.completedCycle() == true );
|
||||||
|
|
||||||
REQUIRE( s2b.didCompleteSuccessfully() == false );
|
REQUIRE( s2b.isSuccessfullyCompleted() == false );
|
||||||
REQUIRE( s2b.hasEnded() == true );
|
REQUIRE( s2b.hasEnded() == true );
|
||||||
REQUIRE( testCase2.hasEnded() == false );
|
REQUIRE( testCase2.hasEnded() == false );
|
||||||
|
|
||||||
testCase2.close();
|
testCase2.close();
|
||||||
REQUIRE( testCase2.didCompleteSuccessfully() == false );
|
REQUIRE( testCase2.isSuccessfullyCompleted() == false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "open a nested section" ) {
|
SECTION( "open a nested section" ) {
|
||||||
SectionPart& s2 = SectionPart::acquire( ctx, "S2" );
|
IPartTracker& s2 = SectionTracker::acquire( ctx, "S2" );
|
||||||
REQUIRE( s2.isOpen() == true );
|
REQUIRE( s2.isOpen() == true );
|
||||||
|
|
||||||
s2.close();
|
s2.close();
|
||||||
REQUIRE( s2.didCompleteSuccessfully() == true );
|
REQUIRE( s2.isSuccessfullyCompleted() == true );
|
||||||
REQUIRE( s1.didCompleteSuccessfully() == false );
|
REQUIRE( s1.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
s1.close();
|
s1.close();
|
||||||
REQUIRE( s1.didCompleteSuccessfully() == true );
|
REQUIRE( s1.isSuccessfullyCompleted() == true );
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == false );
|
REQUIRE( testCase.isSuccessfullyCompleted() == false );
|
||||||
|
|
||||||
testCase.close();
|
testCase.close();
|
||||||
REQUIRE( testCase.didCompleteSuccessfully() == true );
|
REQUIRE( testCase.isSuccessfullyCompleted() == true );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user