Some minor tidy-up/ style alignment of recent toString merges

This commit is contained in:
Phil Nash 2014-09-04 07:27:09 +01:00
parent 4caabfa45e
commit 886ef1620a
9 changed files with 79 additions and 53 deletions

View File

@ -787,5 +787,5 @@ with expansion:
=============================================================================== ===============================================================================
test cases: 148 | 109 passed | 38 failed | 1 failed as expected test cases: 148 | 109 passed | 38 failed | 1 failed as expected
assertions: 738 | 646 passed | 79 failed | 13 failed as expected assertions: 739 | 647 passed | 79 failed | 13 failed as expected

View File

@ -75,6 +75,14 @@ PASSED:
with expansion: with expansion:
"E2/V1" == "E2/V1" "E2/V1" == "E2/V1"
EnumToString.cpp:<line number>:
PASSED:
CHECK( Catch::toString(e3) == "Unknown enum value 10" )
with expansion:
"Unknown enum value 10"
==
"Unknown enum value 10"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Some simple comparisons between doubles Some simple comparisons between doubles
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -7676,5 +7684,5 @@ with expansion:
=============================================================================== ===============================================================================
test cases: 148 | 93 passed | 54 failed | 1 failed as expected test cases: 148 | 93 passed | 54 failed | 1 failed as expected
assertions: 758 | 646 passed | 99 failed | 13 failed as expected assertions: 759 | 647 passed | 99 failed | 13 failed as expected

View File

@ -75,6 +75,14 @@ PASSED:
with expansion: with expansion:
"E2/V1" == "E2/V1" "E2/V1" == "E2/V1"
EnumToString.cpp:<line number>:
PASSED:
CHECK( Catch::toString(e3) == "Unknown enum value 10" )
with expansion:
"Unknown enum value 10"
==
"Unknown enum value 10"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Some simple comparisons between doubles Some simple comparisons between doubles
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -479,5 +487,5 @@ with expansion:
=============================================================================== ===============================================================================
test cases: 19 | 15 passed | 3 failed | 1 failed as expected test cases: 19 | 15 passed | 3 failed | 1 failed as expected
assertions: 61 | 55 passed | 4 failed | 2 failed as expected assertions: 62 | 56 passed | 4 failed | 2 failed as expected

View File

@ -1,5 +1,5 @@
<testsuites> <testsuites>
<testsuite errors="12" failures="87" tests="758" hostname="tbd" time="{duration}" timestamp="tbd"> <testsuite errors="12" failures="87" tests="759" hostname="tbd" time="{duration}" timestamp="tbd">
<testcase classname="global" name="toString(enum)" time="{duration}"/> <testcase classname="global" name="toString(enum)" time="{duration}"/>
<testcase classname="global" name="toString(enum w/operator&lt;&lt;)" time="{duration}"/> <testcase classname="global" name="toString(enum w/operator&lt;&lt;)" time="{duration}"/>
<testcase classname="global" name="toString(enum class)" time="{duration}"/> <testcase classname="global" name="toString(enum class)" time="{duration}"/>

View File

@ -74,6 +74,16 @@
&quot;E2/V1&quot; == &quot;E2/V1&quot; &quot;E2/V1&quot; == &quot;E2/V1&quot;
</Expanded> </Expanded>
</Expression> </Expression>
<Expression success="true" filename="/Users/philnash/Dev/OSS/Catch-Dev/projects/SelfTest/EnumToString.cpp" >
<Original>
Catch::toString(e3) == &quot;Unknown enum value 10&quot;
</Original>
<Expanded>
&quot;Unknown enum value 10&quot;
==
&quot;Unknown enum value 10&quot;
</Expanded>
</Expression>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="Some simple comparisons between doubles"> <TestCase name="Some simple comparisons between doubles">
@ -7940,7 +7950,7 @@ there&quot;
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="646" failures="99" expectedFailures="13"/> <OverallResults successes="647" failures="99" expectedFailures="13"/>
</Group> </Group>
<OverallResults successes="646" failures="99" expectedFailures="13"/> <OverallResults successes="647" failures="99" expectedFailures="13"/>
</Catch> </Catch>

View File

