From 1f3ba8a0b670362ad7adc1dc161bef69e0a86c92 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 25 Apr 2017 11:06:52 +0100 Subject: [PATCH] Converted (almost) all for-loops with iterators or indices to range-based --- include/catch_session.hpp | 33 ++++----- include/internal/catch_common.h | 12 ++-- include/internal/catch_config.hpp | 4 +- include/internal/catch_generators.hpp | 6 +- include/internal/catch_generators_impl.hpp | 6 +- .../catch_legacy_reporter_adapter.hpp | 10 ++- include/internal/catch_list.hpp | 49 +++++-------- include/internal/catch_matchers.hpp | 26 ++++--- include/internal/catch_matchers_vector.h | 4 +- include/internal/catch_section_info.hpp | 12 ++-- include/internal/catch_tag_alias_registry.hpp | 10 ++- include/internal/catch_test_case_info.hpp | 6 +- .../catch_test_case_registry_impl.hpp | 18 ++--- include/internal/catch_test_spec.hpp | 8 +-- include/reporters/catch_reporter_console.hpp | 26 ++++--- include/reporters/catch_reporter_junit.hpp | 34 +++------ include/reporters/catch_reporter_multi.hpp | 72 +++++++------------ include/reporters/catch_reporter_teamcity.hpp | 8 +-- include/reporters/catch_reporter_xml.hpp | 12 ++-- 19 files changed, 136 insertions(+), 220 deletions(-) diff --git a/include/catch_session.hpp b/include/catch_session.hpp index be51bef8..8d200aa6 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -37,18 +37,14 @@ namespace Catch { reporters.push_back( "console" ); Ptr reporter; - for( std::vector::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 addListeners( Ptr const& config, Ptr 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 @@ namespace Catch { testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests std::vector const& allTestCases = getAllTestCasesSorted( *iconfig ); - for( std::vector::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 @@ namespace Catch { } void applyFilenamesAsTags( IConfig const& config ) { - std::vector const& tests = getAllTestCasesSorted( config ); - for(std::size_t i = 0; i < tests.size(); ++i ) { - TestCase& test = const_cast( tests[i] ); - std::set tags = test.tags; + auto& tests = const_cast&>( getAllTestCasesSorted( config ) ); + for( auto& testCase : tests ) { + std::set 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 @@ namespace Catch { 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 d325a089..bdf0f318 100644 --- a/include/internal/catch_common.h +++ b/include/internal/catch_common.h @@ -62,17 +62,13 @@ namespace Catch { template 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 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 174850bf..5431cb9a 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -93,8 +93,8 @@ namespace Catch { { 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 a9ba7eb8..e02691cf 100644 --- a/include/internal/catch_generators.hpp +++ b/include/internal/catch_generators.hpp @@ -88,11 +88,9 @@ public: operator T () const { size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); - typename std::vector*>::const_iterator it = m_composed.begin(); - typename std::vector*>::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* 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 fea699ae..51eb80c4 100644 --- a/include/internal/catch_generators_impl.hpp +++ b/include/internal/catch_generators_impl.hpp @@ -62,10 +62,8 @@ namespace Catch { } bool moveNext() { - std::vector::const_iterator it = m_generatorsInOrder.begin(); - std::vector::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 6034581e..17a59181 100644 --- a/include/internal/catch_legacy_reporter_adapter.hpp +++ b/include/internal/catch_legacy_reporter_adapter.hpp @@ -42,12 +42,10 @@ namespace Catch bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) { if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { - for( std::vector::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 e09898e9..fc1cc91a 100644 --- a/include/internal/catch_list.hpp +++ b/include/internal/catch_list.hpp @@ -35,11 +35,8 @@ namespace Catch { tagsAttr.setIndent( 6 ); std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( std::vector::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 @@ namespace Catch { testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); std::size_t matchedTests = 0; std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( std::vector::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 @@ namespace Catch { } std::string all() const { std::string out; - for( std::set::const_iterator it = spellings.begin(), itEnd = spellings.end(); - it != itEnd; - ++it ) - out += "[" + *it + "]"; + for( auto const& spelling : spellings ) + out += "[" + spelling + "]"; return out; } std::set spellings; @@ -106,29 +98,20 @@ namespace Catch { std::map tagCounts; std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); - it != itEnd; - ++it ) { - for( std::set::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::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::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 @@ namespace Catch { 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 2193c540..12f2333e 100644 --- a/include/internal/catch_matchers.hpp +++ b/include/internal/catch_matchers.hpp @@ -55,8 +55,8 @@ namespace Matchers { template struct MatchAllOf : MatcherBase { 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 @@ namespace Matchers { 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 @@ namespace Matchers { struct MatchAnyOf : MatcherBase { 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 @@ namespace Matchers { 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 6a48a4e0..2889013d 100644 --- a/include/internal/catch_matchers_vector.h +++ b/include/internal/catch_matchers_vector.h @@ -40,8 +40,8 @@ namespace Matchers { // !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 aebbf6a5..74fe4c6b 100644 --- a/include/internal/catch_section_info.hpp +++ b/include/internal/catch_section_info.hpp @@ -60,10 +60,8 @@ namespace Catch { 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 @@ namespace Catch { } 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 11d9e65a..f7928a64 100644 --- a/include/internal/catch_tag_alias_registry.hpp +++ b/include/internal/catch_tag_alias_registry.hpp @@ -27,14 +27,12 @@ namespace Catch { std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { std::string expandedTestSpec = unexpandedTestSpec; - for( std::map::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 4aa70441..1c73699b 100644 --- a/include/internal/catch_test_case_info.hpp +++ b/include/internal/catch_test_case_info.hpp @@ -99,9 +99,9 @@ namespace Catch { testCaseInfo.lcaseTags.clear(); std::ostringstream oss; - for( std::set::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.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 316c6c2c..ca5c9504 100644 --- a/include/internal/catch_test_case_registry_impl.hpp +++ b/include/internal/catch_test_case_registry_impl.hpp @@ -68,17 +68,15 @@ namespace Catch { void enforceNoDuplicateTestCases( std::vector const& functions ) { std::set seenFunctions; - for( std::vector::const_iterator it = functions.begin(), itEnd = functions.end(); - it != itEnd; - ++it ) { - std::pair::const_iterator, bool> prev = seenFunctions.insert( *it ); + for( auto const function : functions ) { + std::pair::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 @@ namespace Catch { std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ) { std::vector filtered; filtered.reserve( testCases.size() ); - for( std::vector::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 const& getAllTestCasesSorted( IConfig const& config ) { diff --git a/include/internal/catch_test_spec.hpp b/include/internal/catch_test_spec.hpp index 3ec59b55..8565661a 100644 --- a/include/internal/catch_test_spec.hpp +++ b/include/internal/catch_test_spec.hpp @@ -64,8 +64,8 @@ namespace Catch { bool matches( TestCaseInfo const& testCase ) const { // All patterns in a filter must match for the filter to be a match - for( std::vector >::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 @@ namespace Catch { } bool matches( TestCaseInfo const& testCase ) const { // A TestSpec matches if any filter matches - for( std::vector::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 5f181241..6d64b132 100644 --- a/include/reporters/catch_reporter_console.hpp +++ b/include/reporters/catch_reporter_console.hpp @@ -218,12 +218,10 @@ namespace Catch { void printMessage() const { if( !messageLabel.empty() ) stream << messageLabel << ':' << '\n'; - for( std::vector::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::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 const& cols, std::size_t row ) { - for( std::vector::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'; diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp index a671c68f..18e501ee 100644 --- a/include/reporters/catch_reporter_junit.hpp +++ b/include/reporters/catch_reporter_junit.hpp @@ -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::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 0e06892f..4dcd6ec0 100644 --- a/include/reporters/catch_reporter_multi.hpp +++ b/include/reporters/catch_reporter_multi.hpp @@ -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 { diff --git a/include/reporters/catch_reporter_teamcity.hpp b/include/reporters/catch_reporter_teamcity.hpp index e685a6ad..248ea3fb 100644 --- a/include/reporters/catch_reporter_teamcity.hpp +++ b/include/reporters/catch_reporter_teamcity.hpp @@ -112,12 +112,8 @@ namespace Catch { msg << " with message:"; if( assertionStats.infoMessages.size() > 1 ) msg << " with messages:"; - for( std::vector::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 55c19564..546c1095 100644 --- a/include/reporters/catch_reporter_xml.hpp +++ b/include/reporters/catch_reporter_xml.hpp @@ -99,15 +99,13 @@ namespace Catch { if( includeResults ) { // Print any info messages in tags. - for( std::vector::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 ); } } }