Remove rest of std::shared_ptr usage in Trackers

Closes #2088
This commit is contained in:
Martin Hořeňovský 2020-12-04 22:57:34 +01:00
parent 6350851f9a
commit 4b51d0dd3b
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
3 changed files with 21 additions and 18 deletions

View File

@ -60,7 +60,8 @@ namespace Catch {
assert( childTracker->isGeneratorTracker() ); assert( childTracker->isGeneratorTracker() );
tracker = static_cast<GeneratorTracker*>( childTracker ); tracker = static_cast<GeneratorTracker*>( childTracker );
} else { } else {
auto newTracker = std::make_shared<GeneratorTracker>( auto newTracker =
Catch::Detail::make_unique<GeneratorTracker>(
nameAndLocation, ctx, &currentTracker ); nameAndLocation, ctx, &currentTracker );
tracker = newTracker.get(); tracker = newTracker.get();
currentTracker.addChild( std::move(newTracker) ); currentTracker.addChild( std::move(newTracker) );
@ -96,7 +97,7 @@ namespace Catch {
if ( std::find_if( if ( std::find_if(
m_children.begin(), m_children.begin(),
m_children.end(), m_children.end(),
[]( TestCaseTracking::ITrackerPtr tracker ) { []( TestCaseTracking::ITrackerPtr const& tracker ) {
return tracker->hasStarted(); return tracker->hasStarted();
} ) != m_children.end() ) { } ) != m_children.end() ) {
return false; return false;
@ -105,7 +106,7 @@ namespace Catch {
// No children have started. We need to check if they _can_ // No children have started. We need to check if they _can_
// start, and thus we should wait for them, or they cannot // start, and thus we should wait for them, or they cannot
// start (due to filters), and we shouldn't wait for them // start (due to filters), and we shouldn't wait for them
auto* parent = m_parent; ITracker* parent = m_parent;
// This is safe: there is always at least one section // This is safe: there is always at least one section
// tracker in a test case tracking tree // tracker in a test case tracking tree
while ( !parent->isSectionTracker() ) { while ( !parent->isSectionTracker() ) {
@ -115,7 +116,7 @@ namespace Catch {
"Missing root (test case) level section" ); "Missing root (test case) level section" );
auto const& parentSection = auto const& parentSection =
static_cast<SectionTracker&>( *parent ); static_cast<SectionTracker const&>( *parent );
auto const& filters = parentSection.getFilters(); auto const& filters = parentSection.getFilters();
// No filters -> no restrictions on running sections // No filters -> no restrictions on running sections
if ( filters.empty() ) { if ( filters.empty() ) {
@ -124,11 +125,11 @@ namespace Catch {
for ( auto const& child : m_children ) { for ( auto const& child : m_children ) {
if ( child->isSectionTracker() && if ( child->isSectionTracker() &&
std::find( filters.begin(), std::find(
filters.begin(),
filters.end(), filters.end(),
static_cast<SectionTracker&>( *child ) static_cast<SectionTracker const&>( *child )
.trimmedName() ) != .trimmedName() ) != filters.end() ) {
filters.end() ) {
return true; return true;
} }
} }

View File

@ -12,7 +12,6 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <memory>
#if defined(__clang__) #if defined(__clang__)
# pragma clang diagnostic push # pragma clang diagnostic push
@ -30,8 +29,8 @@ namespace TestCaseTracking {
ITracker::~ITracker() = default; ITracker::~ITracker() = default;
void ITracker::addChild( ITrackerPtr const& child ) { void ITracker::addChild( ITrackerPtr&& child ) {
m_children.push_back( child ); m_children.push_back( std::move(child) );
} }
ITracker* ITracker::findChild( NameAndLocation const& nameAndLocation ) { ITracker* ITracker::findChild( NameAndLocation const& nameAndLocation ) {
@ -50,7 +49,10 @@ namespace TestCaseTracking {
ITracker& TrackerContext::startRun() { ITracker& TrackerContext::startRun() {
using namespace std::string_literals; using namespace std::string_literals;
m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}"s, CATCH_INTERNAL_LINEINFO ), *this, nullptr ); m_rootTracker = Catch::Detail::make_unique<SectionTracker>(
NameAndLocation( "{root}"s, CATCH_INTERNAL_LINEINFO ),
*this,
nullptr );
m_currentTracker = nullptr; m_currentTracker = nullptr;
m_runState = Executing; m_runState = Executing;
return *m_rootTracker; return *m_rootTracker;
@ -204,7 +206,7 @@ namespace TestCaseTracking {
assert( childTracker->isSectionTracker() ); assert( childTracker->isSectionTracker() );
section = static_cast<SectionTracker*>( childTracker ); section = static_cast<SectionTracker*>( childTracker );
} else { } else {
auto newSection = std::make_shared<SectionTracker>( auto newSection = Catch::Detail::make_unique<SectionTracker>(
nameAndLocation, ctx, &currentTracker ); nameAndLocation, ctx, &currentTracker );
section = newSection.get(); section = newSection.get();
currentTracker.addChild( std::move( newSection ) ); currentTracker.addChild( std::move( newSection ) );

View File

@ -10,10 +10,10 @@
#include <catch2/internal/catch_compiler_capabilities.hpp> #include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_source_line_info.hpp> #include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
namespace Catch { namespace Catch {
namespace TestCaseTracking { namespace TestCaseTracking {
@ -31,7 +31,7 @@ namespace TestCaseTracking {
class ITracker; class ITracker;
using ITrackerPtr = std::shared_ptr<ITracker>; using ITrackerPtr = Catch::Detail::unique_ptr<ITracker>;
class ITracker { class ITracker {
NameAndLocation m_nameAndLocation; NameAndLocation m_nameAndLocation;
@ -69,7 +69,7 @@ namespace TestCaseTracking {
virtual void markAsNeedingAnotherRun() = 0; virtual void markAsNeedingAnotherRun() = 0;
//! Register a nested ITracker //! Register a nested ITracker
void addChild( ITrackerPtr const& child ); void addChild( ITrackerPtr&& child );
/** /**
* Returns ptr to specific child if register with this tracker. * Returns ptr to specific child if register with this tracker.
* *