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

Add -Wmissing-declarations to the SelfTest project

This required some clean-up in our test files
Commit
e1d81174dba1a7d81eb348490005dfc02a648c7e
Author
Martin Hořeňovský ·
Parents
4846ad59e10e

Files · Download .tar.gz

Changes

 projects/CMakeLists.txt                            |  2 +-
 .../IntrospectiveTests/PartTracker.tests.cpp       | 11 ++-----
 .../SelfTest/IntrospectiveTests/String.tests.cpp   |  9 +++---
 .../SelfTest/UsageTests/Decomposition.tests.cpp    |  4 +++
 .../SelfTest/UsageTests/EnumToString.tests.cpp     | 37 ++++++++++++----------
 .../SelfTest/UsageTests/ToStringGeneral.tests.cpp  |  4 +++
 .../SelfTest/UsageTests/ToStringWhich.tests.cpp    | 20 ++++++++++++
 7 files changed, 56 insertions(+), 31 deletions(-)

diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt
index 49888b15..2084c745 100644
--- a/projects/CMakeLists.txt
+++ b/projects/CMakeLists.txt
@@ -268,7 +268,7 @@ endif()
 
 # Add per compiler options
 if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
-    target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code -Wpedantic)
+    target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code -Wpedantic -Wmissing-declarations )
     if (CATCH_ENABLE_WERROR)
         target_compile_options( SelfTest PRIVATE -Werror)
     endif()
diff --git a/projects/SelfTest/IntrospectiveTests/PartTracker.tests.cpp b/projects/SelfTest/IntrospectiveTests/PartTracker.tests.cpp
index 042c03a7..7e7f14b4 100644
--- a/projects/SelfTest/IntrospectiveTests/PartTracker.tests.cpp
+++ b/projects/SelfTest/IntrospectiveTests/PartTracker.tests.cpp
@@ -21,24 +21,17 @@ namespace Catch
 
 } // namespace Catch
 
-inline Catch::TrackerContext& C_A_T_C_H_Context() {
-    return Catch::TrackerContext::instance();
-}
-
 // -------------------
 
 #include "catch.hpp"
 
 using namespace Catch;
 
-//inline void testCase( Catch::LocalContext const& C_A_T_C_H_Context ) {
-//
-//    REQUIRE( C_A_T_C_H_Context().i() == 42 );
-//}
-
+namespace {
 Catch::TestCaseTracking::NameAndLocation makeNAL( std::string const& name ) {
     return Catch::TestCaseTracking::NameAndLocation( name, Catch::SourceLineInfo("",0) );
 }
+}
 
 TEST_CASE( "Tracker" ) {
 
diff --git a/projects/SelfTest/IntrospectiveTests/String.tests.cpp b/projects/SelfTest/IntrospectiveTests/String.tests.cpp
index ee6e4c58..ae21bb3c 100644
--- a/projects/SelfTest/IntrospectiveTests/String.tests.cpp
+++ b/projects/SelfTest/IntrospectiveTests/String.tests.cpp
@@ -16,23 +16,22 @@ namespace Catch {
         }
     };
 
+
+    namespace {
     auto isOwned( StringRef const& stringRef ) -> bool {
         return StringRefTestAccess::isOwned( stringRef );
     }
     auto isSubstring( StringRef const& stringRef ) -> bool {
         return StringRefTestAccess::isSubstring( stringRef );
     }
-} // namespace Catch2
+    } // end anonymous namespace
 
-namespace Catch {
-    inline auto toString( Catch::StringRef const& stringRef ) -> std::string {
-        return std::string( stringRef.currentData(), stringRef.size() );
-    }
 } // namespace Catch
 
 TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
 
     using Catch::StringRef;
