diff --git a/.clang-tidy b/.clang-tidy index fd181737..8d3a17f2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -32,6 +32,7 @@ Checks: >- -modernize-deprecated-headers, ,# There's a lot of these and most of them are probably not useful, -modernize-pass-by-value, + -modernize-use-string-view, # We support C++14, performance-*, performance-enum-size, @@ -58,6 +59,8 @@ Checks: >- -readability-uppercase-literal-suffix, -readability-use-anyofallof, -readability-avoid-return-with-void-value, + ,# We prefer if defined(FOO) form because it is easier to extend later, + -readability-use-concise-preprocessor-directives, ,# time hogs, -bugprone-throw-keyword-missing, diff --git a/src/catch2/benchmark/detail/catch_analyse.cpp b/src/catch2/benchmark/detail/catch_analyse.cpp index 14d7f450..8934f84f 100644 --- a/src/catch2/benchmark/detail/catch_analyse.cpp +++ b/src/catch2/benchmark/detail/catch_analyse.cpp @@ -36,11 +36,11 @@ namespace Catch { samples.data(), samples.data() + samples.size() ); auto wrap_estimate = [](Estimate e) { - return Estimate { - FDuration(e.point), - FDuration(e.lower_bound), - FDuration(e.upper_bound), - e.confidence_interval, + return Estimate{ + FDuration( e.point ), + FDuration( e.lower_bound ), + FDuration( e.upper_bound ), + e.confidence_interval, }; }; std::vector samples2; diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index e7e22c58..a435170f 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -461,14 +461,13 @@ namespace Catch { Detail::g_lastAssertionPassed = true; } else if (!result.succeeded()) { Detail::g_lastAssertionPassed = false; - if (result.isOk()) { - } - else if( m_activeTestCase->getTestCaseInfo().okToFail() ) // Read from a shared state established before the threads could start, this is fine + if (result.isOk()) {} + else if( m_activeTestCase->getTestCaseInfo().okToFail() ) { // Read from a shared state established before the threads could start, this is fine m_atomicAssertionCount.failedButOk++; - else + } else { m_atomicAssertionCount.failed++; - } - else { + } + } else { Detail::g_lastAssertionPassed = true; } @@ -650,7 +649,7 @@ namespace Catch { // and since IResultCapture::getLastResult is deprecated, // we will leave it as is, until it is finally removed. Detail::LockGuard _( m_assertionMutex ); - return &(*m_lastResult); + return &*m_lastResult; } void RunContext::exceptionEarlyReported() { @@ -902,7 +901,7 @@ namespace Catch { } void RunContext::populateReaction( AssertionReaction& reaction, - bool has_normal_disposition ) { + bool has_normal_disposition ) const { reaction.shouldDebugBreak = m_shouldDebugBreak; reaction.shouldThrow = aborting() || has_normal_disposition; } diff --git a/src/catch2/internal/catch_run_context.hpp b/src/catch2/internal/catch_run_context.hpp index 4a77cac5..f333735d 100644 --- a/src/catch2/internal/catch_run_context.hpp +++ b/src/catch2/internal/catch_run_context.hpp @@ -123,7 +123,7 @@ namespace Catch { ITransientExpression const *expr, bool negated ); - void populateReaction( AssertionReaction& reaction, bool has_normal_disposition ); + void populateReaction( AssertionReaction& reaction, bool has_normal_disposition ) const; // Creates dummy info for unexpected exceptions/fatal errors, // where we do not have the access to one, but we still need diff --git a/src/catch2/internal/catch_tag_alias_registry.cpp b/src/catch2/internal/catch_tag_alias_registry.cpp index 510df167..e87e4050 100644 --- a/src/catch2/internal/catch_tag_alias_registry.cpp +++ b/src/catch2/internal/catch_tag_alias_registry.cpp @@ -16,10 +16,11 @@ namespace Catch { TagAlias const* TagAliasRegistry::find( std::string const& alias ) const { auto it = m_registry.find( alias ); - if( it != m_registry.end() ) - return &(it->second); - else + if ( it != m_registry.end() ) { + return &it->second; + } else { return nullptr; + } } std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { diff --git a/src/catch2/internal/catch_test_failure_exception.cpp b/src/catch2/internal/catch_test_failure_exception.cpp index 8ea31313..8c34278f 100644 --- a/src/catch2/internal/catch_test_failure_exception.cpp +++ b/src/catch2/internal/catch_test_failure_exception.cpp @@ -14,7 +14,7 @@ namespace Catch { void throw_test_failure_exception() { #if !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS ) - throw TestFailureException{}; + throw TestFailureException{}; //NOLINT(bugprone-std-exception-baseclass) #else CATCH_ERROR( "Test failure requires aborting test!" ); #endif @@ -22,7 +22,7 @@ namespace Catch { void throw_test_skip_exception() { #if !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS ) - throw Catch::TestSkipException(); + throw Catch::TestSkipException(); //NOLINT(bugprone-std-exception-baseclass) #else CATCH_ERROR( "Explicitly skipping tests during runtime requires exceptions" ); #endif diff --git a/src/catch2/internal/catch_test_registry.hpp b/src/catch2/internal/catch_test_registry.hpp index 593593ba..213b2bdc 100644 --- a/src/catch2/internal/catch_test_registry.hpp +++ b/src/catch2/internal/catch_test_registry.hpp @@ -124,7 +124,7 @@ struct AutoReg : Detail::NonCopyable { namespace Catch { namespace Detail { struct DummyUse { - DummyUse( void ( * )( int ), Catch::NameAndTags const& ); + DummyUse( void ( * )( int ), Catch::NameAndTags const& ) noexcept; }; } // namespace Detail } // namespace Catch diff --git a/src/catch2/reporters/catch_reporter_cumulative_base.cpp b/src/catch2/reporters/catch_reporter_cumulative_base.cpp index 09169632..dc5ae4b0 100644 --- a/src/catch2/reporters/catch_reporter_cumulative_base.cpp +++ b/src/catch2/reporters/catch_reporter_cumulative_base.cpp @@ -20,9 +20,8 @@ namespace Catch { bool operator()( Detail::unique_ptr const& node ) const { - return ( - ( node->stats.sectionInfo.name == m_other.name ) && - ( node->stats.sectionInfo.lineInfo == m_other.lineInfo ) ); + return node->stats.sectionInfo.name == m_other.name + && node->stats.sectionInfo.lineInfo == m_other.lineInfo; } void operator=( BySectionInfo const& ) = delete; diff --git a/tests/SelfTest/IntrospectiveTests/Integer.tests.cpp b/tests/SelfTest/IntrospectiveTests/Integer.tests.cpp index 4ce2ae6a..466412e3 100644 --- a/tests/SelfTest/IntrospectiveTests/Integer.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Integer.tests.cpp @@ -39,8 +39,8 @@ namespace { // ------------------------- // | a | b | c | d | -#define CarryBits( x ) ( x >> 32 ) -#define Digits( x ) ( x & 0xFF'FF'FF'FF ) +#define CarryBits( x ) ( (x) >> 32 ) +#define Digits( x ) ( (x) & 0xFF'FF'FF'FF ) auto r2l2 = Digits( rhs ) * Digits( lhs ); auto r2l1 = Digits( rhs ) * CarryBits( lhs ); diff --git a/tests/SelfTest/UsageTests/ToStringPair.tests.cpp b/tests/SelfTest/UsageTests/ToStringPair.tests.cpp index f5cb239c..b632b071 100644 --- a/tests/SelfTest/UsageTests/ToStringPair.tests.cpp +++ b/tests/SelfTest/UsageTests/ToStringPair.tests.cpp @@ -27,8 +27,8 @@ TEST_CASE( "std::vector > -> toString", "[toString][p // This is pretty contrived - I figure if this works, anything will... TEST_CASE( "pair > -> toString", "[toString][pair]" ) { - typedef std::pair left_t; - typedef std::pair right_t; + using left_t = std::pair; + using right_t = std::pair; left_t left( 42, "Arthur" ); right_t right( "Ford", 24 ); diff --git a/tests/SelfTest/UsageTests/ToStringTuple.tests.cpp b/tests/SelfTest/UsageTests/ToStringTuple.tests.cpp index 9d1d2c46..34000cf0 100644 --- a/tests/SelfTest/UsageTests/ToStringTuple.tests.cpp +++ b/tests/SelfTest/UsageTests/ToStringTuple.tests.cpp @@ -13,7 +13,7 @@ TEST_CASE( "tuple<>", "[toString][tuple]" ) { - typedef std::tuple<> type; + using type = std::tuple<>; CHECK( "{ }" == ::Catch::Detail::stringify(type{}) ); type value {}; CHECK( "{ }" == ::Catch::Detail::stringify(value) ); @@ -21,33 +21,33 @@ TEST_CASE( "tuple<>", "[toString][tuple]" ) TEST_CASE( "tuple", "[toString][tuple]" ) { - typedef std::tuple type; + using type = std::tuple; CHECK( "{ 0 }" == ::Catch::Detail::stringify(type{0}) ); } TEST_CASE( "tuple", "[toString][tuple]" ) { - typedef std::tuple type; + using type = std::tuple; CHECK( "1.5f" == ::Catch::Detail::stringify(float(1.5)) ); CHECK( "{ 1.5f, 0 }" == ::Catch::Detail::stringify(type{1.5f,0}) ); } TEST_CASE( "tuple", "[toString][tuple]" ) { - typedef std::tuple type; + using type = std::tuple; CHECK( "{ \"hello\", \"world\" }" == ::Catch::Detail::stringify(type{"hello","world"}) ); } TEST_CASE( "tuple,tuple<>,float>", "[toString][tuple]" ) { - typedef std::tuple,std::tuple<>,float> type; + using type = std::tuple,std::tuple<>,float>; type value { std::tuple{42}, {}, 1.5f }; CHECK( "{ { 42 }, { }, 1.5f }" == ::Catch::Detail::stringify(value) ); } TEST_CASE( "tuple", "[approvals][toString][tuple]" ) { - typedef std::tuple type; + using type = std::tuple; type value { nullptr, 42, "Catch me" }; CHECK( "{ nullptr, 42, \"Catch me\" }" == ::Catch::Detail::stringify(value) ); }