From af3f2499bcc89d25f4f9eed4c747366f9ef49ec1 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 4 Jan 2018 09:30:06 +0000 Subject: [PATCH 1/6] Added generic container detection in StringMaker. Removed vector specialisation as this is now covered generically - as are any containers that can be called via (freestanding) begin/ end --- include/internal/catch_tostring.h | 33 ++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 79e02448..92161709 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -60,7 +60,7 @@ namespace Catch { } // namespace Detail // If we decide for C++14, change these to enable_if_ts - template + template struct StringMaker { template static @@ -233,12 +233,6 @@ namespace Catch { } } - template - struct StringMaker > { - static std::string convert( std::vector const& v ) { - return ::Catch::Detail::rangeToString( v.begin(), v.end() ); - } - }; template struct EnumStringMaker { @@ -344,6 +338,31 @@ namespace Catch { } #endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER +namespace Catch { + struct not_this_one {}; // Tag type for detecting which begin/ end are being selected + + // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace + using std::begin; + using std::end; + + not_this_one begin( ... ); + not_this_one end( ... ); + + template + struct is_range { + static const bool value = + !std::is_same())), not_this_one>::value && + !std::is_same())), not_this_one>::value; + }; + + template + struct StringMaker::value>::type> { + static std::string convert( R const& range ) { + return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); + } + }; + +} // namespace Catch // Separate std::chrono::duration specialization #if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) From e41e8e8384c415a875309180e9d310a8da9972c4 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 4 Jan 2018 10:03:08 +0000 Subject: [PATCH 2/6] Added tests for stringifying map and set --- .../Baselines/compact.sw.approved.txt | 10 +++ .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 86 ++++++++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 8 +- .../SelfTest/Baselines/xml.sw.approved.txt | 80 ++++++++++++++++- .../UsageTests/ToStringGeneral.tests.cpp | 49 +++++++++++ 6 files changed, 230 insertions(+), 7 deletions(-) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index b205a13f..b2c492cb 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -944,8 +944,18 @@ String.tests.cpp:: passed: Catch::replaceInPlace( s, "'", "|'" ) fo String.tests.cpp:: passed: s == "didn|'t" for: "didn|'t" == "didn|'t" Misc.tests.cpp:: failed: false with 1 message: '3' Message.tests.cpp:: failed: false with 2 messages: 'hi' and 'i := 7' +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( emptyMap ) == "{ }" for: "{ }" == "{ }" +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( map ) == "{ { /"one/", 1 } }" for: "{ { "one", 1 } }" == "{ { "one", 1 } }" +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( map ) == "{ { /"abc/", 1 }, { /"def/", 2 }, { /"ghi/", 3 } }" for: "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }" +== +"{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }" ToStringPair.tests.cpp:: passed: ::Catch::Detail::stringify(value) == "{ 34, /"xyzzy/" }" for: "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }" ToStringPair.tests.cpp:: passed: ::Catch::Detail::stringify( value ) == "{ 34, /"xyzzy/" }" for: "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }" +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( emptySet ) == "{ }" for: "{ }" == "{ }" +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( set ) == "{ /"one/" }" for: "{ "one" }" == "{ "one" }" +ToStringGeneral.tests.cpp:: passed: Catch::Detail::stringify( set ) == "{ /"abc/", /"def/", /"ghi/" }" for: "{ "abc", "def", "ghi" }" +== +"{ "abc", "def", "ghi" }" ToStringPair.tests.cpp:: passed: ::Catch::Detail::stringify( pr ) == "{ { /"green/", 55 } }" for: "{ { "green", 55 } }" == "{ { "green", 55 } }" diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index d8087755..85b6fff3 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1080,6 +1080,6 @@ with expansion: "{?}" == "1" =============================================================================== -test cases: 191 | 139 passed | 48 failed | 4 failed as expected -assertions: 971 | 843 passed | 107 failed | 21 failed as expected +test cases: 193 | 141 passed | 48 failed | 4 failed as expected +assertions: 977 | 849 passed | 107 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index cce06fd3..96fc922e 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -7488,6 +7488,47 @@ with messages: hi i := 7 +------------------------------------------------------------------------------- +std::map is convertible string + empty +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( emptyMap ) == "{ }" ) +with expansion: + "{ }" == "{ }" + +------------------------------------------------------------------------------- +std::map is convertible string + single item +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" ) +with expansion: + "{ { "one", 1 } }" == "{ { "one", 1 } }" + +------------------------------------------------------------------------------- +std::map is convertible string + several items +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }" ) +with expansion: + "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }" + == + "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }" + ------------------------------------------------------------------------------- std::pair -> toString ------------------------------------------------------------------------------- @@ -7512,6 +7553,47 @@ PASSED: with expansion: "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }" +------------------------------------------------------------------------------- +std::set is convertible string + empty +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( emptySet ) == "{ }" ) +with expansion: + "{ }" == "{ }" + +------------------------------------------------------------------------------- +std::set is convertible string + single item +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( set ) == "{ \"one\" }" ) +with expansion: + "{ "one" }" == "{ "one" }" + +------------------------------------------------------------------------------- +std::set is convertible string + several items +------------------------------------------------------------------------------- +ToStringGeneral.tests.cpp: +............................................................................... + +ToStringGeneral.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" ) +with expansion: + "{ "abc", "def", "ghi" }" + == + "{ "abc", "def", "ghi" }" + ------------------------------------------------------------------------------- std::vector > -> toString ------------------------------------------------------------------------------- @@ -8114,6 +8196,6 @@ Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 191 | 137 passed | 50 failed | 4 failed as expected -assertions: 970 | 839 passed | 110 failed | 21 failed as expected +test cases: 193 | 139 passed | 50 failed | 4 failed as expected +assertions: 976 | 845 passed | 110 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 6b09d917..435a40f0 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -799,8 +799,14 @@ i := 7 Message.tests.cpp: + + + + + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index dcc9f894..b39b1b00 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -8429,6 +8429,44 @@ loose text artifact + +
+ + + Catch::Detail::stringify( emptyMap ) == "{ }" + + + "{ }" == "{ }" + + + +
+
+ + + Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" + + + "{ { "one", 1 } }" == "{ { "one", 1 } }" + + + +
+
+ + + Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }" + + + "{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }" +== +"{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }" + + + +
+ +
@@ -8451,6 +8489,44 @@ loose text artifact + +
+ + + Catch::Detail::stringify( emptySet ) == "{ }" + + + "{ }" == "{ }" + + + +
+
+ + + Catch::Detail::stringify( set ) == "{ \"one\" }" + + + "{ "one" }" == "{ "one" }" + + + +
+
+ + + Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" + + + "{ "abc", "def", "ghi" }" +== +"{ "abc", "def", "ghi" }" + + + +
+ +
@@ -9038,7 +9114,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp index 743882b1..3c5a3d94 100644 --- a/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp +++ b/projects/SelfTest/UsageTests/ToStringGeneral.tests.cpp @@ -5,8 +5,11 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ +#define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER #include "catch.hpp" +#include +#include TEST_CASE( "Character pretty printing" ){ SECTION("Specifically escaped"){ @@ -51,3 +54,49 @@ TEST_CASE( "Capture and info messages" ) { REQUIRE(true); } } + +TEST_CASE( "std::map is convertible string", "[toString]" ) { + + SECTION( "empty" ) { + std::map emptyMap; + + REQUIRE( Catch::Detail::stringify( emptyMap ) == "{ }" ); + } + + SECTION( "single item" ) { + std::map map = { { "one", 1 } }; + + REQUIRE( Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" ); + } + + SECTION( "several items" ) { + std::map map = { + { "abc", 1 }, + { "def", 2 }, + { "ghi", 3 } + }; + + REQUIRE( Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }" ); + } +} + +TEST_CASE( "std::set is convertible string", "[toString]" ) { + + SECTION( "empty" ) { + std::set emptySet; + + REQUIRE( Catch::Detail::stringify( emptySet ) == "{ }" ); + } + + SECTION( "single item" ) { + std::set set = { "one" }; + + REQUIRE( Catch::Detail::stringify( set ) == "{ \"one\" }" ); + } + + SECTION( "several items" ) { + std::set set = { "abc", "def", "ghi" }; + + REQUIRE( Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" ); + } +} From 702cfdaf6e3e79f4485190d7f3b4beb2d12ac854 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 4 Jan 2018 10:05:02 +0000 Subject: [PATCH 3/6] Added special handling for vector when stringifying --- include/internal/catch_tostring.h | 25 +++++++++++++++++-- .../UsageTests/ToStringVector.tests.cpp | 10 ++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 92161709..2e7091ad 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -233,7 +233,6 @@ namespace Catch { } } - template struct EnumStringMaker { static std::string convert(const T& t) { @@ -355,10 +354,32 @@ namespace Catch { !std::is_same())), not_this_one>::value; }; + template + std::string rangeToString( Range const& range ) { + return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); + } + + // Handle vector specially + template + std::string rangeToString( std::vector const& v ) { + ReusableStringStream rss; + rss << "{ "; + bool first = true; + for( bool b : v ) { + if( first ) + first = false; + else + rss << ", "; + rss << ::Catch::Detail::stringify( b ); + } + rss << " }"; + return rss.str(); + } + template struct StringMaker::value>::type> { static std::string convert( R const& range ) { - return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); + return rangeToString( range ); } }; diff --git a/projects/SelfTest/UsageTests/ToStringVector.tests.cpp b/projects/SelfTest/UsageTests/ToStringVector.tests.cpp index df9c55ab..0b993c4e 100644 --- a/projects/SelfTest/UsageTests/ToStringVector.tests.cpp +++ b/projects/SelfTest/UsageTests/ToStringVector.tests.cpp @@ -66,3 +66,13 @@ TEST_CASE( "vec> -> toString", "[toString][vector,allocator]" v.push_back( inner { "world" } ); REQUIRE( ::Catch::Detail::stringify(v) == "{ { \"hello\" }, { \"world\" } }" ); } + +// Based on PR by mat-so: https://github.com/catchorg/Catch2/pull/606/files#diff-43562f40f8c6dcfe2c54557316e0f852 +TEST_CASE( "vector -> toString", "[toString][containers][vector]" ) { + std::vector bools; + REQUIRE( ::Catch::Detail::stringify(bools) == "{ }"); + bools.push_back(true); + REQUIRE( ::Catch::Detail::stringify(bools) == "{ true }"); + bools.push_back(false); + REQUIRE( ::Catch::Detail::stringify(bools) == "{ true, false }"); +} From 32eb90b9bdaf45bb1d76ca8bc4efaa3aeaf9a134 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 4 Jan 2018 10:21:52 +0000 Subject: [PATCH 4/6] Fix stringifying of unknown enums --- include/internal/catch_tostring.h | 34 +++++++++------ .../Baselines/compact.sw.approved.txt | 9 ++-- .../Baselines/console.std.approved.txt | 20 +-------- .../Baselines/console.sw.approved.txt | 38 +++++++++++++--- .../SelfTest/Baselines/junit.sw.approved.txt | 12 ++---- .../SelfTest/Baselines/xml.sw.approved.txt | 43 +++++++++++++++---- .../UsageTests/EnumToString.tests.cpp | 4 +- 7 files changed, 101 insertions(+), 59 deletions(-) diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 2e7091ad..5ca019fc 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -57,25 +57,38 @@ namespace Catch { static const bool value = decltype(test(0))::value; }; + template + std::string convertUnknownEnumToString( E e ); + + template + typename std::enable_if::value, std::string>::type convertUnstreamable( T const& ) { + return Detail::unprintableString; + }; + template + typename std::enable_if::value, std::string>::type convertUnstreamable( T const& value ) { + return convertUnknownEnumToString( value ); + }; + } // namespace Detail + // If we decide for C++14, change these to enable_if_ts template struct StringMaker { template static typename std::enable_if<::Catch::Detail::IsStreamInsertable::value, std::string>::type - convert(const Fake& t) { + convert(const Fake& value) { ReusableStringStream rss; - rss << t; + rss << value; return rss.str(); } template static typename std::enable_if::value, std::string>::type - convert(const Fake&) { - return Detail::unprintableString; + convert( const Fake& value ) { + return Detail::convertUnstreamable( value ); } }; @@ -88,8 +101,12 @@ namespace Catch { return ::Catch::StringMaker::type>::type>::convert(e); } - } // namespace Detail + template + std::string convertUnknownEnumToString( E e ) { + return ::Catch::Detail::stringify(static_cast::type>(e)); + } + } // namespace Detail // Some predefined specializations @@ -233,13 +250,6 @@ namespace Catch { } } - template - struct EnumStringMaker { - static std::string convert(const T& t) { - return ::Catch::Detail::stringify(static_cast::type>(t)); - } - }; - #ifdef __OBJC__ template<> struct StringMaker { diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index b2c492cb..2c9b0b80 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -987,8 +987,8 @@ EnumToString.tests.cpp:: passed: ::Catch::Detail::stringify(e1) == EnumToString.tests.cpp:: passed: ::Catch::Detail::stringify(e3) == "Unknown enum value 10" for: "Unknown enum value 10" == "Unknown enum value 10" -EnumToString.tests.cpp:: failed: ::Catch::Detail::stringify(e0) == "0" for: "{?}" == "0" -EnumToString.tests.cpp:: failed: ::Catch::Detail::stringify(e1) == "1" for: "{?}" == "1" +EnumToString.tests.cpp:: passed: ::Catch::Detail::stringify(e0) == "0" for: "0" == "0" +EnumToString.tests.cpp:: passed: ::Catch::Detail::stringify(e1) == "1" for: "1" == "1" EnumToString.tests.cpp:: passed: ::Catch::Detail::stringify(e0) == "E2{0}" for: "E2{0}" == "E2{0}" EnumToString.tests.cpp:: passed: ::Catch::Detail::stringify(e1) == "E2{1}" for: "E2{1}" == "E2{1}" EnumToString.tests.cpp:: passed: ::Catch::Detail::stringify(e0) == "0" for: "0" == "0" @@ -1011,6 +1011,9 @@ ToStringVector.tests.cpp:: passed: ::Catch::Detail::stringify(v) == ToStringVector.tests.cpp:: passed: ::Catch::Detail::stringify(v) == "{ { /"hello/" }, { /"world/" } }" for: "{ { "hello" }, { "world" } }" == "{ { "hello" }, { "world" } }" +ToStringVector.tests.cpp:: passed: ::Catch::Detail::stringify(bools) == "{ }" for: "{ }" == "{ }" +ToStringVector.tests.cpp:: passed: ::Catch::Detail::stringify(bools) == "{ true }" for: "{ true }" == "{ true }" +ToStringVector.tests.cpp:: passed: ::Catch::Detail::stringify(bools) == "{ true, false }" for: "{ true, false }" == "{ true, false }" ToStringVector.tests.cpp:: passed: ::Catch::Detail::stringify(vv) == "{ }" for: "{ }" == "{ }" ToStringVector.tests.cpp:: passed: ::Catch::Detail::stringify(vv) == "{ 42 }" for: "{ 42 }" == "{ 42 }" ToStringVector.tests.cpp:: passed: ::Catch::Detail::stringify(vv) == "{ 42, 250 }" for: "{ 42, 250 }" == "{ 42, 250 }" @@ -1041,5 +1044,5 @@ Misc.tests.cpp:: passed: v.size() == 5 for: 5 == 5 Misc.tests.cpp:: passed: v.capacity() >= 5 for: 5 >= 5 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -Failed 50 test cases, failed 110 assertions. +Failed 49 test cases, failed 108 assertions. diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 85b6fff3..9bb8e8c3 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1063,23 +1063,7 @@ Tricky.tests.cpp:: FAILED: with expansion: "first" == "second" -------------------------------------------------------------------------------- -toString(enum class) -------------------------------------------------------------------------------- -EnumToString.tests.cpp: -............................................................................... - -EnumToString.tests.cpp:: FAILED: - CHECK( ::Catch::Detail::stringify(e0) == "0" ) -with expansion: - "{?}" == "0" - -EnumToString.tests.cpp:: FAILED: - CHECK( ::Catch::Detail::stringify(e1) == "1" ) -with expansion: - "{?}" == "1" - =============================================================================== -test cases: 193 | 141 passed | 48 failed | 4 failed as expected -assertions: 977 | 849 passed | 107 failed | 21 failed as expected +test cases: 194 | 143 passed | 47 failed | 4 failed as expected +assertions: 980 | 854 passed | 105 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 96fc922e..a457fa8d 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -7783,15 +7783,17 @@ toString(enum class) EnumToString.tests.cpp: ............................................................................... -EnumToString.tests.cpp:: FAILED: +EnumToString.tests.cpp:: +PASSED: CHECK( ::Catch::Detail::stringify(e0) == "0" ) with expansion: - "{?}" == "0" + "0" == "0" -EnumToString.tests.cpp:: FAILED: +EnumToString.tests.cpp:: +PASSED: CHECK( ::Catch::Detail::stringify(e1) == "1" ) with expansion: - "{?}" == "1" + "1" == "1" ------------------------------------------------------------------------------- toString(enum w/operator<<) @@ -7939,6 +7941,30 @@ with expansion: == "{ { "hello" }, { "world" } }" +------------------------------------------------------------------------------- +vector -> toString +------------------------------------------------------------------------------- +ToStringVector.tests.cpp: +............................................................................... + +ToStringVector.tests.cpp:: +PASSED: + REQUIRE( ::Catch::Detail::stringify(bools) == "{ }" ) +with expansion: + "{ }" == "{ }" + +ToStringVector.tests.cpp:: +PASSED: + REQUIRE( ::Catch::Detail::stringify(bools) == "{ true }" ) +with expansion: + "{ true }" == "{ true }" + +ToStringVector.tests.cpp:: +PASSED: + REQUIRE( ::Catch::Detail::stringify(bools) == "{ true, false }" ) +with expansion: + "{ true, false }" == "{ true, false }" + ------------------------------------------------------------------------------- vector -> toString ------------------------------------------------------------------------------- @@ -8196,6 +8222,6 @@ Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 193 | 139 passed | 50 failed | 4 failed as expected -assertions: 976 | 845 passed | 110 failed | 21 failed as expected +test cases: 194 | 141 passed | 49 failed | 4 failed as expected +assertions: 979 | 850 passed | 108 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 435a40f0..58d76e46 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -824,14 +824,7 @@ Tricky.tests.cpp: - - -EnumToString.tests.cpp: - - -EnumToString.tests.cpp: - - + @@ -841,6 +834,7 @@ EnumToString.tests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index b39b1b00..c3fc5265 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -8702,24 +8702,24 @@ loose text artifact - - + + ::Catch::Detail::stringify(e0) == "0" - "{?}" == "0" + "0" == "0" - + ::Catch::Detail::stringify(e1) == "1" - "{?}" == "1" + "1" == "1" - + @@ -8868,6 +8868,33 @@ loose text artifact + + + + ::Catch::Detail::stringify(bools) == "{ }" + + + "{ }" == "{ }" + + + + + ::Catch::Detail::stringify(bools) == "{ true }" + + + "{ true }" == "{ true }" + + + + + ::Catch::Detail::stringify(bools) == "{ true, false }" + + + "{ true, false }" == "{ true, false }" + + + + @@ -9114,7 +9141,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/UsageTests/EnumToString.tests.cpp b/projects/SelfTest/UsageTests/EnumToString.tests.cpp index be0da03a..7d18a292 100644 --- a/projects/SelfTest/UsageTests/EnumToString.tests.cpp +++ b/projects/SelfTest/UsageTests/EnumToString.tests.cpp @@ -28,9 +28,7 @@ TEST_CASE( "toString(enum w/operator<<)", "[toString][enum]" ) { // Enum class without user-provided stream operator enum class EnumClass1 { EnumClass1Value0, EnumClass1Value1 }; -// This fails, but has been hidden for a while - not sure if it's a regression or if it never worked -// - need to investigate -TEST_CASE( "toString(enum class)", "[toString][enum][enumClass][.]" ) { +TEST_CASE( "toString(enum class)", "[toString][enum][enumClass]" ) { EnumClass1 e0 = EnumClass1::EnumClass1Value0; CHECK( ::Catch::Detail::stringify(e0) == "0" ); EnumClass1 e1 = EnumClass1::EnumClass1Value1; From 8be1df243e18e4a511b413f49f69546bb4607d2c Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 4 Jan 2018 10:52:55 +0000 Subject: [PATCH 5/6] Added test for stringifying std::arrays --- .../Baselines/compact.sw.approved.txt | 3 ++ .../Baselines/console.std.approved.txt | 4 +-- .../Baselines/console.sw.approved.txt | 28 +++++++++++++++-- .../SelfTest/Baselines/junit.sw.approved.txt | 3 +- .../SelfTest/Baselines/xml.sw.approved.txt | 31 +++++++++++++++++-- .../UsageTests/ToStringVector.tests.cpp | 10 +++++- 6 files changed, 71 insertions(+), 8 deletions(-) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 2c9b0b80..e7dafe5a 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -874,6 +874,9 @@ Xml.tests.cpp:: passed: encode( stringWithQuotes, Catch::XmlEncode: "don't "quote" me on that" Xml.tests.cpp:: passed: encode( "[/x01]" ) == "[//x01]" for: "[/x01]" == "[/x01]" Xml.tests.cpp:: passed: encode( "[/x7F]" ) == "[//x7F]" for: "[/x7F]" == "[/x7F]" +ToStringVector.tests.cpp:: passed: Catch::Detail::stringify( empty ) == "{ }" for: "{ }" == "{ }" +ToStringVector.tests.cpp:: passed: Catch::Detail::stringify( oneValue ) == "{ 42 }" for: "{ 42 }" == "{ 42 }" +ToStringVector.tests.cpp:: passed: Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" for: "{ 42, 250 }" == "{ 42, 250 }" Misc.tests.cpp:: passed: x == 0 for: 0 == 0 Tricky.tests.cpp:: passed: obj.prop != 0 for: 0x != 0 Misc.tests.cpp:: passed: flag for: true diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 9bb8e8c3..375fb71a 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1064,6 +1064,6 @@ with expansion: "first" == "second" =============================================================================== -test cases: 194 | 143 passed | 47 failed | 4 failed as expected -assertions: 980 | 854 passed | 105 failed | 21 failed as expected +test cases: 195 | 144 passed | 47 failed | 4 failed as expected +assertions: 983 | 857 passed | 105 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index a457fa8d..57c3ca79 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -6852,6 +6852,30 @@ PASSED: with expansion: "[\x7F]" == "[\x7F]" +------------------------------------------------------------------------------- +array -> toString +------------------------------------------------------------------------------- +ToStringVector.tests.cpp: +............................................................................... + +ToStringVector.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( empty ) == "{ }" ) +with expansion: + "{ }" == "{ }" + +ToStringVector.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( oneValue ) == "{ 42 }" ) +with expansion: + "{ 42 }" == "{ 42 }" + +ToStringVector.tests.cpp:: +PASSED: + REQUIRE( Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" ) +with expansion: + "{ 42, 250 }" == "{ 42, 250 }" + ------------------------------------------------------------------------------- atomic if ------------------------------------------------------------------------------- @@ -8222,6 +8246,6 @@ Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 194 | 141 passed | 49 failed | 4 failed as expected -assertions: 979 | 850 passed | 108 failed | 21 failed as expected +test cases: 195 | 142 passed | 49 failed | 4 failed as expected +assertions: 982 | 853 passed | 108 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 58d76e46..c7d422a8 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -698,6 +698,7 @@ Exception.tests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index c3fc5265..18823424 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -7749,6 +7749,33 @@ Message from section two + + + + Catch::Detail::stringify( empty ) == "{ }" + + + "{ }" == "{ }" + + + + + Catch::Detail::stringify( oneValue ) == "{ 42 }" + + + "{ 42 }" == "{ 42 }" + + + + + Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" + + + "{ 42, 250 }" == "{ 42, 250 }" + + + + @@ -9141,7 +9168,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/UsageTests/ToStringVector.tests.cpp b/projects/SelfTest/UsageTests/ToStringVector.tests.cpp index 0b993c4e..18e56c08 100644 --- a/projects/SelfTest/UsageTests/ToStringVector.tests.cpp +++ b/projects/SelfTest/UsageTests/ToStringVector.tests.cpp @@ -1,6 +1,6 @@ #include "catch.hpp" #include - +#include // vedctor TEST_CASE( "vector -> toString", "[toString][vector]" ) @@ -76,3 +76,11 @@ TEST_CASE( "vector -> toString", "[toString][containers][vector]" ) { bools.push_back(false); REQUIRE( ::Catch::Detail::stringify(bools) == "{ true, false }"); } +TEST_CASE( "array -> toString", "[toString][containers][array]" ) { + std::array empty; + REQUIRE( Catch::Detail::stringify( empty ) == "{ }" ); + std::array oneValue = {{ 42 }}; + REQUIRE( Catch::Detail::stringify( oneValue ) == "{ 42 }" ); + std::array twoValues = {{ 42, 250 }}; + REQUIRE( Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" ); +} \ No newline at end of file From 2c43620d9baed1fdcaa9146af1d3eb90520cbe92 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 5 Jan 2018 14:39:59 +0000 Subject: [PATCH 6/6] Exclude benchmark dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bf296d96..ffce8e91 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ Build .idea .vs cmake-build-* +benchmark-dir