From 886ef1620a224b1fd3d15001dcae4fc9a5e71c83 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 4 Sep 2014 07:27:09 +0100 Subject: [PATCH] Some minor tidy-up/ style alignment of recent toString merges --- .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 10 ++++- .../Baselines/console.swa4.approved.txt | 10 ++++- .../SelfTest/Baselines/junit.sw.approved.txt | 2 +- .../SelfTest/Baselines/xml.sw.approved.txt | 14 +++++- projects/SelfTest/EnumToString.cpp | 43 +++++++++++-------- projects/SelfTest/ToStringPair.cpp | 12 ++---- projects/SelfTest/ToStringVector.cpp | 21 +++++---- projects/SelfTest/ToStringWhich.cpp | 18 +++----- 9 files changed, 79 insertions(+), 53 deletions(-) diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index d2e42b43..a97b7a3a 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -787,5 +787,5 @@ with expansion: =============================================================================== 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 diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 169f2633..54b7c915 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -75,6 +75,14 @@ PASSED: with expansion: "E2/V1" == "E2/V1" +EnumToString.cpp:: +PASSED: + CHECK( Catch::toString(e3) == "Unknown enum value 10" ) +with expansion: + "Unknown enum value 10" + == + "Unknown enum value 10" + ------------------------------------------------------------------------------- Some simple comparisons between doubles ------------------------------------------------------------------------------- @@ -7676,5 +7684,5 @@ with expansion: =============================================================================== 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 diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt index 276c93ec..c8993019 100644 --- a/projects/SelfTest/Baselines/console.swa4.approved.txt +++ b/projects/SelfTest/Baselines/console.swa4.approved.txt @@ -75,6 +75,14 @@ PASSED: with expansion: "E2/V1" == "E2/V1" +EnumToString.cpp:: +PASSED: + CHECK( Catch::toString(e3) == "Unknown enum value 10" ) +with expansion: + "Unknown enum value 10" + == + "Unknown enum value 10" + ------------------------------------------------------------------------------- Some simple comparisons between doubles ------------------------------------------------------------------------------- @@ -479,5 +487,5 @@ with expansion: =============================================================================== 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 diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 7ce10d72..07984f57 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,5 +1,5 @@ - + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 5c06f6e0..146a9eb3 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -74,6 +74,16 @@ "E2/V1" == "E2/V1" + + + Catch::toString(e3) == "Unknown enum value 10" + + + "Unknown enum value 10" +== +"Unknown enum value 10" + + @@ -7940,7 +7950,7 @@ there" - + - + diff --git a/projects/SelfTest/EnumToString.cpp b/projects/SelfTest/EnumToString.cpp index 40c11ca9..b35721dc 100644 --- a/projects/SelfTest/EnumToString.cpp +++ b/projects/SelfTest/EnumToString.cpp @@ -8,8 +8,7 @@ // Enum without user-provided stream operator enum Enum1 { Enum1Value0, Enum1Value1 }; -TEST_CASE( "toString(enum)", "[toString][enum]" ) -{ +TEST_CASE( "toString(enum)", "[toString][enum]" ) { Enum1 e0 = Enum1Value0; CHECK( Catch::toString(e0) == "0" ); Enum1 e1 = Enum1Value1; @@ -19,13 +18,11 @@ TEST_CASE( "toString(enum)", "[toString][enum]" ) // Enum with user-provided stream operator 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(v) << "}"; } -TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" ) -{ +TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" ) { Enum2 e0 = Enum2Value0; CHECK( Catch::toString(e0) == "E2{0}" ); Enum2 e1 = Enum2Value1; @@ -33,11 +30,15 @@ TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" ) } #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 EnumClass1 { EnumClass1Value0, EnumClass1Value1 }; -TEST_CASE( "toString(enum class)", "[toString][enum][enumClass]" ) -{ +TEST_CASE( "toString(enum class)", "[toString][enum][enumClass]" ) { EnumClass1 e0 = EnumClass1::EnumClass1Value0; CHECK( Catch::toString(e0) == "0" ); 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 EnumClass2 : short { EnumClass2Value0, EnumClass2Value1 }; -inline std::ostream& operator<<( std::ostream& os, EnumClass2 e2 ) -{ - switch( e2 ) - { - case EnumClass2::EnumClass2Value0: - return os << "E2/V0"; - case EnumClass2::EnumClass2Value1: - return os << "E2/V1"; +inline std::ostream& operator<<( std::ostream& os, EnumClass2 e2 ) { + switch( (int)e2 ) { + case (int)EnumClass2::EnumClass2Value0: + return os << "E2/V0"; + case (int)EnumClass2::EnumClass2Value1: + return os << "E2/V1"; + default: + 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; CHECK( Catch::toString(e0) == "E2/V0" ); EnumClass2 e1 = EnumClass2::EnumClass2Value1; CHECK( Catch::toString(e1) == "E2/V1" ); + + EnumClass2 e3 = static_cast(10); + CHECK( Catch::toString(e3) == "Unknown enum value 10" ); } +#ifdef __clang__ +#pragma clang diagnostic pop #endif +#endif // CATCH_CPP11_OR_GREATER diff --git a/projects/SelfTest/ToStringPair.cpp b/projects/SelfTest/ToStringPair.cpp index 2de4a55a..8f510700 100644 --- a/projects/SelfTest/ToStringPair.cpp +++ b/projects/SelfTest/ToStringPair.cpp @@ -18,28 +18,24 @@ namespace Catch { }; } -TEST_CASE( "std::pair -> toString", "[toString][pair]" ) -{ +TEST_CASE( "std::pair -> toString", "[toString][pair]" ) { std::pair value( 34, "xyzzy" ); REQUIRE( Catch::toString( value ) == "{ 34, \"xyzzy\" }" ); } -TEST_CASE( "std::pair -> toString", "[toString][pair]" ) -{ +TEST_CASE( "std::pair -> toString", "[toString][pair]" ) { std::pair value( 34, "xyzzy" ); REQUIRE( Catch::toString(value) == "{ 34, \"xyzzy\" }" ); } -TEST_CASE( "std::vector > -> toString", "[toString][pair]" ) -{ +TEST_CASE( "std::vector > -> toString", "[toString][pair]" ) { std::vector > pr; pr.push_back( std::make_pair("green", 55 ) ); REQUIRE( Catch::toString( pr ) == "{ { \"green\", 55 } }" ); } // This is pretty contrived - I figure if this works, anything will... -TEST_CASE( "pair > -> toString", "[toString][pair]" ) -{ +TEST_CASE( "pair > -> toString", "[toString][pair]" ) { typedef std::pair left_t; typedef std::pair right_t; diff --git a/projects/SelfTest/ToStringVector.cpp b/projects/SelfTest/ToStringVector.cpp index f3b036e5..44790605 100644 --- a/projects/SelfTest/ToStringVector.cpp +++ b/projects/SelfTest/ToStringVector.cpp @@ -24,6 +24,11 @@ TEST_CASE( "vector -> toString", "[toString][vector]" ) } #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 allocator is a lot more work... @@ -34,12 +39,10 @@ namespace { struct minimal_allocator { typedef T value_type; typedef std::size_t size_type; - T *allocate( size_type n ) - { + T *allocate( size_type n ) { return static_cast( ::operator new( n * sizeof(T) ) ); } - void deallocate( T *p, size_type /*n*/ ) - { + void deallocate( T *p, size_type /*n*/ ) { ::operator delete( static_cast(p) ); } template @@ -49,8 +52,7 @@ namespace { }; } -TEST_CASE( "vector -> toString", "[toString][vector,allocator]" ) -{ +TEST_CASE( "vector -> toString", "[toString][vector,allocator]" ) { std::vector > vv; REQUIRE( Catch::toString(vv) == "{ }" ); vv.push_back( 42 ); @@ -59,8 +61,7 @@ TEST_CASE( "vector -> toString", "[toString][vector,allocator]" ) REQUIRE( Catch::toString(vv) == "{ 42, 512 }" ); } -TEST_CASE( "vec> -> toString", "[toString][vector,allocator]" ) -{ +TEST_CASE( "vec> -> toString", "[toString][vector,allocator]" ) { typedef std::vector > inner; typedef std::vector vector; vector v; @@ -69,4 +70,8 @@ TEST_CASE( "vec> -> toString", "[toString][vector,allocator]" v.push_back( inner { "world" } ); REQUIRE( Catch::toString(v) == "{ { \"hello\" }, { \"world\" } }" ); } + +#ifdef __clang__ +#pragma clang diagnostic pop #endif +#endif // CATCH_CPP11_OR_GREATER diff --git a/projects/SelfTest/ToStringWhich.cpp b/projects/SelfTest/ToStringWhich.cpp index 785c65b7..1d4aa892 100644 --- a/projects/SelfTest/ToStringWhich.cpp +++ b/projects/SelfTest/ToStringWhich.cpp @@ -31,43 +31,37 @@ namespace Catch { } // Call the overload -TEST_CASE( "toString( has_toString )", "[toString]" ) -{ +TEST_CASE( "toString( has_toString )", "[toString]" ) { has_toString item; REQUIRE( Catch::toString( item ) == "toString( has_toString )" ); } // Call the overload -TEST_CASE( "toString( has_maker )", "[toString]" ) -{ +TEST_CASE( "toString( has_maker )", "[toString]" ) { has_maker item; REQUIRE( Catch::toString( item ) == "StringMaker" ); } // Call the overload -TEST_CASE( "toString( has_maker_and_toString )", "[toString]" ) -{ +TEST_CASE( "toString( has_maker_and_toString )", "[toString]" ) { has_maker_and_toString item; REQUIRE( Catch::toString( item ) == "toString( has_maker_and_toString )" ); } // Vectors... -TEST_CASE( "toString( vectors v(1); // This invokes template toString which actually gives us '{ ? }' REQUIRE( Catch::toString( v ) == "{ {?} }" ); } -TEST_CASE( "toString( vectors v(1); REQUIRE( Catch::toString( v ) == "{ StringMaker }" ); } -TEST_CASE( "toString( vectors v(1); // Note: This invokes the template toString -> StringMaker REQUIRE( Catch::toString( v ) == "{ StringMaker }" );