mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Converted (almost) all for-loops with iterators or indices to range-based
This commit is contained in:
@@ -218,12 +218,10 @@ namespace Catch {
|
||||
void printMessage() const {
|
||||
if( !messageLabel.empty() )
|
||||
stream << messageLabel << ':' << '\n';
|
||||
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
|
||||
it != itEnd;
|
||||
++it ) {
|
||||
for( auto const& message : messages ) {
|
||||
// If this assertion is a warning ignore any INFO messages
|
||||
if( printInfoMessages || it->type != ResultWas::Info )
|
||||
stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n';
|
||||
if( printInfoMessages || message.type != ResultWas::Info )
|
||||
stream << Text( message.message, TextAttributes().setIndent(2) ) << '\n';
|
||||
}
|
||||
}
|
||||
void printSourceInfo() const {
|
||||
@@ -331,10 +329,10 @@ namespace Catch {
|
||||
std::ostringstream oss;
|
||||
oss << count;
|
||||
std::string row = oss.str();
|
||||
for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) {
|
||||
while( it->size() < row.size() )
|
||||
*it = ' ' + *it;
|
||||
while( it->size() > row.size() )
|
||||
for( auto& oldRow : rows ) {
|
||||
while( oldRow.size() < row.size() )
|
||||
oldRow = ' ' + oldRow;
|
||||
while( oldRow.size() > row.size() )
|
||||
row = ' ' + row;
|
||||
}
|
||||
rows.push_back( row );
|
||||
@@ -379,9 +377,9 @@ namespace Catch {
|
||||
}
|
||||
}
|
||||
void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) {
|
||||
for( std::vector<SummaryColumn>::const_iterator it = cols.begin(); it != cols.end(); ++it ) {
|
||||
std::string value = it->rows[row];
|
||||
if( it->label.empty() ) {
|
||||
for( auto col : cols ) {
|
||||
std::string value = col.rows[row];
|
||||
if( col.label.empty() ) {
|
||||
stream << label << ": ";
|
||||
if( value != "0" )
|
||||
stream << value;
|
||||
@@ -390,8 +388,8 @@ namespace Catch {
|
||||
}
|
||||
else if( value != "0" ) {
|
||||
stream << Colour( Colour::LightGrey ) << " | ";
|
||||
stream << Colour( it->colour )
|
||||
<< value << ' ' << it->label;
|
||||
stream << Colour( col.colour )
|
||||
<< value << ' ' << col.label;
|
||||
}
|
||||
}
|
||||
stream << '\n';
|
||||
|
@@ -118,11 +118,8 @@ namespace Catch {
|
||||
xml.writeAttribute( "timestamp", getCurrentTimestamp() );
|
||||
|
||||
// Write test cases
|
||||
for( TestGroupNode::ChildNodes::const_iterator
|
||||
it = groupNode.children.begin(), itEnd = groupNode.children.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
writeTestCase( **it );
|
||||
for( auto const& child : groupNode.children )
|
||||
writeTestCase( *child );
|
||||
|
||||
xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false );
|
||||
xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
|
||||
@@ -173,23 +170,16 @@ namespace Catch {
|
||||
if( !sectionNode.stdErr.empty() )
|
||||
xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
|
||||
}
|
||||
for( SectionNode::ChildSections::const_iterator
|
||||
it = sectionNode.childSections.begin(),
|
||||
itEnd = sectionNode.childSections.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
for( auto const& childNode : sectionNode.childSections )
|
||||
if( className.empty() )
|
||||
writeSection( name, "", **it );
|
||||
writeSection( name, "", *childNode );
|
||||
else
|
||||
writeSection( className, name, **it );
|
||||
writeSection( className, name, *childNode );
|
||||
}
|
||||
|
||||
void writeAssertions( SectionNode const& sectionNode ) {
|
||||
for( SectionNode::Assertions::const_iterator
|
||||
it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
writeAssertion( *it );
|
||||
for( auto const& assertion : sectionNode.assertions )
|
||||
writeAssertion( assertion );
|
||||
}
|
||||
void writeAssertion( AssertionStats const& stats ) {
|
||||
AssertionResult const& result = stats.assertionResult;
|
||||
@@ -229,13 +219,9 @@ namespace Catch {
|
||||
std::ostringstream oss;
|
||||
if( !result.getMessage().empty() )
|
||||
oss << result.getMessage() << '\n';
|
||||
for( std::vector<MessageInfo>::const_iterator
|
||||
it = stats.infoMessages.begin(),
|
||||
itEnd = stats.infoMessages.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
if( it->type == ResultWas::Info )
|
||||
oss << it->message << '\n';
|
||||
for( auto const& msg : stats.infoMessages )
|
||||
if( msg.type == ResultWas::Info )
|
||||
oss << msg.message << '\n';
|
||||
|
||||
oss << "at " << result.getSourceInfo();
|
||||
xml.writeText( oss.str(), false );
|
||||
|
@@ -28,95 +28,71 @@ public: // IStreamingReporter
|
||||
}
|
||||
|
||||
virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->noMatchingTestCases( spec );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->noMatchingTestCases( spec );
|
||||
}
|
||||
|
||||
|
||||
virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->testRunStarting( testRunInfo );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->testRunStarting( testRunInfo );
|
||||
}
|
||||
|
||||
virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->testGroupStarting( groupInfo );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->testGroupStarting( groupInfo );
|
||||
}
|
||||
|
||||
|
||||
virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->testCaseStarting( testInfo );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->testCaseStarting( testInfo );
|
||||
}
|
||||
|
||||
virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->sectionStarting( sectionInfo );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->sectionStarting( sectionInfo );
|
||||
}
|
||||
|
||||
|
||||
virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->assertionStarting( assertionInfo );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->assertionStarting( assertionInfo );
|
||||
}
|
||||
|
||||
|
||||
// The return value indicates if the messages buffer should be cleared:
|
||||
virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
|
||||
bool clearBuffer = false;
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
clearBuffer |= (*it)->assertionEnded( assertionStats );
|
||||
for( auto const& reporter : m_reporters )
|
||||
clearBuffer |= reporter->assertionEnded( assertionStats );
|
||||
return clearBuffer;
|
||||
}
|
||||
|
||||
virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->sectionEnded( sectionStats );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->sectionEnded( sectionStats );
|
||||
}
|
||||
|
||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->testCaseEnded( testCaseStats );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->testCaseEnded( testCaseStats );
|
||||
}
|
||||
|
||||
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->testGroupEnded( testGroupStats );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->testGroupEnded( testGroupStats );
|
||||
}
|
||||
|
||||
virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->testRunEnded( testRunStats );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->testRunEnded( testRunStats );
|
||||
}
|
||||
|
||||
|
||||
virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
|
||||
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
(*it)->skipTest( testInfo );
|
||||
for( auto const& reporter : m_reporters )
|
||||
reporter->skipTest( testInfo );
|
||||
}
|
||||
|
||||
virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {
|
||||
|
@@ -112,12 +112,8 @@ namespace Catch {
|
||||
msg << " with message:";
|
||||
if( assertionStats.infoMessages.size() > 1 )
|
||||
msg << " with messages:";
|
||||
for( std::vector<MessageInfo>::const_iterator
|
||||
it = assertionStats.infoMessages.begin(),
|
||||
itEnd = assertionStats.infoMessages.end();
|
||||
it != itEnd;
|
||||
++it )
|
||||
msg << "\n \"" << it->message << "\"";
|
||||
for( auto const& messageInfo : assertionStats.infoMessages )
|
||||
msg << "\n \"" << messageInfo.message << "\"";
|
||||
|
||||
|
||||
if( result.hasExpression() ) {
|
||||
|
@@ -99,15 +99,13 @@ namespace Catch {
|
||||
|
||||
if( includeResults ) {
|
||||
// Print any info messages in <Info> tags.
|
||||
for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
|
||||
it != itEnd;
|
||||
++it ) {
|
||||
if( it->type == ResultWas::Info ) {
|
||||
for( auto const& msg : assertionStats.infoMessages ) {
|
||||
if( msg.type == ResultWas::Info ) {
|
||||
m_xml.scopedElement( "Info" )
|
||||
.writeText( it->message );
|
||||
} else if ( it->type == ResultWas::Warning ) {
|
||||
.writeText( msg.message );
|
||||
} else if ( msg.type == ResultWas::Warning ) {
|
||||
m_xml.scopedElement( "Warning" )
|
||||
.writeText( it->message );
|
||||
.writeText( msg.message );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user