+    using Catch::isOwned; using Catch::isSubstring;
 
     SECTION( "Empty string" ) {
         StringRef empty;
diff --git a/projects/SelfTest/UsageTests/Decomposition.tests.cpp b/projects/SelfTest/UsageTests/Decomposition.tests.cpp
index 1b44b602..5bb19cd6 100644
--- a/projects/SelfTest/UsageTests/Decomposition.tests.cpp
+++ b/projects/SelfTest/UsageTests/Decomposition.tests.cpp
@@ -9,6 +9,8 @@
 #include <iostream>
 #include <cstdio>
 
+namespace {
+
 struct truthy {
     truthy(bool b):m_value(b){}
     operator bool() const {
@@ -22,6 +24,8 @@ std::ostream& operator<<(std::ostream& o, truthy) {
     return o;
 }
 
+} // end anonymous namespace
+
 #include "catch.hpp"
 
 TEST_CASE( "Reconstruction should be based on stringification: #914" , "[Decomposition][failing][.]") {
diff --git a/projects/SelfTest/UsageTests/EnumToString.tests.cpp b/projects/SelfTest/UsageTests/EnumToString.tests.cpp
index 7d18a292..0b188a82 100644
--- a/projects/SelfTest/UsageTests/EnumToString.tests.cpp
+++ b/projects/SelfTest/UsageTests/EnumToString.tests.cpp
@@ -1,22 +1,24 @@
 #include "catch.hpp"
 
 
+namespace {
 // Enum without user-provided stream operator
 enum Enum1 { Enum1Value0, Enum1Value1 };
 
-TEST_CASE( "toString(enum)", "[toString][enum]" ) {
-    Enum1 e0 = Enum1Value0;
-    CHECK( ::Catch::Detail::stringify(e0) == "0" );
-    Enum1 e1 = Enum1Value1;
-    CHECK( ::Catch::Detail::stringify(e1) == "1" );
-}
-
 // Enum with user-provided stream operator
 enum Enum2 { Enum2Value0, Enum2Value1 };
 
 std::ostream& operator<<( std::ostream& os, Enum2 v ) {
     return os << "E2{" << static_cast<int>(v) << "}";
 }
+} // end anonymous namespace
+
+TEST_CASE( "toString(enum)", "[toString][enum]" ) {
+    Enum1 e0 = Enum1Value0;
+    CHECK( ::Catch::Detail::stringify(e0) == "0" );
+    Enum1 e1 = Enum1Value1;
+    CHECK( ::Catch::Detail::stringify(e1) == "1" );
+}
 
 TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" ) {
     Enum2 e0 = Enum2Value0;
@@ -26,17 +28,11 @@ TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" ) {
 }
 
 // Enum class without user-provided stream operator
+namespace {
 enum class EnumClass1 { EnumClass1Value0, EnumClass1Value1 };
 
-TEST_CASE( "toString(enum class)", "[toString][enum][enumClass]" ) {
-    EnumClass1 e0 = EnumClass1::EnumClass1Value0;
-    CHECK( ::Catch::Detail::stringify(e0) == "0" );
-    EnumClass1 e1 = EnumClass1::EnumClass1Value1;
-    CHECK( ::Catch::Detail::stringify(e1) == "1" );
-}
-
 // Enum class with user-provided stream operator
-enum class EnumClass2 : short { EnumClass2Value0, EnumClass2Value1 };
+enum class EnumClass2 { EnumClass2Value0, EnumClass2Value1 };
 
 std::ostream& operator<<( std::ostream& os, EnumClass2 e2 ) {
     switch( static_cast<int>( e2 ) ) {
@@ -49,6 +45,16 @@ std::ostream& operator<<( std::ostream& os, EnumClass2 e2 ) {
     }
 }
 
+} // end anonymous namespace
+
+TEST_CASE( "toString(enum class)", "[toString][enum][enumClass]" ) {
+    EnumClass1 e0 = EnumClass1::EnumClass1Value0;
+    CHECK( ::Catch::Detail::stringify(e0) == "0" );
+    EnumClass1 e1 = EnumClass1::EnumClass1Value1;
+    CHECK( ::Catch::Detail::stringify(e1) == "1" );
+}
+
+
 TEST_CASE( "toString(enum class w/operator<<)", "[toString][enum][enumClass]" ) {
     EnumClass2 e0 = EnumClass2::EnumClass2Value0;
     CHECK( ::Catch::Detail::stringify(e0) == "E2/V0" );
@@ -58,4 +64,3 @@ TEST_CASE( "toString(enum class w/operator<<)", "[toString][enum][enumClass]" )
     EnumClass2 e3 = static_cast<EnumClass2>(10);
     CHECK( ::Catch::Detail::stringify(e3) == "Unknown enum value 10" );
 }
-
diff --git a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
index a1f8c233..3f6fa05f 100644
--- a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
+++ b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp
@@ -116,6 +116,8 @@ TEST_CASE("Static arrays are convertible to string", "[toString]") {
     }
 }
 
+namespace {
+
 struct WhatException : std::exception {
     char const* what() const noexcept override {
         return "This exception has overriden what() method";
@@ -136,6 +138,8 @@ struct StringMakerException : std::exception {
     ~StringMakerException() override;
 };
 
+} // end anonymous namespace
+
 namespace Catch {
 template <>
 struct StringMaker<StringMakerException> {
diff --git a/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp b/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp
index 26afa3b1..cd4a1518 100644
--- a/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp
+++ b/projects/SelfTest/UsageTests/ToStringWhich.tests.cpp
@@ -16,6 +16,16 @@ std::string fallbackStringifier(T const&) {
 #include "catch.hpp"
 
 
+
+#if defined(__GNUC__)
+// This has to be left enabled until end of the TU, because the GCC
+// frontend reports operator<<(std::ostream& os, const has_maker_and_operator&)
+// as unused anyway
+#    pragma GCC diagnostic ignored "-Wunused-function"
+#endif
+
+namespace {
+
 struct has_operator { };
 struct has_maker {};
 struct has_maker_and_operator {};
@@ -38,6 +48,8 @@ StreamT& operator<<(StreamT& os, const has_template_operator&) {
     return os;
 }
 
+} // end anonymous namespace
+
 namespace Catch {
     template<>
     struct StringMaker<has_maker> {
@@ -100,6 +112,8 @@ TEST_CASE( "stringify( vectors<has_maker_and_operator> )", "[toString]" ) {
     REQUIRE( ::Catch::Detail::stringify( v ) == "{ StringMaker<has_maker_and_operator> }" );
 }
 
+namespace {
+
 // Range-based conversion should only be used if other possibilities fail
 struct int_iterator {
     using iterator_category = std::input_iterator_tag;
@@ -139,6 +153,8 @@ struct stringmaker_range {
     int_iterator end() const { return {}; }
 };
 
+} // end anonymous namespace
+
 namespace Catch {
 template <>
 struct StringMaker<stringmaker_range> {
@@ -148,6 +164,8 @@ struct StringMaker<stringmaker_range> {
 };
 }
 
+namespace {
+
 struct just_range {
     int_iterator begin() const { return int_iterator{ 1 }; }
     int_iterator end() const { return {}; }
@@ -158,6 +176,8 @@ struct disabled_range {
     int_iterator end() const { return {}; }
 };
 
+} // end anonymous namespace
+
 namespace Catch {
 template <>
 struct is_range<disabled_range> {