mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 11:43:29 +01:00
Removed redundant .c_str()s from StringRef usages
This commit is contained in:
parent
fa3535e95e
commit
ece64c3b3a
@ -79,7 +79,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
void AssertionHandler::handle( ResultWas::OfType resultType, StringRef const& message ) {
|
void AssertionHandler::handle( ResultWas::OfType resultType, StringRef const& message ) {
|
||||||
AssertionResultData data( resultType, LazyExpression( false ) );
|
AssertionResultData data( resultType, LazyExpression( false ) );
|
||||||
data.message = message.c_str();
|
data.message = message;
|
||||||
handle( data, nullptr );
|
handle( data, nullptr );
|
||||||
}
|
}
|
||||||
void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) {
|
void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) {
|
||||||
@ -126,7 +126,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AssertionHandler::useActiveException() {
|
void AssertionHandler::useActiveException() {
|
||||||
handle( ResultWas::ThrewException, Catch::translateActiveException().c_str() );
|
handle( ResultWas::ThrewException, Catch::translateActiveException() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssertionHandler::setExceptionGuard() {
|
void AssertionHandler::setExceptionGuard() {
|
||||||
|
@ -52,16 +52,23 @@ namespace Catch {
|
|||||||
|
|
||||||
std::string AssertionResult::getExpression() const {
|
std::string AssertionResult::getExpression() const {
|
||||||
if (isFalseTest(m_info.resultDisposition))
|
if (isFalseTest(m_info.resultDisposition))
|
||||||
return '!' + std::string(m_info.capturedExpression.c_str());
|
return '!' + std::string(m_info.capturedExpression);
|
||||||
else
|
else
|
||||||
return std::string(m_info.capturedExpression.c_str());
|
return m_info.capturedExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AssertionResult::getExpressionInMacro() const {
|
std::string AssertionResult::getExpressionInMacro() const {
|
||||||
|
std::string expr;
|
||||||
if( m_info.macroName[0] == 0 )
|
if( m_info.macroName[0] == 0 )
|
||||||
return std::string(m_info.capturedExpression.c_str());
|
expr = m_info.capturedExpression;
|
||||||
else
|
else {
|
||||||
return std::string(m_info.macroName.c_str()) + "( " + m_info.capturedExpression.c_str() + " )";
|
expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 );
|
||||||
|
expr += m_info.macroName;
|
||||||
|
expr += "( ";
|
||||||
|
expr += m_info.capturedExpression;
|
||||||
|
expr += " )";
|
||||||
|
}
|
||||||
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AssertionResult::hasExpandedExpression() const {
|
bool AssertionResult::hasExpandedExpression() const {
|
||||||
@ -83,7 +90,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string AssertionResult::getTestMacroName() const {
|
std::string AssertionResult::getTestMacroName() const {
|
||||||
return m_info.macroName.c_str();
|
return m_info.macroName;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -28,7 +28,7 @@ namespace Catch {
|
|||||||
public:
|
public:
|
||||||
// Keep most of this inline as it's on the code path that is being timed
|
// Keep most of this inline as it's on the code path that is being timed
|
||||||
BenchmarkLooper( StringRef name )
|
BenchmarkLooper( StringRef name )
|
||||||
: m_name( name.c_str() ),
|
: m_name( name ),
|
||||||
m_resolution( getResolution() )
|
m_resolution( getResolution() )
|
||||||
{
|
{
|
||||||
reportStart();
|
reportStart();
|
||||||
|
@ -126,7 +126,7 @@
|
|||||||
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
|
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
|
||||||
do { \
|
do { \
|
||||||
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
||||||
catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str().c_str() ); \
|
catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ namespace Catch {
|
|||||||
auto matcherAsString = m_matcher.toString();
|
auto matcherAsString = m_matcher.toString();
|
||||||
os << Catch::Detail::stringify( m_arg ) << ' ';
|
os << Catch::Detail::stringify( m_arg ) << ' ';
|
||||||
if( matcherAsString == Detail::unprintableString )
|
if( matcherAsString == Detail::unprintableString )
|
||||||
os << m_matcherString.c_str();
|
os << m_matcherString;
|
||||||
else
|
else
|
||||||
os << matcherAsString;
|
os << matcherAsString;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ namespace Catch {
|
|||||||
BinaryExpr( bool comparisionResult, LhsT lhs, StringRef op, RhsT rhs )
|
BinaryExpr( bool comparisionResult, LhsT lhs, StringRef op, RhsT rhs )
|
||||||
: m_result( comparisionResult ),
|
: m_result( comparisionResult ),
|
||||||
m_lhs( lhs ),
|
m_lhs( lhs ),
|
||||||
m_op( op.c_str() ),
|
m_op( op ),
|
||||||
m_rhs( rhs )
|
m_rhs( rhs )
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
@ -42,7 +42,7 @@ namespace Catch {
|
|||||||
if( assertionResult.hasMessage() ) {
|
if( assertionResult.hasMessage() ) {
|
||||||
// Copy message into messages list.
|
// Copy message into messages list.
|
||||||
// !TBD This should have been done earlier, somewhere
|
// !TBD This should have been done earlier, somewhere
|
||||||
MessageBuilder builder( assertionResult.getTestMacroName().c_str(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
|
MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
|
||||||
builder << assertionResult.getMessage();
|
builder << assertionResult.getMessage();
|
||||||
builder.m_info.message = builder.m_stream.str();
|
builder.m_info.message = builder.m_stream.str();
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ namespace Catch {
|
|||||||
.registerTest(
|
.registerTest(
|
||||||
makeTestCase(
|
makeTestCase(
|
||||||
invoker,
|
invoker,
|
||||||
extractClassName( classOrMethod.c_str() ),
|
extractClassName( classOrMethod ),
|
||||||
nameAndTags.name.c_str(),
|
nameAndTags.name,
|
||||||
nameAndTags.tags.c_str(),
|
nameAndTags.tags,
|
||||||
lineInfo));
|
lineInfo));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// Do not throw when constructing global objects, instead register the exception to be processed later
|
// Do not throw when constructing global objects, instead register the exception to be processed later
|
||||||
|
@ -85,7 +85,7 @@ namespace {
|
|||||||
friend TablePrinter& operator << ( TablePrinter& tp, ColumnBreak ) {
|
friend TablePrinter& operator << ( TablePrinter& tp, ColumnBreak ) {
|
||||||
auto colStr = tp.m_oss.str();
|
auto colStr = tp.m_oss.str();
|
||||||
// This takes account of utf8 encodings
|
// This takes account of utf8 encodings
|
||||||
auto strSize = Catch::StringRef( colStr.c_str(), colStr.size() ).numberOfCharacters();
|
auto strSize = Catch::StringRef( colStr ).numberOfCharacters();
|
||||||
tp.m_oss.str("");
|
tp.m_oss.str("");
|
||||||
tp.open();
|
tp.open();
|
||||||
if( tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size()-1) ) {
|
if( tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size()-1) ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user