mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Devirtualize nested tracker handling
This commit is contained in:
parent
125d4b4164
commit
ef92178058
@ -31,6 +31,23 @@ namespace TestCaseTracking {
|
|||||||
|
|
||||||
ITracker::~ITracker() = default;
|
ITracker::~ITracker() = default;
|
||||||
|
|
||||||
|
void ITracker::addChild( ITrackerPtr const& child ) {
|
||||||
|
m_children.push_back( child );
|
||||||
|
}
|
||||||
|
|
||||||
|
ITrackerPtr ITracker::findChild( NameAndLocation const& nameAndLocation ) {
|
||||||
|
auto it = std::find_if(
|
||||||
|
m_children.begin(),
|
||||||
|
m_children.end(),
|
||||||
|
[&nameAndLocation]( ITrackerPtr const& tracker ) {
|
||||||
|
return tracker->nameAndLocation().location ==
|
||||||
|
nameAndLocation.location &&
|
||||||
|
tracker->nameAndLocation().name == nameAndLocation.name;
|
||||||
|
} );
|
||||||
|
return ( it != m_children.end() ) ? *it : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ITracker& TrackerContext::startRun() {
|
ITracker& TrackerContext::startRun() {
|
||||||
m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr );
|
m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr );
|
||||||
@ -79,26 +96,7 @@ namespace TestCaseTracking {
|
|||||||
bool TrackerBase::isOpen() const {
|
bool TrackerBase::isOpen() const {
|
||||||
return m_runState != NotStarted && !isComplete();
|
return m_runState != NotStarted && !isComplete();
|
||||||
}
|
}
|
||||||
bool TrackerBase::hasChildren() const {
|
|
||||||
return !m_children.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TrackerBase::addChild( ITrackerPtr const& child ) {
|
|
||||||
m_children.push_back( child );
|
|
||||||
}
|
|
||||||
|
|
||||||
ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) {
|
|
||||||
auto it = std::find_if( m_children.begin(), m_children.end(),
|
|
||||||
[&nameAndLocation]( ITrackerPtr const& tracker ){
|
|
||||||
return
|
|
||||||
tracker->nameAndLocation().location == nameAndLocation.location &&
|
|
||||||
tracker->nameAndLocation().name == nameAndLocation.name;
|
|
||||||
} );
|
|
||||||
return( it != m_children.end() )
|
|
||||||
? *it
|
|
||||||
: nullptr;
|
|
||||||
}
|
|
||||||
ITracker& TrackerBase::parent() {
|
ITracker& TrackerBase::parent() {
|
||||||
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;
|
||||||
|
@ -36,6 +36,11 @@ namespace TestCaseTracking {
|
|||||||
class ITracker {
|
class ITracker {
|
||||||
NameAndLocation m_nameAndLocation;
|
NameAndLocation m_nameAndLocation;
|
||||||
|
|
||||||
|
using Children = std::vector<ITrackerPtr>;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Children m_children;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ITracker(NameAndLocation const& nameAndLoc) :
|
ITracker(NameAndLocation const& nameAndLoc) :
|
||||||
m_nameAndLocation(nameAndLoc)
|
m_nameAndLocation(nameAndLoc)
|
||||||
@ -54,7 +59,6 @@ namespace TestCaseTracking {
|
|||||||
virtual bool isComplete() const = 0; // Successfully completed or failed
|
virtual bool isComplete() const = 0; // Successfully completed or failed
|
||||||
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 bool hasChildren() const = 0;
|
|
||||||
virtual bool hasStarted() const = 0;
|
virtual bool hasStarted() const = 0;
|
||||||
|
|
||||||
virtual ITracker& parent() = 0;
|
virtual ITracker& parent() = 0;
|
||||||
@ -64,8 +68,20 @@ namespace TestCaseTracking {
|
|||||||
virtual void fail() = 0;
|
virtual void fail() = 0;
|
||||||
virtual void markAsNeedingAnotherRun() = 0;
|
virtual void markAsNeedingAnotherRun() = 0;
|
||||||
|
|
||||||
virtual void addChild( ITrackerPtr const& child ) = 0;
|
//! Register a nested ITracker
|
||||||
virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0;
|
void addChild( ITrackerPtr const& child );
|
||||||
|
/**
|
||||||
|
* Returns ptr to specific child if register with this tracker.
|
||||||
|
*
|
||||||
|
* Returns nullptr if not found.
|
||||||
|
*/
|
||||||
|
ITrackerPtr findChild( NameAndLocation const& nameAndLocation );
|
||||||
|
//! Have any children been added?
|
||||||
|
bool hasChildren() const {
|
||||||
|
return !m_children.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void openChild() = 0;
|
virtual void openChild() = 0;
|
||||||
|
|
||||||
// Debug/ checking
|
// Debug/ checking
|
||||||
@ -109,10 +125,8 @@ namespace TestCaseTracking {
|
|||||||
Failed
|
Failed
|
||||||
};
|
};
|
||||||
|
|
||||||
using Children = std::vector<ITrackerPtr>;
|
|
||||||
TrackerContext& m_ctx;
|
TrackerContext& m_ctx;
|
||||||
ITracker* m_parent;
|
ITracker* m_parent;
|
||||||
Children m_children;
|
|
||||||
CycleState m_runState = NotStarted;
|
CycleState m_runState = NotStarted;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -121,14 +135,10 @@ namespace TestCaseTracking {
|
|||||||
bool isComplete() const override;
|
bool isComplete() const override;
|
||||||
bool isSuccessfullyCompleted() const override;
|
bool isSuccessfullyCompleted() const override;
|
||||||
bool isOpen() const override;
|
bool isOpen() const override;
|
||||||
bool hasChildren() const override;
|
|
||||||
bool hasStarted() const override {
|
bool hasStarted() const override {
|
||||||
return m_runState != NotStarted;
|
return m_runState != NotStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addChild( ITrackerPtr const& child ) override;
|
|
||||||
|
|
||||||
ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override;
|
|
||||||
ITracker& parent() override;
|
ITracker& parent() override;
|
||||||
|
|
||||||
void openChild() override;
|
void openChild() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user