Converted (almost) all for-loops with iterators or indices to range-based

This commit is contained in:
Phil Nash 2017-04-25 11:06:52 +01:00
parent 073377a4e4
commit 1f3ba8a0b6
19 changed files with 136 additions and 220 deletions

View File

@ -37,18 +37,14 @@ namespace Catch {
reporters.push_back( "console" ); reporters.push_back( "console" );
Ptr<IStreamingReporter> reporter; Ptr<IStreamingReporter> reporter;
for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end(); for( auto const& name : reporters )
it != itEnd; reporter = addReporter( reporter, createReporter( name, config ) );
++it )
reporter = addReporter( reporter, createReporter( *it, config ) );
return reporter; return reporter;
} }
Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) { Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners(); IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end(); for( auto const& listener : listeners )
it != itEnd; reporters = addReporter(reporters, listener->create( ReporterConfig( config ) ) );
++it )
reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) );
return reporters; return reporters;
} }
@ -71,13 +67,11 @@ namespace Catch {
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig ); std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end(); for( auto const& testCase : allTestCases ) {
it != itEnd; if( !context.aborting() && matchTest( testCase, testSpec, *iconfig ) )
++it ) { totals += context.runTest( testCase );
if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
totals += context.runTest( *it );
else else
reporter->skipTest( *it ); reporter->skipTest( testCase );
} }
context.testGroupEnded( iconfig->name(), totals, 1, 1 ); context.testGroupEnded( iconfig->name(), totals, 1, 1 );
@ -85,12 +79,11 @@ namespace Catch {
} }
void applyFilenamesAsTags( IConfig const& config ) { void applyFilenamesAsTags( IConfig const& config ) {
std::vector<TestCase> const& tests = getAllTestCasesSorted( config ); auto& tests = const_cast<std::vector<TestCase>&>( getAllTestCasesSorted( config ) );
for(std::size_t i = 0; i < tests.size(); ++i ) { for( auto& testCase : tests ) {
TestCase& test = const_cast<TestCase&>( tests[i] ); std::set<std::string> tags = testCase.tags;
std::set<std::string> tags = test.tags;
std::string filename = test.lineInfo.file; std::string filename = testCase.lineInfo.file;
std::string::size_type lastSlash = filename.find_last_of( "\\/" ); std::string::size_type lastSlash = filename.find_last_of( "\\/" );
if( lastSlash != std::string::npos ) if( lastSlash != std::string::npos )
filename = filename.substr( lastSlash+1 ); filename = filename.substr( lastSlash+1 );
@ -100,7 +93,7 @@ namespace Catch {
filename = filename.substr( 0, lastDot ); filename = filename.substr( 0, lastDot );
tags.insert( "#" + filename ); tags.insert( "#" + filename );
setTags( test, tags ); setTags( testCase, tags );
} }
} }

View File

@ -62,17 +62,13 @@ namespace Catch {
template<typename ContainerT> template<typename ContainerT>
inline void deleteAll( ContainerT& container ) { inline void deleteAll( ContainerT& container ) {
typename ContainerT::const_iterator it = container.begin(); for( auto p : container )
typename ContainerT::const_iterator itEnd = container.end(); delete p;
for(; it != itEnd; ++it )
delete *it;
} }
template<typename AssociativeContainerT> template<typename AssociativeContainerT>
inline void deleteAllValues( AssociativeContainerT& container ) { inline void deleteAllValues( AssociativeContainerT& container ) {
typename AssociativeContainerT::const_iterator it = container.begin(); for( auto const& kvp : container )
typename AssociativeContainerT::const_iterator itEnd = container.end(); delete kvp.second;
for(; it != itEnd; ++it )
delete it->second;
} }
bool startsWith( std::string const& s, std::string const& prefix ); bool startsWith( std::string const& s, std::string const& prefix );

View File

@ -93,8 +93,8 @@ namespace Catch {
{ {
if( !data.testsOrTags.empty() ) { if( !data.testsOrTags.empty() ) {
TestSpecParser parser( ITagAliasRegistry::get() ); TestSpecParser parser( ITagAliasRegistry::get() );
for( std::size_t i = 0; i < data.testsOrTags.size(); ++i ) for( auto const& testOrTags : data.testsOrTags )
parser.parse( data.testsOrTags[i] ); parser.parse( testOrTags );
m_testSpec = parser.testSpec(); m_testSpec = parser.testSpec();
} }
} }

View File

@ -88,11 +88,9 @@ public:
operator T () const { operator T () const {
size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin(); size_t index = 0;
typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end(); for( auto generator : m_composed )
for( size_t index = 0; it != itEnd; ++it )
{ {
const IGenerator<T>* generator = *it;
if( overallIndex >= index && overallIndex < index + generator->size() ) if( overallIndex >= index && overallIndex < index + generator->size() )
{ {
return generator->getValue( overallIndex-index ); return generator->getValue( overallIndex-index );

View File

@ -62,10 +62,8 @@ namespace Catch {
} }
bool moveNext() { bool moveNext() {
std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin(); for( auto generator : m_generatorsInOrder ) {
std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end(); if( generator->moveNext() )
for(; it != itEnd; ++it ) {
if( (*it)->moveNext() )
return true; return true;
} }
return false; return false;

View File

@ -42,12 +42,10 @@ namespace Catch
bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) { bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); for( auto const& messageInfo : assertionStats.infoMessages ) {
it != itEnd; if( messageInfo.type == ResultWas::Info ) {
++it ) { ResultBuilder rb( messageInfo.macroName.c_str(), messageInfo.lineInfo, "", ResultDisposition::Normal );
if( it->type == ResultWas::Info ) { rb << messageInfo.message;
ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
rb << it->message;
rb.setResultType( ResultWas::Info ); rb.setResultType( ResultWas::Info );
AssertionResult result = rb.build(); AssertionResult result = rb.build();
m_legacyReporter->Result( result ); m_legacyReporter->Result( result );

View File

@ -35,11 +35,8 @@ namespace Catch {
tagsAttr.setIndent( 6 ); tagsAttr.setIndent( 6 );
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); for( auto const& testCaseInfo : matchedTestCases ) {
it != itEnd;
++it ) {
matchedTests++; matchedTests++;
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
Colour::Code colour = testCaseInfo.isHidden() Colour::Code colour = testCaseInfo.isHidden()
? Colour::SecondaryText ? Colour::SecondaryText
: Colour::None; : Colour::None;
@ -63,11 +60,8 @@ namespace Catch {
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
std::size_t matchedTests = 0; std::size_t matchedTests = 0;
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); for( auto const& testCaseInfo : matchedTestCases ) {
it != itEnd;
++it ) {
matchedTests++; matchedTests++;
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
if( startsWith( testCaseInfo.name, '#' ) ) if( startsWith( testCaseInfo.name, '#' ) )
Catch::cout() << '"' << testCaseInfo.name << '"' << std::endl; Catch::cout() << '"' << testCaseInfo.name << '"' << std::endl;
else else
@ -84,10 +78,8 @@ namespace Catch {
} }
std::string all() const { std::string all() const {
std::string out; std::string out;
for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end(); for( auto const& spelling : spellings )
it != itEnd; out += "[" + spelling + "]";
++it )
out += "[" + *it + "]";
return out; return out;
} }
std::set<std::string> spellings; std::set<std::string> spellings;
@ -106,29 +98,20 @@ namespace Catch {
std::map<std::string, TagInfo> tagCounts; std::map<std::string, TagInfo> tagCounts;
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); for( auto const& testCase : matchedTestCases ) {
it != itEnd; for( auto const& tagName : testCase.getTestCaseInfo().tags ) {
++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;
std::string lcaseTagName = toLower( tagName ); std::string lcaseTagName = toLower( tagName );
std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName ); auto countIt = tagCounts.find( lcaseTagName );
if( countIt == tagCounts.end() ) if( countIt == tagCounts.end() )
countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
countIt->second.add( tagName ); countIt->second.add( tagName );
} }
} }
for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(), for( auto const& tagCount : tagCounts ) {
countItEnd = tagCounts.end();
countIt != countItEnd;
++countIt ) {
std::ostringstream oss; std::ostringstream oss;
oss << " " << std::setw(2) << countIt->second.count << " "; oss << " " << std::setw(2) << tagCount.second.count << " ";
Text wrapper( countIt->second.all(), TextAttributes() Text wrapper( tagCount.second.all(), TextAttributes()
.setInitialIndent( 0 ) .setInitialIndent( 0 )
.setIndent( oss.str().size() ) .setIndent( oss.str().size() )
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) ); .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
@ -143,18 +126,18 @@ namespace Catch {
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it; IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
std::size_t maxNameLen = 0; std::size_t maxNameLen = 0;
for(it = itBegin; it != itEnd; ++it ) for( auto const factoryKvp : getRegistryHub().getReporterRegistry().getFactories() )
maxNameLen = (std::max)( maxNameLen, it->first.size() ); maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
for(it = itBegin; it != itEnd; ++it ) { for( auto const factoryKvp : getRegistryHub().getReporterRegistry().getFactories() ) {
Text wrapper( it->second->getDescription(), TextAttributes() Text wrapper( factoryKvp.second->getDescription(), TextAttributes()
.setInitialIndent( 0 ) .setInitialIndent( 0 )
.setIndent( 7+maxNameLen ) .setIndent( 7+maxNameLen )
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) ); .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
Catch::cout() << " " Catch::cout() << " "
<< it->first << factoryKvp.first
<< ':' << ':'
<< std::string( maxNameLen - it->first.size() + 2, ' ' ) << std::string( maxNameLen - factoryKvp.first.size() + 2, ' ' )
<< wrapper << '\n'; << wrapper << '\n';
} }
Catch::cout() << std::endl; Catch::cout() << std::endl;

View File

@ -55,8 +55,8 @@ namespace Matchers {
template<typename ArgT> template<typename ArgT>
struct MatchAllOf : MatcherBase<ArgT> { struct MatchAllOf : MatcherBase<ArgT> {
virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE { virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
for( std::size_t i = 0; i < m_matchers.size(); ++i ) { for( auto matcher : m_matchers ) {
if (!m_matchers[i]->match(arg)) if (!matcher->match(arg))
return false; return false;
} }
return true; return true;
@ -65,10 +65,13 @@ namespace Matchers {
std::string description; std::string description;
description.reserve( 4 + m_matchers.size()*32 ); description.reserve( 4 + m_matchers.size()*32 );
description += "( "; description += "( ";
for( std::size_t i = 0; i < m_matchers.size(); ++i ) { bool first = true;
if( i != 0 ) for( auto matcher : m_matchers ) {
if( first )
first = false;
else
description += " and "; description += " and ";
description += m_matchers[i]->toString(); description += matcher->toString();
} }
description += " )"; description += " )";
return description; return description;
@ -85,8 +88,8 @@ namespace Matchers {
struct MatchAnyOf : MatcherBase<ArgT> { struct MatchAnyOf : MatcherBase<ArgT> {
virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE { virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
for( std::size_t i = 0; i < m_matchers.size(); ++i ) { for( auto matcher : m_matchers ) {
if (m_matchers[i]->match(arg)) if (matcher->match(arg))
return true; return true;
} }
return false; return false;
@ -95,10 +98,13 @@ namespace Matchers {
std::string description; std::string description;
description.reserve( 4 + m_matchers.size()*32 ); description.reserve( 4 + m_matchers.size()*32 );
description += "( "; description += "( ";
for( std::size_t i = 0; i < m_matchers.size(); ++i ) { bool first = true;
if( i != 0 ) for( auto matcher : m_matchers ) {
if( first )
first = false;
else
description += " or "; description += " or ";
description += m_matchers[i]->toString(); description += matcher->toString();
} }
description += " )"; description += " )";
return description; return description;

View File

@ -40,8 +40,8 @@ namespace Matchers {
// !TBD: see note in EqualsMatcher // !TBD: see note in EqualsMatcher
if (m_comparator.size() > v.size()) if (m_comparator.size() > v.size())
return false; return false;
for (size_t i = 0; i < m_comparator.size(); ++i) for ( auto const& comparator : m_comparator )
if (std::find(v.begin(), v.end(), m_comparator[i]) == v.end()) if (std::find(v.begin(), v.end(), comparator) == v.end())
return false; return false;
return true; return true;
} }

View File

@ -60,10 +60,8 @@ namespace Catch {
bool hasUntestedSections() const { bool hasUntestedSections() const {
if( m_state == Unknown ) if( m_state == Unknown )
return true; return true;
for( SubSections::const_iterator it = m_subSections.begin(); for( auto subSection : m_subSections )
it != m_subSections.end(); if( subSection->hasUntestedSections() )
++it)
if( (*it)->hasUntestedSections() )
return true; return true;
return false; return false;
} }
@ -75,10 +73,8 @@ namespace Catch {
} }
RunningSection* findOrAddSubSection( std::string const& name, bool& changed ) { RunningSection* findOrAddSubSection( std::string const& name, bool& changed ) {
for( SubSections::const_iterator it = m_subSections.begin(); for( auto subSection : m_subSections )
it != m_subSections.end(); if( subSection->getName() == name )
++it)
if( (*it)->getName() == name )
return *it; return *it;
RunningSection* subSection = new RunningSection( this, name ); RunningSection* subSection = new RunningSection( this, name );
m_subSections.push_back( subSection ); m_subSections.push_back( subSection );

View File

@ -27,14 +27,12 @@ namespace Catch {
std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
std::string expandedTestSpec = unexpandedTestSpec; std::string expandedTestSpec = unexpandedTestSpec;
for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end(); for( auto const& registryKvp : m_registry ) {
it != itEnd; std::size_t pos = expandedTestSpec.find( registryKvp.first );
++it ) {
std::size_t pos = expandedTestSpec.find( it->first );
if( pos != std::string::npos ) { if( pos != std::string::npos ) {
expandedTestSpec = expandedTestSpec.substr( 0, pos ) + expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
it->second.tag + registryKvp.second.tag +
expandedTestSpec.substr( pos + it->first.size() ); expandedTestSpec.substr( pos + registryKvp.first.size() );
} }
} }
return expandedTestSpec; return expandedTestSpec;

View File

@ -99,9 +99,9 @@ namespace Catch {
testCaseInfo.lcaseTags.clear(); testCaseInfo.lcaseTags.clear();
std::ostringstream oss; std::ostringstream oss;
for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) { for( auto const& tag : tags ) {
oss << '[' << *it << ']'; oss << '[' << tag << ']';
std::string lcaseTag = toLower( *it ); std::string lcaseTag = toLower( tag );
testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
testCaseInfo.lcaseTags.insert( lcaseTag ); testCaseInfo.lcaseTags.insert( lcaseTag );
} }

View File

@ -68,17 +68,15 @@ namespace Catch {
void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) { void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
std::set<TestCase> seenFunctions; std::set<TestCase> seenFunctions;
for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end(); for( auto const function : functions ) {
it != itEnd; std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( function );
++it ) {
std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
if( !prev.second ) { if( !prev.second ) {
std::ostringstream ss; std::ostringstream ss;
ss << Colour( Colour::Red ) 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' << "\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()); throw std::runtime_error(ss.str());
} }
@ -88,11 +86,9 @@ namespace Catch {
std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) { std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
std::vector<TestCase> filtered; std::vector<TestCase> filtered;
filtered.reserve( testCases.size() ); filtered.reserve( testCases.size() );
for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end(); for( auto const& testCase : testCases )
it != itEnd; if( matchTest( testCase, testSpec, config ) )
++it ) filtered.push_back( testCase );
if( matchTest( *it, testSpec, config ) )
filtered.push_back( *it );
return filtered; return filtered;
} }
std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) { std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {

View File

@ -64,8 +64,8 @@ namespace Catch {
bool matches( TestCaseInfo const& testCase ) const { bool matches( TestCaseInfo const& testCase ) const {
// All patterns in a filter must match for the filter to be a match // 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 ) { for( auto const& pattern : m_patterns ) {
if( !(*it)->matches( testCase ) ) if( !pattern->matches( testCase ) )
return false; return false;
} }
return true; return true;
@ -78,8 +78,8 @@ namespace Catch {
} }
bool matches( TestCaseInfo const& testCase ) const { bool matches( TestCaseInfo const& testCase ) const {
// A TestSpec matches if any filter matches // A TestSpec matches if any filter matches
for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it ) for( auto const& filter : m_filters )
if( it->matches( testCase ) ) if( filter.matches( testCase ) )
return true; return true;
return false; return false;
} }

View File

@ -218,12 +218,10 @@ namespace Catch {
void printMessage() const { void printMessage() const {
if( !messageLabel.empty() ) if( !messageLabel.empty() )
stream << messageLabel << ':' << '\n'; stream << messageLabel << ':' << '\n';
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end(); for( auto const& message : messages ) {
it != itEnd;
++it ) {
// If this assertion is a warning ignore any INFO messages // If this assertion is a warning ignore any INFO messages
if( printInfoMessages || it->type != ResultWas::Info ) if( printInfoMessages || message.type != ResultWas::Info )
stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n'; stream << Text( message.message, TextAttributes().setIndent(2) ) << '\n';
} }
} }
void printSourceInfo() const { void printSourceInfo() const {
@ -331,10 +329,10 @@ namespace Catch {
std::ostringstream oss; std::ostringstream oss;
oss << count; oss << count;
std::string row = oss.str(); std::string row = oss.str();
for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) { for( auto& oldRow : rows ) {
while( it->size() < row.size() ) while( oldRow.size() < row.size() )
*it = ' ' + *it; oldRow = ' ' + oldRow;
while( it->size() > row.size() ) while( oldRow.size() > row.size() )
row = ' ' + row; row = ' ' + row;
} }
rows.push_back( 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 ) { 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 ) { for( auto col : cols ) {
std::string value = it->rows[row]; std::string value = col.rows[row];
if( it->label.empty() ) { if( col.label.empty() ) {
stream << label << ": "; stream << label << ": ";
if( value != "0" ) if( value != "0" )
stream << value; stream << value;
@ -390,8 +388,8 @@ namespace Catch {
} }
else if( value != "0" ) { else if( value != "0" ) {
stream << Colour( Colour::LightGrey ) << " | "; stream << Colour( Colour::LightGrey ) << " | ";
stream << Colour( it->colour ) stream << Colour( col.colour )
<< value << ' ' << it->label; << value << ' ' << col.label;
} }
} }
stream << '\n'; stream << '\n';

View File

@ -118,11 +118,8 @@ namespace Catch {
xml.writeAttribute( "timestamp", getCurrentTimestamp() ); xml.writeAttribute( "timestamp", getCurrentTimestamp() );
// Write test cases // Write test cases
for( TestGroupNode::ChildNodes::const_iterator for( auto const& child : groupNode.children )
it = groupNode.children.begin(), itEnd = groupNode.children.end(); writeTestCase( *child );
it != itEnd;
++it )
writeTestCase( **it );
xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false ); xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false );
xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false ); xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
@ -173,23 +170,16 @@ namespace Catch {
if( !sectionNode.stdErr.empty() ) if( !sectionNode.stdErr.empty() )
xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
} }
for( SectionNode::ChildSections::const_iterator for( auto const& childNode : sectionNode.childSections )
it = sectionNode.childSections.begin(),
itEnd = sectionNode.childSections.end();
it != itEnd;
++it )
if( className.empty() ) if( className.empty() )
writeSection( name, "", **it ); writeSection( name, "", *childNode );
else else
writeSection( className, name, **it ); writeSection( className, name, *childNode );
} }
void writeAssertions( SectionNode const& sectionNode ) { void writeAssertions( SectionNode const& sectionNode ) {
for( SectionNode::Assertions::const_iterator for( auto const& assertion : sectionNode.assertions )
it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end(); writeAssertion( assertion );
it != itEnd;
++it )
writeAssertion( *it );
} }
void writeAssertion( AssertionStats const& stats ) { void writeAssertion( AssertionStats const& stats ) {
AssertionResult const& result = stats.assertionResult; AssertionResult const& result = stats.assertionResult;
@ -229,13 +219,9 @@ namespace Catch {
std::ostringstream oss; std::ostringstream oss;
if( !result.getMessage().empty() ) if( !result.getMessage().empty() )
oss << result.getMessage() << '\n'; oss << result.getMessage() << '\n';
for( std::vector<MessageInfo>::const_iterator for( auto const& msg : stats.infoMessages )
it = stats.infoMessages.begin(), if( msg.type == ResultWas::Info )
itEnd = stats.infoMessages.end(); oss << msg.message << '\n';
it != itEnd;
++it )
if( it->type == ResultWas::Info )
oss << it->message << '\n';
oss << "at " << result.getSourceInfo(); oss << "at " << result.getSourceInfo();
xml.writeText( oss.str(), false ); xml.writeText( oss.str(), false );

View File

@ -28,95 +28,71 @@ public: // IStreamingReporter
} }
virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE { virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->noMatchingTestCases( spec );
++it )
(*it)->noMatchingTestCases( spec );
} }
virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE { virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->testRunStarting( testRunInfo );
++it )
(*it)->testRunStarting( testRunInfo );
} }
virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE { virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->testGroupStarting( groupInfo );
++it )
(*it)->testGroupStarting( groupInfo );
} }
virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->testCaseStarting( testInfo );
++it )
(*it)->testCaseStarting( testInfo );
} }
virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->sectionStarting( sectionInfo );
++it )
(*it)->sectionStarting( sectionInfo );
} }
virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE { virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->assertionStarting( assertionInfo );
++it )
(*it)->assertionStarting( assertionInfo );
} }
// The return value indicates if the messages buffer should be cleared: // The return value indicates if the messages buffer should be cleared:
virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
bool clearBuffer = false; bool clearBuffer = false;
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; clearBuffer |= reporter->assertionEnded( assertionStats );
++it )
clearBuffer |= (*it)->assertionEnded( assertionStats );
return clearBuffer; return clearBuffer;
} }
virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE { virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->sectionEnded( sectionStats );
++it )
(*it)->sectionEnded( sectionStats );
} }
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->testCaseEnded( testCaseStats );
++it )
(*it)->testCaseEnded( testCaseStats );
} }
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->testGroupEnded( testGroupStats );
++it )
(*it)->testGroupEnded( testGroupStats );
} }
virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE { virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->testRunEnded( testRunStats );
++it )
(*it)->testRunEnded( testRunStats );
} }
virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); for( auto const& reporter : m_reporters )
it != itEnd; reporter->skipTest( testInfo );
++it )
(*it)->skipTest( testInfo );
} }
virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE { virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {

View File

@ -112,12 +112,8 @@ namespace Catch {
msg << " with message:"; msg << " with message:";
if( assertionStats.infoMessages.size() > 1 ) if( assertionStats.infoMessages.size() > 1 )
msg << " with messages:"; msg << " with messages:";
for( std::vector<MessageInfo>::const_iterator for( auto const& messageInfo : assertionStats.infoMessages )
it = assertionStats.infoMessages.begin(), msg << "\n \"" << messageInfo.message << "\"";
itEnd = assertionStats.infoMessages.end();
it != itEnd;
++it )
msg << "\n \"" << it->message << "\"";
if( result.hasExpression() ) { if( result.hasExpression() ) {

View File

@ -99,15 +99,13 @@ namespace Catch {
if( includeResults ) { if( includeResults ) {
// Print any info messages in <Info> tags. // Print any info messages in <Info> tags.
for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); for( auto const& msg : assertionStats.infoMessages ) {
it != itEnd; if( msg.type == ResultWas::Info ) {
++it ) {
if( it->type == ResultWas::Info ) {
m_xml.scopedElement( "Info" ) m_xml.scopedElement( "Info" )
.writeText( it->message ); .writeText( msg.message );
} else if ( it->type == ResultWas::Warning ) { } else if ( msg.type == ResultWas::Warning ) {
m_xml.scopedElement( "Warning" ) m_xml.scopedElement( "Warning" )
.writeText( it->message ); .writeText( msg.message );
} }
} }
} }