Converted (almost) all for-loops with iterators or indices to range-based
diff --git a/include/catch_session.hpp b/include/catch_session.hpp
index be51bef..8d200aa 100644
--- a/include/catch_session.hpp
+++ b/include/catch_session.hpp
@@ -37,18 +37,14 @@
reporters.push_back( "console" );
Ptr<IStreamingReporter> reporter;
- for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end();
- it != itEnd;
- ++it )
- reporter = addReporter( reporter, createReporter( *it, config ) );
+ for( auto const& name : reporters )
+ reporter = addReporter( reporter, createReporter( name, config ) );
return reporter;
}
Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
- for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end();
- it != itEnd;
- ++it )
- reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) );
+ for( auto const& listener : listeners )
+ reporters = addReporter(reporters, listener->create( ReporterConfig( config ) ) );
return reporters;
}
@@ -71,13 +67,11 @@
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
- for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
- it != itEnd;
- ++it ) {
- if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
- totals += context.runTest( *it );
+ for( auto const& testCase : allTestCases ) {
+ if( !context.aborting() && matchTest( testCase, testSpec, *iconfig ) )
+ totals += context.runTest( testCase );
else
- reporter->skipTest( *it );
+ reporter->skipTest( testCase );
}
context.testGroupEnded( iconfig->name(), totals, 1, 1 );
@@ -85,12 +79,11 @@
}
void applyFilenamesAsTags( IConfig const& config ) {
- std::vector<TestCase> const& tests = getAllTestCasesSorted( config );
- for(std::size_t i = 0; i < tests.size(); ++i ) {
- TestCase& test = const_cast<TestCase&>( tests[i] );
- std::set<std::string> tags = test.tags;
+ auto& tests = const_cast<std::vector<TestCase>&>( getAllTestCasesSorted( config ) );
+ for( auto& testCase : tests ) {
+ std::set<std::string> tags = testCase.tags;
- std::string filename = test.lineInfo.file;
+ std::string filename = testCase.lineInfo.file;
std::string::size_type lastSlash = filename.find_last_of( "\\/" );
if( lastSlash != std::string::npos )
filename = filename.substr( lastSlash+1 );
@@ -100,7 +93,7 @@
filename = filename.substr( 0, lastDot );
tags.insert( "#" + filename );
- setTags( test, tags );
+ setTags( testCase, tags );
}
}
diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h
index d325a08..bdf0f31 100644
--- a/include/internal/catch_common.h
+++ b/include/internal/catch_common.h
@@ -62,17 +62,13 @@
template<typename ContainerT>
inline void deleteAll( ContainerT& container ) {
- typename ContainerT::const_iterator it = container.begin();
- typename ContainerT::const_iterator itEnd = container.end();
- for(; it != itEnd; ++it )
- delete *it;
+ for( auto p : container )
+ delete p;
}
template<typename AssociativeContainerT>
inline void deleteAllValues( AssociativeContainerT& container ) {
- typename AssociativeContainerT::const_iterator it = container.begin();
- typename AssociativeContainerT::const_iterator itEnd = container.end();
- for(; it != itEnd; ++it )
- delete it->second;
+ for( auto const& kvp : container )
+ delete kvp.second;
}
bool startsWith( std::string const& s, std::string const& prefix );
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index 174850b..5431cb9 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -93,8 +93,8 @@
{
if( !data.testsOrTags.empty() ) {
TestSpecParser parser( ITagAliasRegistry::get() );
- for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
- parser.parse( data.testsOrTags[i] );
+ for( auto const& testOrTags : data.testsOrTags )
+ parser.parse( testOrTags );
m_testSpec = parser.testSpec();
}
}
diff --git a/include/internal/catch_generators.hpp b/include/internal/catch_generators.hpp
index a9ba7eb..e02691c 100644
--- a/include/internal/catch_generators.hpp
+++ b/include/internal/catch_generators.hpp
@@ -88,11 +88,9 @@
operator T () const {
size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
- typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
- typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
- for( size_t index = 0; it != itEnd; ++it )
+ size_t index = 0;
+ for( auto generator : m_composed )
{
- const IGenerator<T>* generator = *it;
if( overallIndex >= index && overallIndex < index + generator->size() )
{
return generator->getValue( overallIndex-index );
diff --git a/include/internal/catch_generators_impl.hpp b/include/internal/catch_generators_impl.hpp
index fea699a..51eb80c 100644
--- a/include/internal/catch_generators_impl.hpp
+++ b/include/internal/catch_generators_impl.hpp
@@ -62,10 +62,8 @@
}
bool moveNext() {
- std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
- std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
- for(; it != itEnd; ++it ) {
- if( (*it)->moveNext() )
+ for( auto generator : m_generatorsInOrder ) {
+ if( generator->moveNext() )
return true;
}
return false;
diff --git a/include/internal/catch_legacy_reporter_adapter.hpp b/include/internal/catch_legacy_reporter_adapter.hpp
index 6034581..17a5918 100644
--- a/include/internal/catch_legacy_reporter_adapter.hpp
+++ b/include/internal/catch_legacy_reporter_adapter.hpp
@@ -42,12 +42,10 @@
bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
- for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
- it != itEnd;
- ++it ) {
- if( it->type == ResultWas::Info ) {
- ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
- rb << it->message;
+ for( auto const& messageInfo : assertionStats.infoMessages ) {
+ if( messageInfo.type == ResultWas::Info ) {
+ ResultBuilder rb( messageInfo.macroName.c_str(), messageInfo.lineInfo, "", ResultDisposition::Normal );
+ rb << messageInfo.message;
rb.setResultType( ResultWas::Info );
AssertionResult result = rb.build();
m_legacyReporter->Result( result );
diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.hpp
index e09898e..fc1cc91 100644
--- a/include/internal/catch_list.hpp
+++ b/include/internal/catch_list.hpp
@@ -35,11 +35,8 @@
tagsAttr.setIndent( 6 );
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
- for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
- it != itEnd;
- ++it ) {
+ for( auto const& testCaseInfo : matchedTestCases ) {
matchedTests++;
- TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
Colour::Code colour = testCaseInfo.isHidden()
? Colour::SecondaryText
: Colour::None;
@@ -63,11 +60,8 @@
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
std::size_t matchedTests = 0;
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
- for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
- it != itEnd;
- ++it ) {
+ for( auto const& testCaseInfo : matchedTestCases ) {
matchedTests++;
- TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
if( startsWith( testCaseInfo.name, '#' ) )
Catch::cout() << '"' << testCaseInfo.name << '"' << std::endl;
else
@@ -84,10 +78,8 @@
}
std::string all() const {
std::string out;
- for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
- it != itEnd;
- ++it )
- out += "[" + *it + "]";
+ for( auto const& spelling : spellings )
+ out += "[" + spelling + "]";
return out;
}
std::set<std::string> spellings;
@@ -106,29 +98,20 @@
std::map<std::string, TagInfo> tagCounts;
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
- for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
- it != itEnd;
- ++it ) {
- for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
- tagItEnd = it->getTestCaseInfo().tags.end();
- tagIt != tagItEnd;
- ++tagIt ) {
- std::string tagName = *tagIt;
+ for( auto const& testCase : matchedTestCases ) {
+ for( auto const& tagName : testCase.getTestCaseInfo().tags ) {
std::string lcaseTagName = toLower( tagName );
- std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
+ auto countIt = tagCounts.find( lcaseTagName );
if( countIt == tagCounts.end() )
countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
countIt->second.add( tagName );
}
}
- for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
- countItEnd = tagCounts.end();
- countIt != countItEnd;
- ++countIt ) {
+ for( auto const& tagCount : tagCounts ) {
std::ostringstream oss;
- oss << " " << std::setw(2) << countIt->second.count << " ";
- Text wrapper( countIt->second.all(), TextAttributes()
+ oss << " " << std::setw(2) << tagCount.second.count << " ";
+ Text wrapper( tagCount.second.all(), TextAttributes()
.setInitialIndent( 0 )
.setIndent( oss.str().size() )
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
@@ -143,18 +126,18 @@
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
std::size_t maxNameLen = 0;
- for(it = itBegin; it != itEnd; ++it )
- maxNameLen = (std::max)( maxNameLen, it->first.size() );
+ for( auto const factoryKvp : getRegistryHub().getReporterRegistry().getFactories() )
+ maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
- for(it = itBegin; it != itEnd; ++it ) {
- Text wrapper( it->second->getDescription(), TextAttributes()
+ for( auto const factoryKvp : getRegistryHub().getReporterRegistry().getFactories() ) {
+ Text wrapper( factoryKvp.second->getDescription(), TextAttributes()
.setInitialIndent( 0 )
.setIndent( 7+maxNameLen )
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
Catch::cout() << " "
- << it->first
+ << factoryKvp.first
<< ':'
- << std::string( maxNameLen - it->first.size() + 2, ' ' )
+ << std::string( maxNameLen - factoryKvp.first.size() + 2, ' ' )
<< wrapper << '\n';
}
Catch::cout() << std::endl;
diff --git a/include/internal/catch_matchers.hpp b/include/internal/catch_matchers.hpp
index 2193c54..12f2333 100644
--- a/include/internal/catch_matchers.hpp
+++ b/include/internal/catch_matchers.hpp
@@ -55,8 +55,8 @@
template<typename ArgT>
struct MatchAllOf : MatcherBase<ArgT> {
virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
- for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
- if (!m_matchers[i]->match(arg))
+ for( auto matcher : m_matchers ) {
+ if (!matcher->match(arg))
return false;
}
return true;
@@ -65,10 +65,13 @@
std::string description;
description.reserve( 4 + m_matchers.size()*32 );
description += "( ";
- for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
- if( i != 0 )
+ bool first = true;
+ for( auto matcher : m_matchers ) {
+ if( first )
+ first = false;
+ else
description += " and ";
- description += m_matchers[i]->toString();
+ description += matcher->toString();
}
description += " )";
return description;
@@ -85,8 +88,8 @@
struct MatchAnyOf : MatcherBase<ArgT> {
virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
- for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
- if (m_matchers[i]->match(arg))
+ for( auto matcher : m_matchers ) {
+ if (matcher->match(arg))
return true;
}
return false;
@@ -95,10 +98,13 @@
std::string description;
description.reserve( 4 + m_matchers.size()*32 );
description += "( ";
- for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
- if( i != 0 )
+ bool first = true;
+ for( auto matcher : m_matchers ) {
+ if( first )
+ first = false;
+ else
description += " or ";
- description += m_matchers[i]->toString();
+ description += matcher->toString();
}
description += " )";
return description;
diff --git a/include/internal/catch_matchers_vector.h b/include/internal/catch_matchers_vector.h
index 6a48a4e..2889013 100644
--- a/include/internal/catch_matchers_vector.h
+++ b/include/internal/catch_matchers_vector.h
@@ -40,8 +40,8 @@
// !TBD: see note in EqualsMatcher
if (m_comparator.size() > v.size())
return false;
- for (size_t i = 0; i < m_comparator.size(); ++i)
- if (std::find(v.begin(), v.end(), m_comparator[i]) == v.end())
+ for ( auto const& comparator : m_comparator )
+ if (std::find(v.begin(), v.end(), comparator) == v.end())
return false;
return true;
}
diff --git a/include/internal/catch_section_info.hpp b/include/internal/catch_section_info.hpp
index aebbf6a..74fe4c6 100644
--- a/include/internal/catch_section_info.hpp
+++ b/include/internal/catch_section_info.hpp
@@ -60,10 +60,8 @@
bool hasUntestedSections() const {
if( m_state == Unknown )
return true;
- for( SubSections::const_iterator it = m_subSections.begin();
- it != m_subSections.end();
- ++it)
- if( (*it)->hasUntestedSections() )
+ for( auto subSection : m_subSections )
+ if( subSection->hasUntestedSections() )
return true;
return false;
}
@@ -75,10 +73,8 @@
}
RunningSection* findOrAddSubSection( std::string const& name, bool& changed ) {
- for( SubSections::const_iterator it = m_subSections.begin();
- it != m_subSections.end();
- ++it)
- if( (*it)->getName() == name )
+ for( auto subSection : m_subSections )
+ if( subSection->getName() == name )
return *it;
RunningSection* subSection = new RunningSection( this, name );
m_subSections.push_back( subSection );
diff --git a/include/internal/catch_tag_alias_registry.hpp b/include/internal/catch_tag_alias_registry.hpp
index 11d9e65..f7928a6 100644
--- a/include/internal/catch_tag_alias_registry.hpp
+++ b/include/internal/catch_tag_alias_registry.hpp
@@ -27,14 +27,12 @@
std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
std::string expandedTestSpec = unexpandedTestSpec;
- for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end();
- it != itEnd;
- ++it ) {
- std::size_t pos = expandedTestSpec.find( it->first );
+ for( auto const& registryKvp : m_registry ) {
+ std::size_t pos = expandedTestSpec.find( registryKvp.first );
if( pos != std::string::npos ) {
expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
- it->second.tag +
- expandedTestSpec.substr( pos + it->first.size() );
+ registryKvp.second.tag +
+ expandedTestSpec.substr( pos + registryKvp.first.size() );
}
}
return expandedTestSpec;
diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp
index 4aa7044..1c73699 100644
--- a/include/internal/catch_test_case_info.hpp
+++ b/include/internal/catch_test_case_info.hpp
@@ -99,9 +99,9 @@
testCaseInfo.lcaseTags.clear();
std::ostringstream oss;
- for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
- oss << '[' << *it << ']';
- std::string lcaseTag = toLower( *it );
+ for( auto const& tag : tags ) {
+ oss << '[' << tag << ']';
+ std::string lcaseTag = toLower( tag );
testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
testCaseInfo.lcaseTags.insert( lcaseTag );
}
diff --git a/include/internal/catch_test_case_registry_impl.hpp b/include/internal/catch_test_case_registry_impl.hpp
index 316c6c2..ca5c950 100644
--- a/include/internal/catch_test_case_registry_impl.hpp
+++ b/include/internal/catch_test_case_registry_impl.hpp
@@ -68,17 +68,15 @@
void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
std::set<TestCase> seenFunctions;
- for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end();
- it != itEnd;
- ++it ) {
- std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
+ for( auto const function : functions ) {
+ std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( function );
if( !prev.second ) {
std::ostringstream ss;
ss << Colour( Colour::Red )
- << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
+ << "error: TEST_CASE( \"" << function.name << "\" ) already defined.\n"
<< "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << '\n'
- << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
+ << "\tRedefined at " << function.getTestCaseInfo().lineInfo << std::endl;
throw std::runtime_error(ss.str());
}
@@ -88,11 +86,9 @@
std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
std::vector<TestCase> filtered;
filtered.reserve( testCases.size() );
- for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
- it != itEnd;
- ++it )
- if( matchTest( *it, testSpec, config ) )
- filtered.push_back( *it );
+ for( auto const& testCase : testCases )
+ if( matchTest( testCase, testSpec, config ) )
+ filtered.push_back( testCase );
return filtered;
}
std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
diff --git a/include/internal/catch_test_spec.hpp b/include/internal/catch_test_spec.hpp
index 3ec59b5..8565661 100644
--- a/include/internal/catch_test_spec.hpp
+++ b/include/internal/catch_test_spec.hpp
@@ -64,8 +64,8 @@
bool matches( TestCaseInfo const& testCase ) const {
// All patterns in a filter must match for the filter to be a match
- for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
- if( !(*it)->matches( testCase ) )
+ for( auto const& pattern : m_patterns ) {
+ if( !pattern->matches( testCase ) )
return false;
}
return true;
@@ -78,8 +78,8 @@
}
bool matches( TestCaseInfo const& testCase ) const {
// A TestSpec matches if any filter matches
- for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
- if( it->matches( testCase ) )
+ for( auto const& filter : m_filters )
+ if( filter.matches( testCase ) )
return true;
return false;
}
diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp
index 5f18124..6d64b13 100644
--- a/include/reporters/catch_reporter_console.hpp
+++ b/include/reporters/catch_reporter_console.hpp
@@ -218,12 +218,10 @@
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 @@
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 @@
}
}
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 @@
}
else if( value != "0" ) {
stream << Colour( Colour::LightGrey ) << " | ";
- stream << Colour( it->colour )
- << value << ' ' << it->label;
+ stream << Colour( col.colour )
+ << value << ' ' << col.label;
}
}
stream << '\n';
diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp
index a671c68..18e501e 100644
--- a/include/reporters/catch_reporter_junit.hpp
+++ b/include/reporters/catch_reporter_junit.hpp
@@ -118,11 +118,8 @@
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 @@
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 @@
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 );
diff --git a/include/reporters/catch_reporter_multi.hpp b/include/reporters/catch_reporter_multi.hpp
index 0e06892..4dcd6ec 100644
--- a/include/reporters/catch_reporter_multi.hpp
+++ b/include/reporters/catch_reporter_multi.hpp
@@ -28,95 +28,71 @@
}
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 {
diff --git a/include/reporters/catch_reporter_teamcity.hpp b/include/reporters/catch_reporter_teamcity.hpp
index e685a6a..248ea3f 100644
--- a/include/reporters/catch_reporter_teamcity.hpp
+++ b/include/reporters/catch_reporter_teamcity.hpp
@@ -112,12 +112,8 @@
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() ) {
diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp
index 55c1956..546c109 100644
--- a/include/reporters/catch_reporter_xml.hpp
+++ b/include/reporters/catch_reporter_xml.hpp
@@ -99,15 +99,13 @@
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 );
}
}
}