mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 05:16:10 +01:00
Some refactorings:
- Overrides added - usages of push_back() replaced with emplace_back() - Loop variable made const-refernce - NULL replaced with nullptr - Names used in the declaration and definition unified - size() replaced with empty - Identical cases merged
This commit is contained in:
parent
ab520f4e97
commit
06c32862b3
@ -30,7 +30,7 @@ std::ostream& operator<<(std::ostream& out, Catch::Tag t) {
|
|||||||
template< typename T >
|
template< typename T >
|
||||||
std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
|
std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
|
||||||
os << "{ ";
|
os << "{ ";
|
||||||
for ( auto x : v )
|
for ( const auto& x : v )
|
||||||
os << x << ", ";
|
os << x << ", ";
|
||||||
return os << "}";
|
return os << "}";
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ void print( std::ostream& os, int const level, Catch::MessageInfo const& info )
|
|||||||
|
|
||||||
void print( std::ostream& os, int const level, std::string const& title, std::vector<Catch::MessageInfo> const& v ) {
|
void print( std::ostream& os, int const level, std::string const& title, std::vector<Catch::MessageInfo> const& v ) {
|
||||||
os << ws(level ) << title << ":\n";
|
os << ws(level ) << title << ":\n";
|
||||||
for ( auto x : v )
|
for ( const auto& x : v )
|
||||||
{
|
{
|
||||||
os << ws(level+1) << "{\n";
|
os << ws(level+1) << "{\n";
|
||||||
print( os, level+2, x );
|
print( os, level+2, x );
|
||||||
|
@ -18,7 +18,7 @@ class out_buff : public std::stringbuf {
|
|||||||
public:
|
public:
|
||||||
out_buff(std::FILE* stream):m_stream(stream) {}
|
out_buff(std::FILE* stream):m_stream(stream) {}
|
||||||
~out_buff();
|
~out_buff();
|
||||||
int sync() {
|
int sync() override {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
for (unsigned char c : str()) {
|
for (unsigned char c : str()) {
|
||||||
if (putc(c, m_stream) == EOF) {
|
if (putc(c, m_stream) == EOF) {
|
||||||
|
@ -50,14 +50,13 @@ namespace Catch {
|
|||||||
if( !startsWith( line, '"' ) )
|
if( !startsWith( line, '"' ) )
|
||||||
line = '"' + line + '"';
|
line = '"' + line + '"';
|
||||||
config.testsOrTags.push_back( line );
|
config.testsOrTags.push_back( line );
|
||||||
config.testsOrTags.push_back( "," );
|
config.testsOrTags.emplace_back( "," );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Remove comma in the end
|
//Remove comma in the end
|
||||||
if(!config.testsOrTags.empty())
|
if(!config.testsOrTags.empty())
|
||||||
config.testsOrTags.erase( config.testsOrTags.end()-1 );
|
config.testsOrTags.erase( config.testsOrTags.end()-1 );
|
||||||
|
|
||||||
return ParserResult::ok( ParseResultType::Matched );
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
};
|
};
|
||||||
auto const setTestOrder = [&]( std::string const& order ) {
|
auto const setTestOrder = [&]( std::string const& order ) {
|
||||||
@ -211,7 +210,7 @@ namespace Catch {
|
|||||||
| Opt( config.benchmarkNoAnalysis )
|
| Opt( config.benchmarkNoAnalysis )
|
||||||
["--benchmark-no-analysis"]
|
["--benchmark-no-analysis"]
|
||||||
( "perform only measurements; do not perform any analysis" )
|
( "perform only measurements; do not perform any analysis" )
|
||||||
| Arg( config.testsOrTags, "test name|pattern|tags" )
|
| Arg( config.testsOrTags, "test name|pattern|tags" )
|
||||||
( "which test or tests to use" );
|
( "which test or tests to use" );
|
||||||
|
|
||||||
return cli;
|
return cli;
|
||||||
|
@ -34,7 +34,7 @@ namespace Catch {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct NoColourImpl : IColourImpl {
|
struct NoColourImpl : IColourImpl {
|
||||||
void use( Colour::Code ) {}
|
void use( Colour::Code ) override {}
|
||||||
|
|
||||||
static IColourImpl* instance() {
|
static IColourImpl* instance() {
|
||||||
static NoColourImpl s_instance;
|
static NoColourImpl s_instance;
|
||||||
@ -208,13 +208,13 @@ namespace Catch {
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
Colour::Colour( Code _colourCode ) { use( _colourCode ); }
|
Colour::Colour( Code _colourCode ) { use( _colourCode ); }
|
||||||
Colour::Colour( Colour&& rhs ) noexcept {
|
Colour::Colour( Colour&& other ) noexcept {
|
||||||
m_moved = rhs.m_moved;
|
m_moved = other.m_moved;
|
||||||
rhs.m_moved = true;
|
other.m_moved = true;
|
||||||
}
|
}
|
||||||
Colour& Colour::operator=( Colour&& rhs ) noexcept {
|
Colour& Colour::operator=( Colour&& other ) noexcept {
|
||||||
m_moved = rhs.m_moved;
|
m_moved = other.m_moved;
|
||||||
rhs.m_moved = true;
|
other.m_moved = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ namespace Catch {
|
|||||||
// However, under some conditions it does happen (see #1626),
|
// However, under some conditions it does happen (see #1626),
|
||||||
// and this change is small enough that we can let practicality
|
// and this change is small enough that we can let practicality
|
||||||
// triumph over purity in this case.
|
// triumph over purity in this case.
|
||||||
if (impl != NULL) {
|
if (impl != nullptr) {
|
||||||
impl->use( _colourCode );
|
impl->use( _colourCode );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ namespace Catch {
|
|||||||
assert( valueNames.size() == values.size() );
|
assert( valueNames.size() == values.size() );
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
for( auto value : values )
|
for( auto value : values )
|
||||||
enumInfo->m_values.push_back({ value, valueNames[i++] });
|
enumInfo->m_values.emplace_back(value, valueNames[i++]);
|
||||||
|
|
||||||
return enumInfo;
|
return enumInfo;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ namespace Catch {
|
|||||||
pos = skipq(pos, c);
|
pos = skipq(pos, c);
|
||||||
break;
|
break;
|
||||||
case ',':
|
case ',':
|
||||||
if (start != pos && openings.size() == 0) {
|
if (start != pos && openings.empty()) {
|
||||||
m_messages.emplace_back(macroName, lineInfo, resultType);
|
m_messages.emplace_back(macroName, lineInfo, resultType);
|
||||||
m_messages.back().message = static_cast<std::string>(trimmed(start, pos));
|
m_messages.back().message = static_cast<std::string>(trimmed(start, pos));
|
||||||
m_messages.back().message += " := ";
|
m_messages.back().message += " := ";
|
||||||
@ -119,7 +119,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(openings.size() == 0 && "Mismatched openings");
|
assert(openings.empty() && "Mismatched openings");
|
||||||
m_messages.emplace_back(macroName, lineInfo, resultType);
|
m_messages.emplace_back(macroName, lineInfo, resultType);
|
||||||
m_messages.back().message = static_cast<std::string>(trimmed(start, names.size() - 1));
|
m_messages.back().message = static_cast<std::string>(trimmed(start, names.size() - 1));
|
||||||
m_messages.back().message += " := ";
|
m_messages.back().message += " := ";
|
||||||
|
@ -204,11 +204,11 @@ namespace Catch {
|
|||||||
char **utf8Argv = new char *[ argc ];
|
char **utf8Argv = new char *[ argc ];
|
||||||
|
|
||||||
for ( int i = 0; i < argc; ++i ) {
|
for ( int i = 0; i < argc; ++i ) {
|
||||||
int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL );
|
int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, nullptr, 0, nullptr, nullptr );
|
||||||
|
|
||||||
utf8Argv[ i ] = new char[ bufSize ];
|
utf8Argv[ i ] = new char[ bufSize ];
|
||||||
|
|
||||||
WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL );
|
WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, nullptr, nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
int returnCode = applyCommandLine( argc, utf8Argv );
|
int returnCode = applyCommandLine( argc, utf8Argv );
|
||||||
|
@ -224,8 +224,8 @@ namespace TestCaseTracking {
|
|||||||
void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) {
|
void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) {
|
||||||
if( !filters.empty() ) {
|
if( !filters.empty() ) {
|
||||||
m_filters.reserve( m_filters.size() + filters.size() + 2 );
|
m_filters.reserve( m_filters.size() + filters.size() + 2 );
|
||||||
m_filters.push_back(""); // Root - should never be consulted
|
m_filters.emplace_back(""); // Root - should never be consulted
|
||||||
m_filters.push_back(""); // Test Case - not a section filter
|
m_filters.emplace_back(""); // Test Case - not a section filter
|
||||||
m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
|
m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,11 +228,7 @@ namespace Catch {
|
|||||||
elementName = "error";
|
elementName = "error";
|
||||||
break;
|
break;
|
||||||
case ResultWas::ExplicitFailure:
|
case ResultWas::ExplicitFailure:
|
||||||
elementName = "failure";
|
|
||||||
break;
|
|
||||||
case ResultWas::ExpressionFailed:
|
case ResultWas::ExpressionFailed:
|
||||||
elementName = "failure";
|
|
||||||
break;
|
|
||||||
case ResultWas::DidntThrowException:
|
case ResultWas::DidntThrowException:
|
||||||
elementName = "failure";
|
elementName = "failure";
|
||||||
break;
|
break;
|
||||||
|
@ -17,9 +17,9 @@ TEST_CASE( "vector<string> -> toString", "[toString][vector]" )
|
|||||||
{
|
{
|
||||||
std::vector<std::string> vv;
|
std::vector<std::string> vv;
|
||||||
REQUIRE( ::Catch::Detail::stringify(vv) == "{ }" );
|
REQUIRE( ::Catch::Detail::stringify(vv) == "{ }" );
|
||||||
vv.push_back( "hello" );
|
vv.emplace_back( "hello" );
|
||||||
REQUIRE( ::Catch::Detail::stringify(vv) == "{ \"hello\" }" );
|
REQUIRE( ::Catch::Detail::stringify(vv) == "{ \"hello\" }" );
|
||||||
vv.push_back( "world" );
|
vv.emplace_back( "world" );
|
||||||
REQUIRE( ::Catch::Detail::stringify(vv) == "{ \"hello\", \"world\" }" );
|
REQUIRE( ::Catch::Detail::stringify(vv) == "{ \"hello\", \"world\" }" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,4 +83,4 @@ TEST_CASE( "array<int, N> -> toString", "[toString][containers][array]" ) {
|
|||||||
REQUIRE( Catch::Detail::stringify( oneValue ) == "{ 42 }" );
|
REQUIRE( Catch::Detail::stringify( oneValue ) == "{ 42 }" );
|
||||||
std::array<int, 2> twoValues = {{ 42, 250 }};
|
std::array<int, 2> twoValues = {{ 42, 250 }};
|
||||||
REQUIRE( Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" );
|
REQUIRE( Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user