mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-25 23:06:10 +01:00
Decomposer checks for 0 when assuming an int arg was 0 literal
This commit is contained in:
parent
5f9d4ef331
commit
3b139ae51a
@ -12,6 +12,7 @@
|
|||||||
#include <catch2/internal/catch_stringref.hpp>
|
#include <catch2/internal/catch_stringref.hpp>
|
||||||
#include <catch2/internal/catch_meta.hpp>
|
#include <catch2/internal/catch_meta.hpp>
|
||||||
#include <catch2/internal/catch_compare_traits.hpp>
|
#include <catch2/internal/catch_compare_traits.hpp>
|
||||||
|
#include <catch2/internal/catch_test_failure_exception.hpp>
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
@ -196,6 +197,9 @@ namespace Catch {
|
|||||||
int> = 0> \
|
int> = 0> \
|
||||||
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
|
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
|
||||||
->BinaryExpr<LhsT, RhsT> { \
|
->BinaryExpr<LhsT, RhsT> { \
|
||||||
|
if ( rhs != 0 ) { \
|
||||||
|
throw_test_failure_exception(); \
|
||||||
|
} \
|
||||||
return { \
|
return { \
|
||||||
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
|
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
|
||||||
} \
|
} \
|
||||||
@ -210,6 +214,9 @@ namespace Catch {
|
|||||||
int> = 0> \
|
int> = 0> \
|
||||||
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
|
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
|
||||||
->BinaryExpr<LhsT, RhsT> { \
|
->BinaryExpr<LhsT, RhsT> { \
|
||||||
|
if ( lhs.m_lhs != 0 ) { \
|
||||||
|
throw_test_failure_exception(); \
|
||||||
|
} \
|
||||||
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
|
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
|
||||||
}
|
}
|
||||||
CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == )
|
CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == )
|
||||||
@ -247,7 +254,9 @@ namespace Catch {
|
|||||||
int> = 0> \
|
int> = 0> \
|
||||||
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
|
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
|
||||||
->BinaryExpr<LhsT, RhsT> { \
|
->BinaryExpr<LhsT, RhsT> { \
|
||||||
/* TODO: do we want to assert that Rhs is 0? */ \
|
if ( rhs != 0 ) { \
|
||||||
|
throw_test_failure_exception(); \
|
||||||
|
} \
|
||||||
return { \
|
return { \
|
||||||
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
|
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
|
||||||
} \
|
} \
|
||||||
@ -259,7 +268,9 @@ namespace Catch {
|
|||||||
int> = 0> \
|
int> = 0> \
|
||||||
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
|
friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
|
||||||
->BinaryExpr<LhsT, RhsT> { \
|
->BinaryExpr<LhsT, RhsT> { \
|
||||||
/* TODO: do we want to assert that lhs is 0? */ \
|
if ( lhs.m_lhs != 0 ) { \
|
||||||
|
throw_test_failure_exception(); \
|
||||||
|
} \
|
||||||
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
|
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
|
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
|
||||||
#include <catch2/internal/catch_optional.hpp>
|
#include <catch2/internal/catch_optional.hpp>
|
||||||
|
|
||||||
|
#include <helpers/type_with_lit_0_comparisons.hpp>
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4702) // unreachable code in the macro expansions
|
#pragma warning(disable:4702) // unreachable code in the macro expansions
|
||||||
@ -86,3 +88,44 @@ TEST_CASE("Optional comparison ops", "[optional][approvals]") {
|
|||||||
REQUIRE_FALSE( a != b );
|
REQUIRE_FALSE( a != b );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Decomposer checks that the argument is 0 when handling "
|
||||||
|
"only-0-comparable types",
|
||||||
|
"[decomposition][approvals]" ) {
|
||||||
|
TypeWithLit0Comparisons t{};
|
||||||
|
|
||||||
|
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
|
||||||
|
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
|
||||||
|
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= t == 42 );
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= 42 == t );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= t == 0 );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= 0 == t );
|
||||||
|
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= t != 42 );
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= 42 != t );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= t != 0 );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= 0 != t );
|
||||||
|
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= t < 42 );
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= 42 < t );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= t < 0 );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= 0 < t );
|
||||||
|
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= t <= 42 );
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= 42 <= t );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= t <= 0 );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= 0 <= t );
|
||||||
|
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= t > 42 );
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= 42 > t );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= t > 0 );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= 0 > t );
|
||||||
|
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= t >= 42 );
|
||||||
|
REQUIRE_THROWS( Catch::Decomposer{} <= 42 >= t );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= t >= 0 );
|
||||||
|
REQUIRE_NOTHROW( Catch::Decomposer{} <= 0 >= t );
|
||||||
|
|
||||||
|
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user