From 401ad7a18941fb3744533a315a8a9500a7f573c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 21 Nov 2017 21:39:40 +0100 Subject: [PATCH] Remove isTrue, alwaysTrue, alwaysFalse isTrue and alwaysFalse were replaced by (void)0, 0 inspired by doctest alwaysTrue was replaced by warning suppression --- include/internal/catch_capture.hpp | 12 +++---- include/internal/catch_capture_matchers.h | 4 +-- include/internal/catch_common.cpp | 3 -- include/internal/catch_common.h | 5 --- include/internal/catch_debugger.h | 2 +- .../Baselines/console.sw.approved.txt | 24 ++++---------- .../SelfTest/Baselines/xml.sw.approved.txt | 12 +++---- .../SelfTest/UsageTests/Exception.tests.cpp | 31 +++++++------------ projects/SelfTest/UsageTests/Tricky.tests.cpp | 8 ++--- 9 files changed, 37 insertions(+), 64 deletions(-) diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 595336d4..e0613487 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -63,7 +63,7 @@ CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( Catch::isTrue(false) && static_cast( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look + } while( (void)0, 0 && static_cast( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. /////////////////////////////////////////////////////////////////////////////// @@ -88,7 +88,7 @@ catchAssertionHandler.useActiveException(); \ } \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( Catch::alwaysFalse() ) + } while( false ) /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \ @@ -105,7 +105,7 @@ else \ catchAssertionHandler.handle( Catch::ResultWas::Ok ); \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( Catch::alwaysFalse() ) + } while( false ) /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ @@ -125,7 +125,7 @@ else \ catchAssertionHandler.handle( Catch::ResultWas::Ok ); \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( Catch::alwaysFalse() ) + } while( false ) /////////////////////////////////////////////////////////////////////////////// @@ -134,7 +134,7 @@ Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( Catch::alwaysFalse() ) + } while( false ) /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_INFO( macroName, log ) \ @@ -156,7 +156,7 @@ else \ catchAssertionHandler.handle( Catch::ResultWas::Ok ); \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( Catch::alwaysFalse() ) + } while( false ) #endif // CATCH_CONFIG_DISABLE diff --git a/include/internal/catch_capture_matchers.h b/include/internal/catch_capture_matchers.h index 77366f33..cce61747 100644 --- a/include/internal/catch_capture_matchers.h +++ b/include/internal/catch_capture_matchers.h @@ -63,7 +63,7 @@ namespace Catch { catchAssertionHandler.handle( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \ } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( Catch::alwaysFalse() ) + } while( false ) /////////////////////////////////////////////////////////////////////////////// @@ -84,6 +84,6 @@ namespace Catch { else \ catchAssertionHandler.handle( Catch::ResultWas::Ok ); \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( Catch::alwaysFalse() ) + } while( false ) #endif // TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED diff --git a/include/internal/catch_common.cpp b/include/internal/catch_common.cpp index 470b7ea9..e96c3be2 100644 --- a/include/internal/catch_common.cpp +++ b/include/internal/catch_common.cpp @@ -38,9 +38,6 @@ namespace Catch { return os; } - bool alwaysTrue() { return true; } - bool alwaysFalse() { return false; } - std::string StreamEndStop::operator+() const { return std::string(); } diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h index 026ac2bb..c1a771c1 100644 --- a/include/internal/catch_common.h +++ b/include/internal/catch_common.h @@ -60,11 +60,6 @@ namespace Catch { std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - // This is just here to avoid compiler warnings with macro constants and boolean literals - inline bool isTrue( bool value ){ return value; } - bool alwaysTrue(); - bool alwaysFalse(); - // Use this in variadic streaming macros to allow // >> +StreamEndStop // as well as diff --git a/include/internal/catch_debugger.h b/include/internal/catch_debugger.h index f842ff5b..6ca6a539 100644 --- a/include/internal/catch_debugger.h +++ b/include/internal/catch_debugger.h @@ -40,7 +40,7 @@ namespace Catch { #ifdef CATCH_TRAP #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } #else - #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue(); + #define CATCH_BREAK_INTO_DEBUGGER() (void)0, 0 #endif #endif // TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 6eac35ed..26270ec6 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -762,9 +762,7 @@ Tricky.tests.cpp: Tricky.tests.cpp:: PASSED: - REQUIRE( Catch::alwaysTrue() ) -with expansion: - true + REQUIRE( true ) ------------------------------------------------------------------------------- Assertions then sections @@ -775,9 +773,7 @@ Tricky.tests.cpp: Tricky.tests.cpp:: PASSED: - REQUIRE( Catch::alwaysTrue() ) -with expansion: - true + REQUIRE( true ) ------------------------------------------------------------------------------- Assertions then sections @@ -789,9 +785,7 @@ Tricky.tests.cpp: Tricky.tests.cpp:: PASSED: - REQUIRE( Catch::alwaysTrue() ) -with expansion: - true + REQUIRE( true ) ------------------------------------------------------------------------------- Assertions then sections @@ -801,9 +795,7 @@ Tricky.tests.cpp: Tricky.tests.cpp:: PASSED: - REQUIRE( Catch::alwaysTrue() ) -with expansion: - true + REQUIRE( true ) ------------------------------------------------------------------------------- Assertions then sections @@ -814,9 +806,7 @@ Tricky.tests.cpp: Tricky.tests.cpp:: PASSED: - REQUIRE( Catch::alwaysTrue() ) -with expansion: - true + REQUIRE( true ) ------------------------------------------------------------------------------- Assertions then sections @@ -828,9 +818,7 @@ Tricky.tests.cpp: Tricky.tests.cpp:: PASSED: - REQUIRE( Catch::alwaysTrue() ) -with expansion: - true + REQUIRE( true ) ------------------------------------------------------------------------------- Assorted miscellaneous tests diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index d194c96e..925c54d0 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -819,7 +819,7 @@ - Catch::alwaysTrue() + true true @@ -828,7 +828,7 @@
- Catch::alwaysTrue() + true true @@ -837,7 +837,7 @@
- Catch::alwaysTrue() + true true @@ -849,7 +849,7 @@
- Catch::alwaysTrue() + true true @@ -858,7 +858,7 @@
- Catch::alwaysTrue() + true true @@ -867,7 +867,7 @@
- Catch::alwaysTrue() + true true diff --git a/projects/SelfTest/UsageTests/Exception.tests.cpp b/projects/SelfTest/UsageTests/Exception.tests.cpp index 1100114a..b9a9ef36 100644 --- a/projects/SelfTest/UsageTests/Exception.tests.cpp +++ b/projects/SelfTest/UsageTests/Exception.tests.cpp @@ -12,11 +12,12 @@ #include #ifdef _MSC_VER -#pragma warning(disable:4702) // Unreachable code -- MSVC 19 (VS 2015) sees right through the indirection +#pragma warning(disable:4702) // Unreachable code -- uncoditional throws and so on #endif #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wweak-vtables" +#pragma clang diagnostic ignored "-Wmissing-noreturn" #endif namespace { namespace ExceptionTests { @@ -24,9 +25,8 @@ namespace { namespace ExceptionTests { #ifndef EXCEPTION_TEST_HELPERS_INCLUDED // Don't compile this more than once per TU #define EXCEPTION_TEST_HELPERS_INCLUDED -inline int thisThrows() { - if( Catch::alwaysTrue() ) - throw std::domain_error( "expected exception" ); +int thisThrows() { + throw std::domain_error( "expected exception" ); return 1; } @@ -63,9 +63,8 @@ private: std::string m_msg; }; -inline void throwCustom() { - if( Catch::alwaysTrue() ) - throw CustomException( "custom exception - not std" ); +[[noreturn]] void throwCustom() { + throw CustomException( "custom exception - not std" ); } #endif @@ -83,20 +82,17 @@ TEST_CASE( "Expected exceptions that don't throw or unexpected exceptions fail t } TEST_CASE( "When unchecked exceptions are thrown directly they are always failures", "[.][failing][!throws]" ) { - if( Catch::alwaysTrue() ) - throw std::domain_error( "unexpected exception" ); + throw std::domain_error( "unexpected exception" ); } TEST_CASE( "An unchecked exception reports the line of the last assertion", "[.][failing][!throws]" ) { CHECK( 1 == 1 ); - if( Catch::alwaysTrue() ) - throw std::domain_error( "unexpected exception" ); + throw std::domain_error( "unexpected exception" ); } TEST_CASE( "When unchecked exceptions are thrown from sections they are always failures", "[.][failing][!throws]" ) { SECTION( "section name" ) { - if( Catch::alwaysTrue() ) - throw std::domain_error( "unexpected exception" ); + throw std::domain_error("unexpected exception"); } } @@ -139,13 +135,11 @@ CATCH_TRANSLATE_EXCEPTION( double& ex ) { } TEST_CASE("Non-std exceptions can be translated", "[.][failing][!throws]" ) { - if( Catch::alwaysTrue() ) - throw CustomException( "custom exception" ); + throw CustomException( "custom exception" ); } TEST_CASE("Custom std-exceptions can be custom translated", "[.][failing][!throws]" ) { - if( Catch::alwaysTrue() ) - throw CustomException( "custom std exception" ); + throw CustomException( "custom std exception" ); } TEST_CASE( "Custom exceptions can be translated when testing for nothrow", "[.][failing][!throws]" ) { @@ -157,8 +151,7 @@ TEST_CASE( "Custom exceptions can be translated when testing for throwing as som } TEST_CASE( "Unexpected exceptions can be translated", "[.][failing][!throws]" ) { - if( Catch::alwaysTrue() ) - throw double( 3.14 ); + throw double( 3.14 ); } #ifndef CATCH_CONFIG_DISABLE_MATCHERS diff --git a/projects/SelfTest/UsageTests/Tricky.tests.cpp b/projects/SelfTest/UsageTests/Tricky.tests.cpp index 79d2c63c..1c352ce9 100644 --- a/projects/SelfTest/UsageTests/Tricky.tests.cpp +++ b/projects/SelfTest/UsageTests/Tricky.tests.cpp @@ -298,19 +298,19 @@ TEST_CASE( "Assertions then sections", "[Tricky]" ) // This was causing a failure due to the way the console reporter was handling // the current section - REQUIRE( Catch::alwaysTrue() ); + REQUIRE( true ); SECTION( "A section" ) { - REQUIRE( Catch::alwaysTrue() ); + REQUIRE( true ); SECTION( "Another section" ) { - REQUIRE( Catch::alwaysTrue() ); + REQUIRE( true ); } SECTION( "Another other section" ) { - REQUIRE( Catch::alwaysTrue() ); + REQUIRE( true ); } } }