summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroffa <bm-dev@yandex.com>2020-01-21 21:04:42 +0100
committerMartin Hořeňovský <martin.horenovsky@gmail.com>2020-01-25 09:01:04 +0100
commit2d172dc688ffab0867a94928159e93384475a870 (patch)
tree0198f95dadc3560939d8a02736e2e93cee2f6d91
parent587a20b312a44fef5373b53b897a9bd5ebfa5c0b (diff)
downloadcatch2-2d172dc688ffab0867a94928159e93384475a870.tar.gz
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
-rw-r--r--examples/210-Evt-EventListeners.cpp6
-rw-r--r--examples/231-Cfg-OutputStreams.cpp2
-rw-r--r--include/internal/catch_commandline.cpp7
-rw-r--r--include/internal/catch_console_colour.cpp16
-rw-r--r--include/internal/catch_enum_values_registry.cpp2
-rw-r--r--include/internal/catch_message.cpp4
-rw-r--r--include/internal/catch_session.cpp14
-rw-r--r--include/internal/catch_test_case_info.cpp2
-rw-r--r--include/internal/catch_test_case_tracker.cpp4
-rw-r--r--include/reporters/catch_reporter_junit.cpp4
-rw-r--r--projects/SelfTest/UsageTests/ToStringVector.tests.cpp6
11 files changed, 31 insertions, 36 deletions
diff --git a/examples/210-Evt-EventListeners.cpp b/examples/210-Evt-EventListeners.cpp
index 2d5fdb28..044a29e3 100644
--- a/examples/210-Evt-EventListeners.cpp
+++ b/examples/210-Evt-EventListeners.cpp
@@ -24,7 +24,7 @@ std::string ws(int const level) {
template< typename T >
std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
os << "{ ";
- for ( auto x : v )
+ for ( const auto& x : v )
os << x << ", ";
return os << "}";
}
@@ -57,7 +57,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 ) {
os << ws(level ) << title << ":\n";
- for ( auto x : v )
+ for ( const auto& x : v )
{
os << ws(level+1) << "{\n";
print( os, level+2, x );
@@ -300,7 +300,7 @@ char const * dashed_line =
struct MyListener : Catch::TestEventListenerBase {
using TestEventListenerBase::TestEventListenerBase; // inherit constructor
-
+
// Get rid of Wweak-tables
~MyListener();
diff --git a/examples/231-Cfg-OutputStreams.cpp b/examples/231-Cfg-OutputStreams.cpp
index 2f42c297..8c65cc44 100644
--- a/examples/231-Cfg-OutputStreams.cpp
+++ b/examples/231-Cfg-OutputStreams.cpp
@@ -16,7 +16,7 @@ class out_buff : public std::stringbuf {
public:
out_buff(std::FILE* stream):m_stream(stream) {}
~out_buff();
- int sync() {
+ int sync() override {
int ret = 0;
for (unsigned char c : str()) {
if (putc(c, m_stream) == EOF) {
diff --git a/include/internal/catch_commandline.cpp b/include/internal/catch_commandline.cpp
index 365a3c9d..ecb7dc2f 100644
--- a/include/internal/catch_commandline.cpp
+++ b/include/internal/catch_commandline.cpp
@@ -50,14 +50,13 @@ namespace Catch {
if( !startsWith( line, '"' ) )
line = '"' + line + '"';
config.testsOrTags.push_back( line );
- config.testsOrTags.push_back( "," );
-
+ config.testsOrTags.emplace_back( "," );
}
}
//Remove comma in the end
if(!config.testsOrTags.empty())
config.testsOrTags.erase( config.testsOrTags.end()-1 );
-
+
return ParserResult::ok( ParseResultType::Matched );
};
auto const setTestOrder = [&]( std::string const& order ) {
@@ -214,7 +213,7 @@ namespace Catch {
| Opt( config.benchmarkNoAnalysis )
["--benchmark-no-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" );
return cli;
diff --git a/include/internal/catch_console_colour.cpp b/include/internal/catch_console_colour.cpp
index f3c2204f..de0fff43 100644
--- a/include/internal/catch_console_colour.cpp
+++ b/include/internal/catch_console_colour.cpp
@@ -34,7 +34,7 @@ namespace Catch {
};
struct NoColourImpl : IColourImpl {
- void use( Colour::Code ) {}
+ void use( Colour::Code ) override {}
static IColourImpl* instance() {
static NoColourImpl s_instance;
@@ -208,13 +208,13 @@ namespace Catch {
namespace Catch {
Colour::Colour( Code _colourCode ) { use( _colourCode ); }
- Colour::Colour( Colour&& rhs ) noexcept {
- m_moved = rhs.m_moved;
- rhs.m_moved = true;
+ Colour::Colour( Colour&& other ) noexcept {
+ m_moved = other.m_moved;
+ other.m_moved = true;
}
- Colour& Colour::operator=( Colour&& rhs ) noexcept {
- m_moved = rhs.m_moved;
- rhs.m_moved = true;
+ Colour& Colour::operator=( Colour&& other ) noexcept {
+ m_moved = other.m_moved;
+ other.m_moved = true;
return *this;
}
@@ -226,7 +226,7 @@ namespace Catch {
// However, under some conditions it does happen (see #1626),
// and this change is small enough that we can let practicality
// triumph over purity in this case.
- if (impl != NULL) {
+ if (impl != nullptr) {
impl->use( _colourCode );
}
}
diff --git a/include/internal/catch_enum_values_registry.cpp b/include/internal/catch_enum_values_registry.cpp
index fb060f5b..063f9d62 100644
--- a/include/internal/catch_enum_values_registry.cpp
+++ b/include/internal/catch_enum_values_registry.cpp
@@ -60,7 +60,7 @@ namespace Catch {
assert( valueNames.size() == values.size() );
std::size_t i = 0;
for( auto value : values )
- enumInfo->m_values.push_back({ value, valueNames[i++] });
+ enumInfo->m_values.emplace_back(value, valueNames[i++]);
return enumInfo;
}
diff --git a/include/internal/catch_message.cpp b/include/internal/catch_message.cpp
index 8f391bcb..64c817b7 100644
--- a/include/internal/catch_message.cpp
+++ b/include/internal/catch_message.cpp
@@ -111,7 +111,7 @@ namespace Catch {
pos = skipq(pos, c);
break;
case ',':
- if (start != pos && openings.size() == 0) {
+ if (start != pos && openings.empty()) {
m_messages.emplace_back(macroName, lineInfo, resultType);
m_messages.back().message = static_cast<std::string>(trimmed(start, pos));
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.back().message = static_cast<std::string>(trimmed(start, names.size() - 1));
m_messages.back().message += " := ";
diff --git a/include/internal/catch_session.cpp b/include/internal/catch_session.cpp
index b1d7a404..24ebe4de 100644
--- a/include/internal/catch_session.cpp
+++ b/include/internal/catch_session.cpp
@@ -69,7 +69,7 @@ namespace Catch {
auto const& allTestCases = getAllTestCasesSorted(*m_config);
m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config);
auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
-
+
if (m_matches.empty() && invalidArgs.empty()) {
for (auto const& test : allTestCases)
if (!test.isHidden())
@@ -97,12 +97,12 @@ namespace Catch {
totals.error = -1;
}
}
-
+
if (!invalidArgs.empty()) {
- for (auto const& invalidArg: invalidArgs)
+ for (auto const& invalidArg: invalidArgs)
m_context.reporter().reportInvalidArguments(invalidArg);
- }
-
+ }
+
m_context.testGroupEnded(m_config->name(), totals, 1, 1);
return totals;
}
@@ -220,11 +220,11 @@ namespace Catch {
char **utf8Argv = new char *[ argc ];
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 ];
- 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 );
diff --git a/include/internal/catch_test_case_info.cpp b/include/internal/catch_test_case_info.cpp
index 685ee30f..716c0b4b 100644
--- a/include/internal/catch_test_case_info.cpp
+++ b/include/internal/catch_test_case_info.cpp
@@ -89,7 +89,7 @@ namespace Catch {
}
}
if( isHidden ) {
- tags.push_back( "." );
+ tags.emplace_back( "." );
}
TestCaseInfo info( static_cast<std::string>(nameAndTags.name), _className, desc, tags, _lineInfo );
diff --git a/include/internal/catch_test_case_tracker.cpp b/include/internal/catch_test_case_tracker.cpp
index 77bd65cb..1fc820b1 100644
--- a/include/internal/catch_test_case_tracker.cpp
+++ b/include/internal/catch_test_case_tracker.cpp
@@ -225,8 +225,8 @@ namespace TestCaseTracking {
void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) {
if( !filters.empty() ) {
m_filters.reserve( m_filters.size() + filters.size() + 2 );
- m_filters.push_back(""); // Root - should never be consulted
- m_filters.push_back(""); // Test Case - not a section filter
+ m_filters.emplace_back(""); // Root - should never be consulted
+ m_filters.emplace_back(""); // Test Case - not a section filter
m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
}
}
diff --git a/include/reporters/catch_reporter_junit.cpp b/include/reporters/catch_reporter_junit.cpp
index 820b574f..7416a523 100644
--- a/include/reporters/catch_reporter_junit.cpp
+++ b/include/reporters/catch_reporter_junit.cpp
@@ -223,11 +223,7 @@ namespace Catch {
elementName = "error";
break;
case ResultWas::ExplicitFailure:
- elementName = "failure";
- break;
case ResultWas::ExpressionFailed:
- elementName = "failure";
- break;
case ResultWas::DidntThrowException:
elementName = "failure";
break;
diff --git a/projects/SelfTest/UsageTests/ToStringVector.tests.cpp b/projects/SelfTest/UsageTests/ToStringVector.tests.cpp
index 63b49e50..ea4d5c86 100644
--- a/projects/SelfTest/UsageTests/ToStringVector.tests.cpp
+++ b/projects/SelfTest/UsageTests/ToStringVector.tests.cpp
@@ -17,9 +17,9 @@ TEST_CASE( "vector<string> -> toString", "[toString][vector]" )
{
std::vector<std::string> vv;
REQUIRE( ::Catch::Detail::stringify(vv) == "{ }" );
- vv.push_back( "hello" );
+ vv.emplace_back( "hello" );
REQUIRE( ::Catch::Detail::stringify(vv) == "{ \"hello\" }" );
- vv.push_back( "world" );
+ vv.emplace_back( "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 }" );
std::array<int, 2> twoValues = {{ 42, 250 }};
REQUIRE( Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" );
-} \ No newline at end of file
+}