Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Cleanups from static analysis

Commit
11a96e186af8b2779d93e550217e9c95d3f89371
Author
Martin Hořeňovský ·
Parents
10f62484bff7

Files · Download .tar.gz

Changes

 .clang-tidy                                             |  3 +++
 src/catch2/benchmark/detail/catch_analyse.cpp           | 10 +++++-----
 src/catch2/internal/catch_run_context.cpp               | 15 +++++++--------
 src/catch2/internal/catch_run_context.hpp               |  2 +-
 src/catch2/internal/catch_tag_alias_registry.cpp        |  7 ++++---
 src/catch2/internal/catch_test_failure_exception.cpp    |  4 ++--
 src/catch2/internal/catch_test_registry.hpp             |  2 +-
 src/catch2/reporters/catch_reporter_cumulative_base.cpp |  5 ++---
 tests/SelfTest/IntrospectiveTests/Integer.tests.cpp     |  4 ++--
 tests/SelfTest/UsageTests/ToStringPair.tests.cpp        |  4 ++--
 tests/SelfTest/UsageTests/ToStringTuple.tests.cpp       | 12 ++++++------
 11 files changed, 35 insertions(+), 33 deletions(-)

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<double> e) {
-                        return Estimate<FDuration> {
-                            FDuration(e.point),
-                                FDuration(e.lower_bound),
-                                FDuration(e.upper_bound),
-                                e.confidence_interval,
+                        return Estimate<FDuration>{
+                            FDuration( e.point ),
+                            FDuration( e.lower_bound ),
+                            FDuration( e.upper_bound ),
+                            e.confidence_interval,
                         };
                     };
                     std::vector<FDuration> 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<CumulativeReporterBase::SectionNode> 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<std::pair<std::string,int> > -> toString", "[toString][p
 
 // This is pretty contrived - I figure if this works, anything will...
 TEST_CASE( "pair<pair<int,const char *,pair<std::string,int> > -> toString", "[toString][pair]" ) {
-    typedef std::pair<int,const char *> left_t;
-    typedef std::pair<std::string,int> right_t;
+    using left_t = std::pair<int,const char *>;
+    using right_t = std::pair<std::string,int>;
 
     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<int>", "[toString][tuple]" )
 {
-    typedef std::tuple<int> type;
+    using type = std::tuple<int>;
     CHECK( "{ 0 }" == ::Catch::Detail::stringify(type{0}) );
 }
 
 
 TEST_CASE( "tuple<float,int>", "[toString][tuple]" )
 {
-    typedef std::tuple<float,int> type;
+    using type = std::tuple<float,int>;
     CHECK( "1.5f" == ::Catch::Detail::stringify(float(1.5)) );
     CHECK( "{ 1.5f, 0 }" == ::Catch::Detail::stringify(type{1.5f,0}) );
 }
 
 TEST_CASE( "tuple<string,string>", "[toString][tuple]" )
 {
-    typedef std::tuple<std::string,std::string> type;
+    using type = std::tuple<std::string,std::string>;
     CHECK( "{ \"hello\", \"world\" }" == ::Catch::Detail::stringify(type{"hello","world"}) );
 }
 
 TEST_CASE( "tuple<tuple<int>,tuple<>,float>", "[toString][tuple]" )
 {
-    typedef std::tuple<std::tuple<int>,std::tuple<>,float> type;
+    using type = std::tuple<std::tuple<int>,std::tuple<>,float>;
     type value { std::tuple<int>{42}, {}, 1.5f };
     CHECK( "{ { 42 }, { }, 1.5f }" == ::Catch::Detail::stringify(value) );
 }
 
 TEST_CASE( "tuple<nullptr,int,const char *>", "[approvals][toString][tuple]" ) {
-    typedef std::tuple<std::nullptr_t,int,const char *> type;
+    using type = std::tuple<std::nullptr_t,int,const char *>;
     type value { nullptr, 42, "Catch me" };
     CHECK( "{ nullptr, 42, \"Catch me\" }" == ::Catch::Detail::stringify(value) );
 }