Merge branch 'dev-performance-round2'

This commit is contained in:
Martin Hořeňovský
2017-01-30 13:02:48 +01:00
16 changed files with 86 additions and 82 deletions

View File

@@ -56,7 +56,7 @@ namespace Catch {
std::string AssertionResult::getExpression() const {
if( isFalseTest( m_info.resultDisposition ) )
return "!" + m_info.capturedExpression;
return '!' + m_info.capturedExpression;
else
return m_info.capturedExpression;
}

View File

@@ -30,7 +30,7 @@ namespace Catch {
if( _warning == "NoAssertions" )
config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
else
throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" );
throw std::runtime_error( "Unrecognised warning: '" + _warning + '\'' );
}
inline void setOrder( ConfigData& config, std::string const& order ) {
if( startsWith( "declared", order ) )
@@ -40,7 +40,7 @@ namespace Catch {
else if( startsWith( "random", order ) )
config.runOrder = RunTests::InRandomOrder;
else
throw std::runtime_error( "Unrecognised ordering: '" + order + "'" );
throw std::runtime_error( "Unrecognised ordering: '" + order + '\'' );
}
inline void setRngSeed( ConfigData& config, std::string const& seed ) {
if( seed == "time" ) {
@@ -88,7 +88,7 @@ namespace Catch {
line = trim(line);
if( !line.empty() && !startsWith( line, '#' ) ) {
if( !startsWith( line, '"' ) )
line = "\"" + line + "\"";
line = '"' + line + '"';
addTestOrTags( config, line + ',' );
}
}

View File

@@ -102,8 +102,8 @@ namespace Catch {
SourceLineInfo();
SourceLineInfo( char const* _file, std::size_t _line );
SourceLineInfo( SourceLineInfo const& other );
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
SourceLineInfo(SourceLineInfo const& other) = default;
SourceLineInfo( SourceLineInfo && ) = default;
SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
SourceLineInfo& operator = ( SourceLineInfo && ) = default;
@@ -112,7 +112,7 @@ namespace Catch {
bool operator == ( SourceLineInfo const& other ) const;
bool operator < ( SourceLineInfo const& other ) const;
std::string file;
char const* file;
std::size_t line;
};

View File

@@ -10,6 +10,8 @@
#include "catch_common.h"
#include <cstring>
namespace Catch {
bool startsWith( std::string const& s, std::string const& prefix ) {
@@ -69,29 +71,25 @@ namespace Catch {
{}
std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
os << pluraliser.m_count << " " << pluraliser.m_label;
os << pluraliser.m_count << ' ' << pluraliser.m_label;
if( pluraliser.m_count != 1 )
os << "s";
os << 's';
return os;
}
SourceLineInfo::SourceLineInfo() : line( 0 ){}
SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){}
SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
: file( _file ),
line( _line )
{}
SourceLineInfo::SourceLineInfo( SourceLineInfo const& other )
: file( other.file ),
line( other.line )
{}
bool SourceLineInfo::empty() const {
return file.empty();
return file[0] == '\0';
}
bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
return line == other.line && file == other.file;
return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
}
bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
return line < other.line || ( line == other.line && file < other.file );
return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
}
void seedRng( IConfig const& config ) {
@@ -113,7 +111,7 @@ namespace Catch {
void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) {
std::ostringstream oss;
oss << locationInfo << ": Internal Catch error: '" << message << "'";
oss << locationInfo << ": Internal Catch error: '" << message << '\'';
if( alwaysTrue() )
throw std::logic_error( oss.str() );
}

View File

@@ -69,7 +69,7 @@ namespace Catch {
matchedTests++;
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
if( startsWith( testCaseInfo.name, '#' ) )
Catch::cout() << "\"" << testCaseInfo.name << "\"" << std::endl;
Catch::cout() << '"' << testCaseInfo.name << '"' << std::endl;
else
Catch::cout() << testCaseInfo.name << std::endl;
}
@@ -132,9 +132,9 @@ namespace Catch {
.setInitialIndent( 0 )
.setIndent( oss.str().size() )
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
Catch::cout() << oss.str() << wrapper << "\n";
Catch::cout() << oss.str() << wrapper << '\n';
}
Catch::cout() << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl;
Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
return tagCounts.size();
}
@@ -153,9 +153,9 @@ namespace Catch {
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
Catch::cout() << " "
<< it->first
<< ":"
<< ':'
<< std::string( maxNameLen - it->first.size() + 2, ' ' )
<< wrapper << "\n";
<< wrapper << '\n';
}
Catch::cout() << std::endl;
return factories.size();

View File

@@ -202,7 +202,7 @@ namespace Matchers {
return m_data.m_str == m_data.adjustString( expr );;
}
virtual std::string toString() const {
return "equals: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
return "equals: \"" + m_data.m_str + '"' + m_data.toStringSuffix();
}
CasedString m_data;
@@ -219,7 +219,7 @@ namespace Matchers {
return m_data.adjustString( expr ).find( m_data.m_str ) != std::string::npos;
}
virtual std::string toString() const {
return "contains: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
return "contains: \"" + m_data.m_str + '"' + m_data.toStringSuffix();
}
CasedString m_data;
@@ -237,7 +237,7 @@ namespace Matchers {
return startsWith( m_data.adjustString( expr ), m_data.m_str );
}
virtual std::string toString() const {
return "starts with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
return "starts with: \"" + m_data.m_str + '"' + m_data.toStringSuffix();
}
CasedString m_data;
@@ -254,7 +254,7 @@ namespace Matchers {
return endsWith( m_data.adjustString( expr ), m_data.m_str );
}
virtual std::string toString() const {
return "ends with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
return "ends with: \"" + m_data.m_str + '"' + m_data.toStringSuffix();
}
CasedString m_data;

View File

@@ -61,7 +61,7 @@ namespace Catch {
m_ofs.open( filename.c_str() );
if( m_ofs.fail() ) {
std::ostringstream oss;
oss << "Unable to open file: '" << filename << "'";
oss << "Unable to open file: '" << filename << '\'';
throw std::domain_error( oss.str() );
}
}

View File

@@ -102,7 +102,7 @@ namespace Catch {
std::ostringstream oss;
for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
oss << "[" << *it << "]";
oss << '[' << *it << ']';
std::string lcaseTag = toLower( *it );
testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
testCaseInfo.lcaseTags.insert( lcaseTag );

View File

@@ -69,7 +69,7 @@ std::string toString( std::string const& value ) {
}
}
}
return "\"" + s + "\"";
return '"' + s + '"';
}
std::string toString( std::wstring const& value ) {
@@ -138,7 +138,7 @@ std::string toString( const double value ) {
return fpToString( value, 10 );
}
std::string toString( const float value ) {
return fpToString( value, 5 ) + "f";
return fpToString( value, 5 ) + 'f';
}
std::string toString( bool value ) {

View File

@@ -26,13 +26,13 @@ namespace Catch {
{}
std::ostream& operator << ( std::ostream& os, Version const& version ) {
os << version.majorVersion << "."
<< version.minorVersion << "."
os << version.majorVersion << '.'
<< version.minorVersion << '.'
<< version.patchNumber;
if( !version.branchName.empty() ) {
os << "-" << version.branchName
<< "." << version.buildNumber;
os << '-' << version.branchName
<< '.' << version.buildNumber;
}
return os;
}

View File

@@ -136,7 +136,7 @@ namespace Catch {
XmlWriter& startElement( std::string const& name ) {
ensureTagClosed();
newlineIfNecessary();
stream() << m_indent << "<" << name;
stream() << m_indent << '<' << name;
m_tags.push_back( name );
m_indent += " ";
m_tagIsOpen = true;
@@ -165,12 +165,12 @@ namespace Catch {
XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) {
if( !name.empty() && !attribute.empty() )
stream() << " " << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << "\"";
stream() << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"';
return *this;
}
XmlWriter& writeAttribute( std::string const& name, bool attribute ) {
stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\"";
stream() << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"';
return *this;
}
@@ -227,7 +227,7 @@ namespace Catch {
void newlineIfNecessary() {
if( m_needsNewline ) {
stream() << "\n";
stream() << '\n';
m_needsNewline = false;
}
}