mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Add -Wmissing-declarations to the SelfTest project
This required some clean-up in our test files
This commit is contained in:
		| @@ -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" ) { | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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][.]") { | ||||
|   | ||||
| @@ -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" ); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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> { | ||||
|   | ||||
| @@ -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> { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský