Add evaluation specialization for T* and long

Fixes #1005
This commit is contained in:
Martin Hořeňovský 2017-08-30 11:40:29 +02:00
parent 07211cea9c
commit 61d2c375dd
7 changed files with 82 additions and 9 deletions

View File

@ -80,14 +80,22 @@ namespace Catch {
template<typename T> template<typename T>
auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }; auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); };
template<typename T> template<typename T>
auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); };
template<typename T>
auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }; auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; };
template<typename T>
auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; };
template<typename LhsT, typename RhsT> template<typename LhsT, typename RhsT>
auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return const_cast<LhsT&>( lhs ) != rhs; }; auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return const_cast<LhsT&>( lhs ) != rhs; };
template<typename T> template<typename T>
auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }; auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); };
template<typename T> template<typename T>
auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); };
template<typename T>
auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }; auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; };
template<typename T>
auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; };
template<typename LhsT> template<typename LhsT>

View File

@ -1020,6 +1020,6 @@ with expansion:
"{?}" == "1" "{?}" == "1"
=============================================================================== ===============================================================================
test cases: 183 | 132 passed | 47 failed | 4 failed as expected test cases: 184 | 133 passed | 47 failed | 4 failed as expected
assertions: 882 | 765 passed | 96 failed | 21 failed as expected assertions: 884 | 767 passed | 96 failed | 21 failed as expected

View File

@ -14,6 +14,25 @@ PASSED:
with message: with message:
yay yay
-------------------------------------------------------------------------------
#1005: Comparing pointer to int and long (NULL can be either on various
systems)
-------------------------------------------------------------------------------
DecompositionTests.cpp:<line number>
...............................................................................
DecompositionTests.cpp:<line number>:
PASSED:
REQUIRE( fptr == 0 )
with expansion:
0 == 0
DecompositionTests.cpp:<line number>:
PASSED:
REQUIRE( fptr == 0l )
with expansion:
0 == 0
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
#748 - captures with unexpected exceptions #748 - captures with unexpected exceptions
outside assertions outside assertions
@ -7535,6 +7554,6 @@ MiscTests.cpp:<line number>:
PASSED: PASSED:
=============================================================================== ===============================================================================
test cases: 183 | 129 passed | 50 failed | 4 failed as expected test cases: 184 | 130 passed | 50 failed | 4 failed as expected
assertions: 884 | 761 passed | 102 failed | 21 failed as expected assertions: 886 | 763 passed | 102 failed | 21 failed as expected

View File

@ -14,6 +14,25 @@ PASSED:
with message: with message:
yay yay
-------------------------------------------------------------------------------
#1005: Comparing pointer to int and long (NULL can be either on various
systems)
-------------------------------------------------------------------------------
DecompositionTests.cpp:<line number>
...............................................................................
DecompositionTests.cpp:<line number>:
PASSED:
REQUIRE( fptr == 0 )
with expansion:
0 == 0
DecompositionTests.cpp:<line number>:
PASSED:
REQUIRE( fptr == 0l )
with expansion:
0 == 0
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
#748 - captures with unexpected exceptions #748 - captures with unexpected exceptions
outside assertions outside assertions
@ -218,6 +237,6 @@ ConditionTests.cpp:<line number>: FAILED:
CHECK_FALSE( true ) CHECK_FALSE( true )
=============================================================================== ===============================================================================
test cases: 8 | 5 passed | 1 failed | 2 failed as expected test cases: 9 | 6 passed | 1 failed | 2 failed as expected
assertions: 24 | 17 passed | 4 failed | 3 failed as expected assertions: 26 | 19 passed | 4 failed | 3 failed as expected

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <testsuitesloose text artifact
> >
<testsuite name="<exe-name>" errors="15" failures="88" tests="885" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="15" failures="88" tests="887" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/> <testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}"> <testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}">
<error type="TEST_CASE"> <error type="TEST_CASE">
expected exception expected exception

View File

@ -4,6 +4,25 @@
<TestCase name="# A test name that starts with a #" filename="projects/<exe-name>/MiscTests.cpp" > <TestCase name="# A test name that starts with a #" filename="projects/<exe-name>/MiscTests.cpp" >
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" tags="[Decomposition]" filename="projects/<exe-name>/DecompositionTests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/DecompositionTests.cpp" >
<Original>
fptr == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/DecompositionTests.cpp" >
<Original>
fptr == 0l
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="#748 - captures with unexpected exceptions" tags="[!shouldfail][!throws][.][failing]" filename="projects/<exe-name>/ExceptionTests.cpp" > <TestCase name="#748 - captures with unexpected exceptions" tags="[!shouldfail][!throws][.][failing]" filename="projects/<exe-name>/ExceptionTests.cpp" >
<Section name="outside assertions" filename="projects/<exe-name>/ExceptionTests.cpp" > <Section name="outside assertions" filename="projects/<exe-name>/ExceptionTests.cpp" >
<Info> <Info>
@ -8287,7 +8306,7 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="761" failures="103" expectedFailures="21"/> <OverallResults successes="763" failures="103" expectedFailures="21"/>
</Group> </Group>
<OverallResults successes="761" failures="102" expectedFailures="21"/> <OverallResults successes="763" failures="102" expectedFailures="21"/>
</Catch> </Catch>

View File

@ -7,6 +7,7 @@
*/ */
#include <iostream> #include <iostream>
#include <cstdio>
struct truthy { struct truthy {
truthy(bool b):m_value(b){} truthy(bool b):m_value(b){}
@ -26,3 +27,9 @@ std::ostream& operator<<(std::ostream& o, truthy) {
TEST_CASE( "Reconstruction should be based on stringification: #914" , "[Decomposition][failing][.]") { TEST_CASE( "Reconstruction should be based on stringification: #914" , "[Decomposition][failing][.]") {
CHECK(truthy(false)); CHECK(truthy(false));
} }
TEST_CASE("#1005: Comparing pointer to int and long (NULL can be either on various systems)", "[Decomposition]") {
FILE* fptr = nullptr;
REQUIRE(fptr == 0);
REQUIRE(fptr == 0l);
}