Use CATCH_NULL instead of NULL

- expands to nullptr if CATCH_CONFIG_CPP11_NULLPTR is defined (see #444)
This commit is contained in:
Phil Nash
2015-07-01 07:33:27 +01:00
parent 3b18d9e962
commit 805de43a3d
25 changed files with 112 additions and 101 deletions

View File

@@ -973,51 +973,51 @@ ConditionTests.cpp:<line number>
ConditionTests.cpp:<line number>:
PASSED:
REQUIRE( p == __null )
REQUIRE( p == nullptr )
with expansion:
__null == 0
NULL == nullptr
ConditionTests.cpp:<line number>:
PASSED:
REQUIRE( p == pNULL )
with expansion:
__null == __null
NULL == NULL
ConditionTests.cpp:<line number>:
PASSED:
REQUIRE( p != __null )
REQUIRE( p != nullptr )
with expansion:
0x<hex digits> != 0
0x<hex digits> != nullptr
ConditionTests.cpp:<line number>:
PASSED:
REQUIRE( cp != __null )
REQUIRE( cp != nullptr )
with expansion:
0x<hex digits> != 0
0x<hex digits> != nullptr
ConditionTests.cpp:<line number>:
PASSED:
REQUIRE( cpc != __null )
REQUIRE( cpc != nullptr )
with expansion:
0x<hex digits> != 0
0x<hex digits> != nullptr
ConditionTests.cpp:<line number>:
PASSED:
REQUIRE( returnsNull() == __null )
REQUIRE( returnsNull() == nullptr )
with expansion:
{null string} == 0
{null string} == nullptr
ConditionTests.cpp:<line number>:
PASSED:
REQUIRE( returnsConstNull() == __null )
REQUIRE( returnsConstNull() == nullptr )
with expansion:
{null string} == 0
{null string} == nullptr
ConditionTests.cpp:<line number>:
PASSED:
REQUIRE( __null != p )
REQUIRE( nullptr != p )
with expansion:
0 != 0x<hex digits>
nullptr != 0x<hex digits>
-------------------------------------------------------------------------------
'Not' checks that should succeed
@@ -3113,13 +3113,13 @@ MiscTests.cpp:<line number>
MiscTests.cpp:<line number>:
PASSED:
REQUIRE( makeString( false ) != static_cast<char*>(__null) )
REQUIRE( makeString( false ) != static_cast<char*>(nullptr) )
with expansion:
"valid string" != {null string}
MiscTests.cpp:<line number>:
PASSED:
REQUIRE( makeString( true ) == static_cast<char*>(__null) )
REQUIRE( makeString( true ) == static_cast<char*>(nullptr) )
with expansion:
{null string} == {null string}
@@ -3316,7 +3316,7 @@ MiscTests.cpp:<line number>
MiscTests.cpp:<line number>:
PASSED:
REQUIRE_THAT( "" Equals(__null) )
REQUIRE_THAT( "" Equals(nullptr) )
with expansion:
"" equals: ""
@@ -5863,9 +5863,9 @@ TrickyTests.cpp:<line number>
TrickyTests.cpp:<line number>:
PASSED:
REQUIRE( obj.prop != __null )
REQUIRE( obj.prop != nullptr )
with expansion:
0x<hex digits> != 0
0x<hex digits> != nullptr
-------------------------------------------------------------------------------
(unimplemented) static bools can be evaluated
@@ -6106,7 +6106,7 @@ TrickyTests.cpp:<line number>:
PASSED:
REQUIRE( p == 0 )
with expansion:
__null == 0
NULL == 0
-------------------------------------------------------------------------------
null_ptr
@@ -6118,7 +6118,7 @@ TrickyTests.cpp:<line number>:
PASSED:
REQUIRE( ptr.get() == nullptr )
with expansion:
__null == nullptr
NULL == nullptr
-------------------------------------------------------------------------------
X/level/0/a

View File

@@ -1205,10 +1205,10 @@
<TestCase name="Pointers can be compared to null">
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/ConditionTests.cpp" >
<Original>
p == __null
p == nullptr
</Original>
<Expanded>
__null == 0
NULL == nullptr
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/ConditionTests.cpp" >
@@ -1216,55 +1216,55 @@
p == pNULL
</Original>
<Expanded>
__null == __null
NULL == NULL
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/ConditionTests.cpp" >
<Original>
p != __null
p != nullptr
</Original>
<Expanded>
0x<hex digits> != 0
0x<hex digits> != nullptr
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/ConditionTests.cpp" >
<Original>
cp != __null
cp != nullptr
</Original>
<Expanded>
0x<hex digits> != 0
0x<hex digits> != nullptr
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/ConditionTests.cpp" >
<Original>
cpc != __null
cpc != nullptr
</Original>
<Expanded>
0x<hex digits> != 0
0x<hex digits> != nullptr
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/ConditionTests.cpp" >
<Original>
returnsNull() == __null
returnsNull() == nullptr
</Original>
<Expanded>
{null string} == 0
{null string} == nullptr
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/ConditionTests.cpp" >
<Original>
returnsConstNull() == __null
returnsConstNull() == nullptr
</Original>
<Expanded>
{null string} == 0
{null string} == nullptr
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/ConditionTests.cpp" >
<Original>
__null != p
nullptr != p
</Original>
<Expanded>
0 != 0x<hex digits>
nullptr != 0x<hex digits>
</Expanded>
</Expression>
<OverallResult success="true"/>
@@ -3226,7 +3226,7 @@
<TestCase name="null strings">
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/MiscTests.cpp" >
<Original>
makeString( false ) != static_cast&lt;char*>(__null)
makeString( false ) != static_cast&lt;char*>(nullptr)
</Original>
<Expanded>
&quot;valid string&quot; != {null string}
@@ -3234,7 +3234,7 @@
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/MiscTests.cpp" >
<Original>
makeString( true ) == static_cast&lt;char*>(__null)
makeString( true ) == static_cast&lt;char*>(nullptr)
</Original>
<Expanded>
{null string} == {null string}
@@ -3434,7 +3434,7 @@
<TestCase name="Equals string matcher, with NULL">
<Expression success="true" type="REQUIRE_THAT" filename="projects/SelfTest/MiscTests.cpp" >
<Original>
&quot;&quot; Equals(__null)
&quot;&quot; Equals(nullptr)
</Original>
<Expanded>
&quot;&quot; equals: &quot;&quot;
@@ -6041,10 +6041,10 @@ there&quot;
<TestCase name="boolean member">
<Expression success="true" type="REQUIRE" filename="projects/SelfTest/TrickyTests.cpp" >
<Original>
obj.prop != __null
obj.prop != nullptr
</Original>
<Expanded>
0x<hex digits> != 0
0x<hex digits> != nullptr
</Expanded>
</Expression>
<OverallResult success="true"/>
@@ -6270,7 +6270,7 @@ there&quot;
p == 0
</Original>
<Expanded>
__null == 0
NULL == 0
</Expanded>
</Expression>
<OverallResult success="true"/>
@@ -6281,7 +6281,7 @@ there&quot;
ptr.get() == nullptr
</Original>
<Expanded>
__null == nullptr
NULL == nullptr
</Expanded>
</Expression>
<OverallResult success="true"/>

View File

@@ -10,7 +10,7 @@
#include "catch_test_spec_parser.hpp"
inline Catch::TestCase fakeTestCase( const char* name, const char* desc = "" ){ return Catch::makeTestCase( NULL, "", name, desc, CATCH_INTERNAL_LINEINFO ); }
inline Catch::TestCase fakeTestCase( const char* name, const char* desc = "" ){ return Catch::makeTestCase( CATCH_NULL, "", name, desc, CATCH_INTERNAL_LINEINFO ); }
TEST_CASE( "Parse test names and tags", "" ) {

View File

@@ -265,32 +265,32 @@ TEST_CASE( "Comparisons between ints where one side is computed", "" )
#pragma GCC diagnostic pop
#endif
inline const char* returnsConstNull(){ return NULL; }
inline char* returnsNull(){ return NULL; }
inline const char* returnsConstNull(){ return CATCH_NULL; }
inline char* returnsNull(){ return CATCH_NULL; }
TEST_CASE( "Pointers can be compared to null", "" )
{
TestData* p = NULL;
TestData* pNULL = NULL;
TestData* p = CATCH_NULL;
TestData* pNULL = CATCH_NULL;
REQUIRE( p == NULL );
REQUIRE( p == CATCH_NULL );
REQUIRE( p == pNULL );
TestData data;
p = &data;
REQUIRE( p != NULL );
REQUIRE( p != CATCH_NULL );
const TestData* cp = p;
REQUIRE( cp != NULL );
REQUIRE( cp != CATCH_NULL );
const TestData* const cpc = p;
REQUIRE( cpc != NULL );
REQUIRE( cpc != CATCH_NULL );
REQUIRE( returnsNull() == NULL );
REQUIRE( returnsConstNull() == NULL );
REQUIRE( returnsNull() == CATCH_NULL );
REQUIRE( returnsConstNull() == CATCH_NULL );
REQUIRE( NULL != p );
REQUIRE( CATCH_NULL != p );
}
// Not (!) tests

View File

@@ -124,13 +124,13 @@ TEST_CASE( "Sends stuff to stdout and stderr", "[.]" )
inline const char* makeString( bool makeNull )
{
return makeNull ? NULL : "valid string";
return makeNull ? CATCH_NULL : "valid string";
}
TEST_CASE( "null strings", "" )
{
REQUIRE( makeString( false ) != static_cast<char*>(NULL));
REQUIRE( makeString( true ) == static_cast<char*>(NULL));
REQUIRE( makeString( false ) != static_cast<char*>(CATCH_NULL));
REQUIRE( makeString( true ) == static_cast<char*>(CATCH_NULL));
}
@@ -233,7 +233,7 @@ TEST_CASE("Equals string matcher", "[.][failing][matchers]")
}
TEST_CASE("Equals string matcher, with NULL", "[matchers]")
{
REQUIRE_THAT("", Equals(NULL));
REQUIRE_THAT("", Equals(CATCH_NULL));
}
TEST_CASE("AllOf matcher", "[matchers]")
{

View File

@@ -39,7 +39,7 @@ std::string parseIntoConfigAndReturnError( const char * (&argv)[size], Catch::Co
return "";
}
inline Catch::TestCase fakeTestCase( const char* name, const char* desc = "" ){ return Catch::makeTestCase( NULL, "", name, desc, CATCH_INTERNAL_LINEINFO ); }
inline Catch::TestCase fakeTestCase( const char* name, const char* desc = "" ){ return Catch::makeTestCase( CATCH_NULL, "", name, desc, CATCH_INTERNAL_LINEINFO ); }
TEST_CASE( "Process can be configured on command line", "[config][command-line]" ) {

View File

@@ -42,12 +42,14 @@ TEST_CASE( "tuple<tuple<int>,tuple<>,float>", "[toString][tuple]" )
CHECK( "{ { 42 }, { }, 1.2f }" == Catch::toString(value) );
}
#ifdef CATCH_CONFIG_CPP11_NULLPTR
TEST_CASE( "tuple<nullptr,int,const char *>", "[toString][tuple]" )
{
typedef std::tuple<std::nullptr_t,int,const char *> type;
type value { nullptr, 42, "Catch me" };
CHECK( "{ nullptr, 42, \"Catch me\" }" == Catch::toString(value) );
}
#endif
#ifdef __clang__
#pragma clang diagnostic pop

View File

@@ -234,7 +234,7 @@ struct Obj
TEST_CASE("boolean member", "[Tricky]")
{
Obj obj;
REQUIRE( obj.prop != NULL );
REQUIRE( obj.prop != CATCH_NULL );
}
// Tests for a problem submitted by Ralph McArdell