diff --git a/src/catch2/reporters/catch_reporter_cumulative_base.cpp b/src/catch2/reporters/catch_reporter_cumulative_base.cpp index 5a25ab9b..bba6f67d 100644 --- a/src/catch2/reporters/catch_reporter_cumulative_base.cpp +++ b/src/catch2/reporters/catch_reporter_cumulative_base.cpp @@ -17,7 +17,7 @@ namespace Catch { BySectionInfo( BySectionInfo const& other ): m_other( other.m_other ) {} bool operator()( - std::shared_ptr const& + Detail::unique_ptr const& node ) const { return ( ( node->stats.sectionInfo.name == m_other.name ) && @@ -37,27 +37,30 @@ namespace Catch { void CumulativeReporterBase::sectionStarting( SectionInfo const& sectionInfo ) { SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); - std::shared_ptr node; + SectionNode* node; if ( m_sectionStack.empty() ) { - if ( !m_rootSection ) + if ( !m_rootSection ) { m_rootSection = - std::make_shared( incompleteStats ); - node = m_rootSection; + Detail::make_unique( incompleteStats ); + } + node = m_rootSection.get(); } else { SectionNode& parentNode = *m_sectionStack.back(); auto it = std::find_if( parentNode.childSections.begin(), parentNode.childSections.end(), BySectionInfo( sectionInfo ) ); if ( it == parentNode.childSections.end() ) { - node = std::make_shared( incompleteStats ); - parentNode.childSections.push_back( node ); + auto newNode = + Detail::make_unique( incompleteStats ); + node = newNode.get(); + parentNode.childSections.push_back( std::move( newNode ) ); } else { - node = *it; + node = it->get(); } } - m_deepestSection = node.get(); - m_sectionStack.push_back( node.get() ); + m_deepestSection = node; + m_sectionStack.push_back( node ); } bool CumulativeReporterBase::assertionEnded( @@ -84,11 +87,10 @@ namespace Catch { void CumulativeReporterBase::testCaseEnded( TestCaseStats const& testCaseStats ) { - auto node = std::make_shared( testCaseStats ); + auto node = Detail::make_unique( testCaseStats ); assert( m_sectionStack.size() == 0 ); - node->children.push_back( m_rootSection ); - m_testCases.push_back( node ); - m_rootSection.reset(); + node->children.push_back( std::move(m_rootSection) ); + m_testCases.push_back( std::move(node) ); assert( m_deepestSection ); m_deepestSection->stdOut = testCaseStats.stdOut; @@ -97,9 +99,9 @@ namespace Catch { void CumulativeReporterBase::testGroupEnded( TestGroupStats const& testGroupStats ) { - auto node = std::make_shared( testGroupStats ); + auto node = Detail::make_unique( testGroupStats ); node->children.swap( m_testCases ); - m_testGroups.push_back( node ); + m_testGroups.push_back( std::move(node) ); } void CumulativeReporterBase::testRunEnded( TestRunStats const& testRunStats ) { diff --git a/src/catch2/reporters/catch_reporter_cumulative_base.hpp b/src/catch2/reporters/catch_reporter_cumulative_base.hpp index 7f228420..1c882fa0 100644 --- a/src/catch2/reporters/catch_reporter_cumulative_base.hpp +++ b/src/catch2/reporters/catch_reporter_cumulative_base.hpp @@ -23,7 +23,7 @@ namespace Catch { struct Node { explicit Node( T const& _value ) : value( _value ) {} - using ChildNodes = std::vector>; + using ChildNodes = std::vector>; T value; ChildNodes children; }; @@ -35,7 +35,7 @@ namespace Catch { } SectionStats stats; - std::vector> childSections; + std::vector> childSections; std::vector assertions; std::string stdOut; std::string stdErr; @@ -73,12 +73,12 @@ namespace Catch { std::ostream& stream; // Note: We rely on pointer identity being stable, which is why // which is why we store around pointers rather than values. - std::vector> m_testCases; - std::vector> m_testGroups; + std::vector> m_testCases; + std::vector> m_testGroups; std::vector m_testRuns; - std::shared_ptr m_rootSection; + Detail::unique_ptr m_rootSection; SectionNode* m_deepestSection = nullptr; std::vector m_sectionStack; }; diff --git a/src/catch2/reporters/catch_reporter_sonarqube.cpp b/src/catch2/reporters/catch_reporter_sonarqube.cpp index 579383ac..18ab3134 100644 --- a/src/catch2/reporters/catch_reporter_sonarqube.cpp +++ b/src/catch2/reporters/catch_reporter_sonarqube.cpp @@ -28,15 +28,17 @@ namespace Catch { } void SonarQubeReporter::writeGroup(TestGroupNode const& groupNode) { - std::map testsPerFile; - for (auto const& child : groupNode.children) - testsPerFile[child->value.testInfo->lineInfo.file].push_back(child); + std::map> testsPerFile; + for ( auto const& child : groupNode.children ) { + testsPerFile[child->value.testInfo->lineInfo.file].push_back( + child.get() ); + } for (auto const& kv : testsPerFile) writeTestFile(kv.first, kv.second); } - void SonarQubeReporter::writeTestFile(std::string const& filename, TestGroupNode::ChildNodes const& testCaseNodes) { + void SonarQubeReporter::writeTestFile(std::string const& filename, std::vector const& testCaseNodes) { XmlWriter::ScopedElement e = xml.scopedElement("file"); xml.writeAttribute("path", filename); diff --git a/src/catch2/reporters/catch_reporter_sonarqube.hpp b/src/catch2/reporters/catch_reporter_sonarqube.hpp index e8a55042..d46cb422 100644 --- a/src/catch2/reporters/catch_reporter_sonarqube.hpp +++ b/src/catch2/reporters/catch_reporter_sonarqube.hpp @@ -42,7 +42,7 @@ namespace Catch { void writeGroup(TestGroupNode const& groupNode); - void writeTestFile(std::string const& filename, TestGroupNode::ChildNodes const& testCaseNodes); + void writeTestFile(std::string const& filename, std::vector const& testCaseNodes); void writeTestCase(TestCaseNode const& testCaseNode);