@ -8,8 +8,7 @@
// Enum without user-provided stream operator // Enum without user-provided stream operator
enum Enum1 { Enum1Value0, Enum1Value1 }; enum Enum1 { Enum1Value0, Enum1Value1 };
TEST_CASE( "toString(enum)", "[toString][enum]" ) TEST_CASE( "toString(enum)", "[toString][enum]" ) {
{
Enum1 e0 = Enum1Value0; Enum1 e0 = Enum1Value0;
CHECK( Catch::toString(e0) == "0" ); CHECK( Catch::toString(e0) == "0" );
Enum1 e1 = Enum1Value1; Enum1 e1 = Enum1Value1;
@ -19,13 +18,11 @@ TEST_CASE( "toString(enum)", "[toString][enum]" )
// Enum with user-provided stream operator // Enum with user-provided stream operator
enum Enum2 { Enum2Value0, Enum2Value1 }; enum Enum2 { Enum2Value0, Enum2Value1 };
inline std::ostream& operator<<( std::ostream& os, Enum2 v ) inline std::ostream& operator<<( std::ostream& os, Enum2 v ) {
{
return os << "E2{" << static_cast<int>(v) << "}"; return os << "E2{" << static_cast<int>(v) << "}";
} }
TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" ) TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" ) {
{
Enum2 e0 = Enum2Value0; Enum2 e0 = Enum2Value0;
CHECK( Catch::toString(e0) == "E2{0}" ); CHECK( Catch::toString(e0) == "E2{0}" );
Enum2 e1 = Enum2Value1; Enum2 e1 = Enum2Value1;
@ -33,11 +30,15 @@ TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" )
} }
#if defined(CATCH_CPP11_OR_GREATER) #if defined(CATCH_CPP11_OR_GREATER)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat"
#endif
// Enum class without user-provided stream operator // Enum class without user-provided stream operator
enum class EnumClass1 { EnumClass1Value0, EnumClass1Value1 }; enum class EnumClass1 { EnumClass1Value0, EnumClass1Value1 };
TEST_CASE( "toString(enum class)", "[toString][enum][enumClass]" ) TEST_CASE( "toString(enum class)", "[toString][enum][enumClass]" ) {
{
EnumClass1 e0 = EnumClass1::EnumClass1Value0; EnumClass1 e0 = EnumClass1::EnumClass1Value0;
CHECK( Catch::toString(e0) == "0" ); CHECK( Catch::toString(e0) == "0" );
EnumClass1 e1 = EnumClass1::EnumClass1Value1; EnumClass1 e1 = EnumClass1::EnumClass1Value1;
@ -47,25 +48,29 @@ TEST_CASE( "toString(enum class)", "[toString][enum][enumClass]" )
// Enum class with user-provided stream operator // Enum class with user-provided stream operator
enum class EnumClass2 : short { EnumClass2Value0, EnumClass2Value1 }; enum class EnumClass2 : short { EnumClass2Value0, EnumClass2Value1 };
inline std::ostream& operator<<( std::ostream& os, EnumClass2 e2 ) inline std::ostream& operator<<( std::ostream& os, EnumClass2 e2 ) {
{ switch( (int)e2 ) {
switch( e2 ) case (int)EnumClass2::EnumClass2Value0:
{ return os << "E2/V0";
case EnumClass2::EnumClass2Value0: case (int)EnumClass2::EnumClass2Value1:
return os << "E2/V0"; return os << "E2/V1";
case EnumClass2::EnumClass2Value1: default:
return os << "E2/V1"; return os << "Unknown enum value " << (int)e2;
} }
return os << "unexpected...";
} }
TEST_CASE( "toString(enum class w/operator<<)", "[toString][enum][enumClass]" ) TEST_CASE( "toString(enum class w/operator<<)", "[toString][enum][enumClass]" ) {
{
EnumClass2 e0 = EnumClass2::EnumClass2Value0; EnumClass2 e0 = EnumClass2::EnumClass2Value0;
CHECK( Catch::toString(e0) == "E2/V0" ); CHECK( Catch::toString(e0) == "E2/V0" );
EnumClass2 e1 = EnumClass2::EnumClass2Value1; EnumClass2 e1 = EnumClass2::EnumClass2Value1;
CHECK( Catch::toString(e1) == "E2/V1" ); CHECK( Catch::toString(e1) == "E2/V1" );
EnumClass2 e3 = static_cast<EnumClass2>(10);
CHECK( Catch::toString(e3) == "Unknown enum value 10" );
} }
#ifdef __clang__
#pragma clang diagnostic pop
#endif #endif
#endif // CATCH_CPP11_OR_GREATER

View File

@ -18,28 +18,24 @@ namespace Catch {
}; };
} }
TEST_CASE( "std::pair<int,std::string> -> toString", "[toString][pair]" ) TEST_CASE( "std::pair<int,std::string> -> toString", "[toString][pair]" ) {
{
std::pair<int,std::string> value( 34, "xyzzy" ); std::pair<int,std::string> value( 34, "xyzzy" );
REQUIRE( Catch::toString( value ) == "{ 34, \"xyzzy\" }" ); REQUIRE( Catch::toString( value ) == "{ 34, \"xyzzy\" }" );
} }
TEST_CASE( "std::pair<int,const std::string> -> toString", "[toString][pair]" ) TEST_CASE( "std::pair<int,const std::string> -> toString", "[toString][pair]" ) {
{
std::pair<int,const std::string> value( 34, "xyzzy" ); std::pair<int,const std::string> value( 34, "xyzzy" );
REQUIRE( Catch::toString(value) == "{ 34, \"xyzzy\" }" ); REQUIRE( Catch::toString(value) == "{ 34, \"xyzzy\" }" );
} }
TEST_CASE( "std::vector<std::pair<std::string,int> > -> toString", "[toString][pair]" ) TEST_CASE( "std::vector<std::pair<std::string,int> > -> toString", "[toString][pair]" ) {
{
std::vector<std::pair<std::string,int> > pr; std::vector<std::pair<std::string,int> > pr;
pr.push_back( std::make_pair("green", 55 ) ); pr.push_back( std::make_pair("green", 55 ) );
REQUIRE( Catch::toString( pr ) == "{ { \"green\", 55 } }" ); REQUIRE( Catch::toString( pr ) == "{ { \"green\", 55 } }" );
} }
// This is pretty contrived - I figure if this works, anything will... // This is pretty contrived - I figure if this works, anything will...
TEST_CASE( "pair<pair<int,const char *,pair<std::string,int> > -> toString", "[toString][pair]" ) TEST_CASE( "pair<pair<int,const char *,pair<std::string,int> > -> toString", "[toString][pair]" ) {
{
typedef std::pair<int,const char *> left_t; typedef std::pair<int,const char *> left_t;
typedef std::pair<std::string,int> right_t; typedef std::pair<std::string,int> right_t;

View File

@ -24,6 +24,11 @@ TEST_CASE( "vector<string> -> toString", "[toString][vector]" )
} }
#if defined(CATCH_CPP11_OR_GREATER) #if defined(CATCH_CPP11_OR_GREATER)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat"
#endif
/* /*
Note: These tests *can* be made to work with C++ < 11, but the Note: These tests *can* be made to work with C++ < 11, but the
allocator is a lot more work... allocator is a lot more work...
@ -34,12 +39,10 @@ namespace {
struct minimal_allocator { struct minimal_allocator {
typedef T value_type; typedef T value_type;
typedef std::size_t size_type; typedef std::size_t size_type;
T *allocate( size_type n ) T *allocate( size_type n ) {
{
return static_cast<T *>( ::operator new( n * sizeof(T) ) ); return static_cast<T *>( ::operator new( n * sizeof(T) ) );
} }
void deallocate( T *p, size_type /*n*/ ) void deallocate( T *p, size_type /*n*/ ) {
{
::operator delete( static_cast<void *>(p) ); ::operator delete( static_cast<void *>(p) );
} }
template<typename U> template<typename U>
@ -49,8 +52,7 @@ namespace {
}; };
} }
TEST_CASE( "vector<int,allocator> -> toString", "[toString][vector,allocator]" ) TEST_CASE( "vector<int,allocator> -> toString", "[toString][vector,allocator]" ) {
{
std::vector<int,minimal_allocator<int> > vv; std::vector<int,minimal_allocator<int> > vv;
REQUIRE( Catch::toString(vv) == "{ }" ); REQUIRE( Catch::toString(vv) == "{ }" );
vv.push_back( 42 ); vv.push_back( 42 );
@ -59,8 +61,7 @@ TEST_CASE( "vector<int,allocator> -> toString", "[toString][vector,allocator]" )
REQUIRE( Catch::toString(vv) == "{ 42, 512 }" ); REQUIRE( Catch::toString(vv) == "{ 42, 512 }" );
} }
TEST_CASE( "vec<vec<string,alloc>> -> toString", "[toString][vector,allocator]" ) TEST_CASE( "vec<vec<string,alloc>> -> toString", "[toString][vector,allocator]" ) {
{
typedef std::vector<std::string,minimal_allocator<std::string> > inner; typedef std::vector<std::string,minimal_allocator<std::string> > inner;
typedef std::vector<inner> vector; typedef std::vector<inner> vector;
vector v; vector v;
@ -69,4 +70,8 @@ TEST_CASE( "vec<vec<string,alloc>> -> toString", "[toString][vector,allocator]"
v.push_back( inner { "world" } ); v.push_back( inner { "world" } );
REQUIRE( Catch::toString(v) == "{ { \"hello\" }, { \"world\" } }" ); REQUIRE( Catch::toString(v) == "{ { \"hello\" }, { \"world\" } }" );
} }
#ifdef __clang__
#pragma clang diagnostic pop
#endif #endif
#endif // CATCH_CPP11_OR_GREATER

View File

@ -31,43 +31,37 @@ namespace Catch {
} }
// Call the overload // Call the overload
TEST_CASE( "toString( has_toString )", "[toString]" ) TEST_CASE( "toString( has_toString )", "[toString]" ) {
{
has_toString item; has_toString item;
REQUIRE( Catch::toString( item ) == "toString( has_toString )" ); REQUIRE( Catch::toString( item ) == "toString( has_toString )" );
} }
// Call the overload // Call the overload
TEST_CASE( "toString( has_maker )", "[toString]" ) TEST_CASE( "toString( has_maker )", "[toString]" ) {
{
has_maker item; has_maker item;
REQUIRE( Catch::toString( item ) == "StringMaker<has_maker>" ); REQUIRE( Catch::toString( item ) == "StringMaker<has_maker>" );
} }
// Call the overload // Call the overload
TEST_CASE( "toString( has_maker_and_toString )", "[toString]" ) TEST_CASE( "toString( has_maker_and_toString )", "[toString]" ) {
{
has_maker_and_toString item; has_maker_and_toString item;
REQUIRE( Catch::toString( item ) == "toString( has_maker_and_toString )" ); REQUIRE( Catch::toString( item ) == "toString( has_maker_and_toString )" );
} }
// Vectors... // Vectors...
TEST_CASE( "toString( vectors<has_toString )", "[toString]" ) TEST_CASE( "toString( vectors<has_toString )", "[toString]" ) {
{
std::vector<has_toString> v(1); std::vector<has_toString> v(1);
// This invokes template<T> toString which actually gives us '{ ? }' // This invokes template<T> toString which actually gives us '{ ? }'
REQUIRE( Catch::toString( v ) == "{ {?} }" ); REQUIRE( Catch::toString( v ) == "{ {?} }" );
} }
TEST_CASE( "toString( vectors<has_maker )", "[toString]" ) TEST_CASE( "toString( vectors<has_maker )", "[toString]" ) {
{
std::vector<has_maker> v(1); std::vector<has_maker> v(1);
REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker> }" ); REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker> }" );
} }
TEST_CASE( "toString( vectors<has_maker_and_toString )", "[toString]" ) TEST_CASE( "toString( vectors<has_maker_and_toString )", "[toString]" ) {
{
std::vector<has_maker_and_toString> v(1); std::vector<has_maker_and_toString> v(1);
// Note: This invokes the template<T> toString -> StringMaker // Note: This invokes the template<T> toString -> StringMaker
REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker_and_toString> }" ); REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker_and_toString> }" );