mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-07 06:39:55 +01:00
Remove isTrue, alwaysTrue, alwaysFalse
isTrue and alwaysFalse were replaced by (void)0, 0 inspired by doctest alwaysTrue was replaced by warning suppression
This commit is contained in:
parent
63c097a077
commit
401ad7a189
@ -63,7 +63,7 @@
|
|||||||
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
||||||
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::isTrue(false) && static_cast<bool>( !!(__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<bool>( !!(__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 &&.
|
// 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(); \
|
catchAssertionHandler.useActiveException(); \
|
||||||
} \
|
} \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( false )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
|
#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
|
||||||
@ -105,7 +105,7 @@
|
|||||||
else \
|
else \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( false )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
|
#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
|
||||||
@ -125,7 +125,7 @@
|
|||||||
else \
|
else \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( false )
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -134,7 +134,7 @@
|
|||||||
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
||||||
catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
|
catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( false )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_INFO( macroName, log ) \
|
#define INTERNAL_CATCH_INFO( macroName, log ) \
|
||||||
@ -156,7 +156,7 @@
|
|||||||
else \
|
else \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( false )
|
||||||
|
|
||||||
#endif // CATCH_CONFIG_DISABLE
|
#endif // CATCH_CONFIG_DISABLE
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ namespace Catch {
|
|||||||
catchAssertionHandler.handle( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
|
catchAssertionHandler.handle( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
|
||||||
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( false )
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -84,6 +84,6 @@ namespace Catch {
|
|||||||
else \
|
else \
|
||||||
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( false )
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|
||||||
|
@ -38,9 +38,6 @@ namespace Catch {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool alwaysTrue() { return true; }
|
|
||||||
bool alwaysFalse() { return false; }
|
|
||||||
|
|
||||||
std::string StreamEndStop::operator+() const {
|
std::string StreamEndStop::operator+() const {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,6 @@ namespace Catch {
|
|||||||
|
|
||||||
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
|
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
|
// Use this in variadic streaming macros to allow
|
||||||
// >> +StreamEndStop
|
// >> +StreamEndStop
|
||||||
// as well as
|
// as well as
|
||||||
|
@ -40,7 +40,7 @@ namespace Catch {
|
|||||||
#ifdef CATCH_TRAP
|
#ifdef CATCH_TRAP
|
||||||
#define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
|
#define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
|
||||||
#else
|
#else
|
||||||
#define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue();
|
#define CATCH_BREAK_INTO_DEBUGGER() (void)0, 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED
|
||||||
|
@ -762,9 +762,7 @@ Tricky.tests.cpp:<line number>
|
|||||||
|
|
||||||
Tricky.tests.cpp:<line number>:
|
Tricky.tests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE( Catch::alwaysTrue() )
|
REQUIRE( true )
|
||||||
with expansion:
|
|
||||||
true
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Assertions then sections
|
Assertions then sections
|
||||||
@ -775,9 +773,7 @@ Tricky.tests.cpp:<line number>
|
|||||||
|
|
||||||
Tricky.tests.cpp:<line number>:
|
Tricky.tests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE( Catch::alwaysTrue() )
|
REQUIRE( true )
|
||||||
with expansion:
|
|
||||||
true
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Assertions then sections
|
Assertions then sections
|
||||||
@ -789,9 +785,7 @@ Tricky.tests.cpp:<line number>
|
|||||||
|
|
||||||
Tricky.tests.cpp:<line number>:
|
Tricky.tests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE( Catch::alwaysTrue() )
|
REQUIRE( true )
|
||||||
with expansion:
|
|
||||||
true
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Assertions then sections
|
Assertions then sections
|
||||||
@ -801,9 +795,7 @@ Tricky.tests.cpp:<line number>
|
|||||||
|
|
||||||
Tricky.tests.cpp:<line number>:
|
Tricky.tests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE( Catch::alwaysTrue() )
|
REQUIRE( true )
|
||||||
with expansion:
|
|
||||||
true
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Assertions then sections
|
Assertions then sections
|
||||||
@ -814,9 +806,7 @@ Tricky.tests.cpp:<line number>
|
|||||||
|
|
||||||
Tricky.tests.cpp:<line number>:
|
Tricky.tests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE( Catch::alwaysTrue() )
|
REQUIRE( true )
|
||||||
with expansion:
|
|
||||||
true
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Assertions then sections
|
Assertions then sections
|
||||||
@ -828,9 +818,7 @@ Tricky.tests.cpp:<line number>
|
|||||||
|
|
||||||
Tricky.tests.cpp:<line number>:
|
Tricky.tests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE( Catch::alwaysTrue() )
|
REQUIRE( true )
|
||||||
with expansion:
|
|
||||||
true
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Assorted miscellaneous tests
|
Assorted miscellaneous tests
|
||||||
|
@ -819,7 +819,7 @@
|
|||||||
<TestCase name="Assertions then sections" tags="[Tricky]" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<TestCase name="Assertions then sections" tags="[Tricky]" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
Catch::alwaysTrue()
|
true
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
true
|
true
|
||||||
@ -828,7 +828,7 @@
|
|||||||
<Section name="A section" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Section name="A section" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
Catch::alwaysTrue()
|
true
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
true
|
true
|
||||||
@ -837,7 +837,7 @@
|
|||||||
<Section name="Another section" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Section name="Another section" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
Catch::alwaysTrue()
|
true
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
true
|
true
|
||||||
@ -849,7 +849,7 @@
|
|||||||
</Section>
|
</Section>
|
||||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
Catch::alwaysTrue()
|
true
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
true
|
true
|
||||||
@ -858,7 +858,7 @@
|
|||||||
<Section name="A section" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Section name="A section" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
Catch::alwaysTrue()
|
true
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
true
|
true
|
||||||
@ -867,7 +867,7 @@
|
|||||||
<Section name="Another other section" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Section name="Another other section" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Tricky.tests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
Catch::alwaysTrue()
|
true
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
true
|
true
|
||||||
|
@ -12,11 +12,12 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#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
|
#endif
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wweak-vtables"
|
#pragma clang diagnostic ignored "-Wweak-vtables"
|
||||||
|
#pragma clang diagnostic ignored "-Wmissing-noreturn"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace { namespace ExceptionTests {
|
namespace { namespace ExceptionTests {
|
||||||
@ -24,8 +25,7 @@ namespace { namespace ExceptionTests {
|
|||||||
#ifndef EXCEPTION_TEST_HELPERS_INCLUDED // Don't compile this more than once per TU
|
#ifndef EXCEPTION_TEST_HELPERS_INCLUDED // Don't compile this more than once per TU
|
||||||
#define EXCEPTION_TEST_HELPERS_INCLUDED
|
#define EXCEPTION_TEST_HELPERS_INCLUDED
|
||||||
|
|
||||||
inline int thisThrows() {
|
int thisThrows() {
|
||||||
if( Catch::alwaysTrue() )
|
|
||||||
throw std::domain_error( "expected exception" );
|
throw std::domain_error( "expected exception" );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -63,8 +63,7 @@ private:
|
|||||||
std::string m_msg;
|
std::string m_msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void throwCustom() {
|
[[noreturn]] void throwCustom() {
|
||||||
if( Catch::alwaysTrue() )
|
|
||||||
throw CustomException( "custom exception - not std" );
|
throw CustomException( "custom exception - not std" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,19 +82,16 @@ 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]" ) {
|
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]" ) {
|
TEST_CASE( "An unchecked exception reports the line of the last assertion", "[.][failing][!throws]" ) {
|
||||||
CHECK( 1 == 1 );
|
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]" ) {
|
TEST_CASE( "When unchecked exceptions are thrown from sections they are always failures", "[.][failing][!throws]" ) {
|
||||||
SECTION( "section name" ) {
|
SECTION( "section name" ) {
|
||||||
if( Catch::alwaysTrue() )
|
|
||||||
throw std::domain_error("unexpected exception");
|
throw std::domain_error("unexpected exception");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,12 +135,10 @@ CATCH_TRANSLATE_EXCEPTION( double& ex ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Non-std exceptions can be translated", "[.][failing][!throws]" ) {
|
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]" ) {
|
TEST_CASE("Custom std-exceptions can be custom translated", "[.][failing][!throws]" ) {
|
||||||
if( Catch::alwaysTrue() )
|
|
||||||
throw CustomException( "custom std exception" );
|
throw CustomException( "custom std exception" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +151,6 @@ TEST_CASE( "Custom exceptions can be translated when testing for throwing as som
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Unexpected exceptions can be translated", "[.][failing][!throws]" ) {
|
TEST_CASE( "Unexpected exceptions can be translated", "[.][failing][!throws]" ) {
|
||||||
if( Catch::alwaysTrue() )
|
|
||||||
throw double( 3.14 );
|
throw double( 3.14 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,19 +298,19 @@ TEST_CASE( "Assertions then sections", "[Tricky]" )
|
|||||||
// This was causing a failure due to the way the console reporter was handling
|
// This was causing a failure due to the way the console reporter was handling
|
||||||
// the current section
|
// the current section
|
||||||
|
|
||||||
REQUIRE( Catch::alwaysTrue() );
|
REQUIRE( true );
|
||||||
|
|
||||||
SECTION( "A section" )
|
SECTION( "A section" )
|
||||||
{
|
{
|
||||||
REQUIRE( Catch::alwaysTrue() );
|
REQUIRE( true );
|
||||||
|
|
||||||
SECTION( "Another section" )
|
SECTION( "Another section" )
|
||||||
{
|
{
|
||||||
REQUIRE( Catch::alwaysTrue() );
|
REQUIRE( true );
|
||||||
}
|
}
|
||||||
SECTION( "Another other section" )
|
SECTION( "Another other section" )
|
||||||
{
|
{
|
||||||
REQUIRE( Catch::alwaysTrue() );
|
REQUIRE( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user