mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Replace shared_ptrs with unique_ptrs in CumulativeReporterBase nodes
Closes #2089
This commit is contained in:
parent
bfe5553416
commit
677adf8ade
@ -17,7 +17,7 @@ namespace Catch {
|
||||
BySectionInfo( BySectionInfo const& other ):
|
||||
m_other( other.m_other ) {}
|
||||
bool operator()(
|
||||
std::shared_ptr<CumulativeReporterBase::SectionNode> const&
|
||||
Detail::unique_ptr<CumulativeReporterBase::SectionNode> 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<SectionNode> node;
|
||||
SectionNode* node;
|
||||
if ( m_sectionStack.empty() ) {
|
||||
if ( !m_rootSection )
|
||||
if ( !m_rootSection ) {
|
||||
m_rootSection =
|
||||
std::make_shared<SectionNode>( incompleteStats );
|
||||
node = m_rootSection;
|
||||
Detail::make_unique<SectionNode>( 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<SectionNode>( incompleteStats );
|
||||
parentNode.childSections.push_back( node );
|
||||
auto newNode =
|
||||
Detail::make_unique<SectionNode>( 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<TestCaseNode>( testCaseStats );
|
||||
auto node = Detail::make_unique<TestCaseNode>( 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<TestGroupNode>( testGroupStats );
|
||||
auto node = Detail::make_unique<TestGroupNode>( testGroupStats );
|
||||
node->children.swap( m_testCases );
|
||||
m_testGroups.push_back( node );
|
||||
m_testGroups.push_back( std::move(node) );
|
||||
}
|
||||
|
||||
void CumulativeReporterBase::testRunEnded( TestRunStats const& testRunStats ) {
|
||||
|
@ -23,7 +23,7 @@ namespace Catch {
|
||||
struct Node {
|
||||
explicit Node( T const& _value ) : value( _value ) {}
|
||||
|
||||
using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>;
|
||||
using ChildNodes = std::vector<Detail::unique_ptr<ChildNodeT>>;
|
||||
T value;
|
||||
ChildNodes children;
|
||||
};
|
||||
@ -35,7 +35,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
SectionStats stats;
|
||||
std::vector<std::shared_ptr<SectionNode>> childSections;
|
||||
std::vector<Detail::unique_ptr<SectionNode>> childSections;
|
||||
std::vector<AssertionStats> 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<std::shared_ptr<TestCaseNode>> m_testCases;
|
||||
std::vector<std::shared_ptr<TestGroupNode>> m_testGroups;
|
||||
std::vector<Detail::unique_ptr<TestCaseNode>> m_testCases;
|
||||
std::vector<Detail::unique_ptr<TestGroupNode>> m_testGroups;
|
||||
|
||||
std::vector<TestRunNode> m_testRuns;
|
||||
|
||||
std::shared_ptr<SectionNode> m_rootSection;
|
||||
Detail::unique_ptr<SectionNode> m_rootSection;
|
||||
SectionNode* m_deepestSection = nullptr;
|
||||
std::vector<SectionNode*> m_sectionStack;
|
||||
};
|
||||
|
@ -28,15 +28,17 @@ namespace Catch {
|
||||
}
|
||||
|
||||
void SonarQubeReporter::writeGroup(TestGroupNode const& groupNode) {
|
||||
std::map<std::string, TestGroupNode::ChildNodes> testsPerFile;
|
||||
for (auto const& child : groupNode.children)
|
||||
testsPerFile[child->value.testInfo->lineInfo.file].push_back(child);
|
||||
std::map<std::string, std::vector<TestCaseNode const*>> 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<TestCaseNode const*> const& testCaseNodes) {
|
||||
XmlWriter::ScopedElement e = xml.scopedElement("file");
|
||||
xml.writeAttribute("path", filename);
|
||||
|
||||
|
@ -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<TestCaseNode const*> const& testCaseNodes);
|
||||
|
||||
void writeTestCase(TestCaseNode const& testCaseNode);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user