Merge commit '2c43620d9baed1fdcaa9146af1d3eb90520cbe92'

This commit is contained in:
Phil Nash 2018-01-08 11:13:29 +00:00
commit 161dd4ed24
10 changed files with 447 additions and 68 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ Build
.idea
.vs
cmake-build-*
benchmark-dir

View File

@ -57,25 +57,38 @@ namespace Catch {
static const bool value = decltype(test<std::ostream, const T&>(0))::value;
};
template<typename E>
std::string convertUnknownEnumToString( E e );
template<typename T>
typename std::enable_if<!std::is_enum<T>::value, std::string>::type convertUnstreamable( T const& ) {
return Detail::unprintableString;
};
template<typename T>
typename std::enable_if<std::is_enum<T>::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 <typename T>
template <typename T, typename = void>
struct StringMaker {
template <typename Fake = T>
static
typename std::enable_if<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
convert(const Fake& t) {
convert(const Fake& value) {
ReusableStringStream rss;
rss << t;
rss << value;
return rss.str();
}
template <typename Fake = T>
static
typename std::enable_if<!::Catch::Detail::IsStreamInsertable<Fake>::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<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
}
} // namespace Detail
template<typename E>
std::string convertUnknownEnumToString( E e ) {
return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<E>::type>(e));
}
} // namespace Detail
// Some predefined specializations
@ -233,20 +250,6 @@ namespace Catch {
}
}
template<typename T, typename Allocator>
struct StringMaker<std::vector<T, Allocator> > {
static std::string convert( std::vector<T,Allocator> const& v ) {
return ::Catch::Detail::rangeToString( v.begin(), v.end() );
}
};
template<typename T>
struct EnumStringMaker {
static std::string convert(const T& t) {
return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<T>::type>(t));
}
};
#ifdef __OBJC__
template<>
struct StringMaker<NSString*> {
@ -344,6 +347,53 @@ 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 <typename T>
struct is_range {
static const bool value =
!std::is_same<decltype(begin(std::declval<T>())), not_this_one>::value &&
!std::is_same<decltype(end(std::declval<T>())), not_this_one>::value;
};
template<typename Range>
std::string rangeToString( Range const& range ) {
return ::Catch::Detail::rangeToString( begin( range ), end( range ) );
}
// Handle vector<bool> specially
template<typename Allocator>
std::string rangeToString( std::vector<bool, Allocator> 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<typename R>
struct StringMaker<R, typename std::enable_if<is_range<R>::value>::type> {
static std::string convert( R const& range ) {
return rangeToString( range );
}
};
} // namespace Catch
// Separate std::chrono::duration specialization
#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)

View File

@ -874,6 +874,9 @@ Xml.tests.cpp:<line number>: passed: encode( stringWithQuotes, Catch::XmlEncode:
"don't &quot;quote&quot; me on that"
Xml.tests.cpp:<line number>: passed: encode( "[/x01]" ) == "[//x01]" for: "[/x01]" == "[/x01]"
Xml.tests.cpp:<line number>: passed: encode( "[/x7F]" ) == "[//x7F]" for: "[/x7F]" == "[/x7F]"
ToStringVector.tests.cpp:<line number>: passed: Catch::Detail::stringify( empty ) == "{ }" for: "{ }" == "{ }"
ToStringVector.tests.cpp:<line number>: passed: Catch::Detail::stringify( oneValue ) == "{ 42 }" for: "{ 42 }" == "{ 42 }"
ToStringVector.tests.cpp:<line number>: passed: Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" for: "{ 42, 250 }" == "{ 42, 250 }"
Misc.tests.cpp:<line number>: passed: x == 0 for: 0 == 0
Tricky.tests.cpp:<line number>: passed: obj.prop != 0 for: 0x<hex digits> != 0
Misc.tests.cpp:<line number>: passed: flag for: true
@ -944,8 +947,18 @@ String.tests.cpp:<line number>: passed: Catch::replaceInPlace( s, "'", "|'" ) fo
String.tests.cpp:<line number>: passed: s == "didn|'t" for: "didn|'t" == "didn|'t"
Misc.tests.cpp:<line number>: failed: false with 1 message: '3'
Message.tests.cpp:<line number>: failed: false with 2 messages: 'hi' and 'i := 7'
ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( emptyMap ) == "{ }" for: "{ }" == "{ }"
ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( map ) == "{ { /"one/", 1 } }" for: "{ { "one", 1 } }" == "{ { "one", 1 } }"
ToStringGeneral.tests.cpp:<line number>: 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:<line number>: passed: ::Catch::Detail::stringify(value) == "{ 34, /"xyzzy/" }" for: "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }"
ToStringPair.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( value ) == "{ 34, /"xyzzy/" }" for: "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }"
ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( emptySet ) == "{ }" for: "{ }" == "{ }"
ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( set ) == "{ /"one/" }" for: "{ "one" }" == "{ "one" }"
ToStringGeneral.tests.cpp:<line number>: passed: Catch::Detail::stringify( set ) == "{ /"abc/", /"def/", /"ghi/" }" for: "{ "abc", "def", "ghi" }"
==
"{ "abc", "def", "ghi" }"
ToStringPair.tests.cpp:<line number>: passed: ::Catch::Detail::stringify( pr ) == "{ { /"green/", 55 } }" for: "{ { "green", 55 } }"
==
"{ { "green", 55 } }"
@ -977,8 +990,8 @@ EnumToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(e1) ==
EnumToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(e3) == "Unknown enum value 10" for: "Unknown enum value 10"
==
"Unknown enum value 10"
EnumToString.tests.cpp:<line number>: failed: ::Catch::Detail::stringify(e0) == "0" for: "{?}" == "0"
EnumToString.tests.cpp:<line number>: failed: ::Catch::Detail::stringify(e1) == "1" for: "{?}" == "1"
EnumToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(e0) == "0" for: "0" == "0"
EnumToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(e1) == "1" for: "1" == "1"
EnumToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(e0) == "E2{0}" for: "E2{0}" == "E2{0}"
EnumToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(e1) == "E2{1}" for: "E2{1}" == "E2{1}"
EnumToString.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(e0) == "0" for: "0" == "0"
@ -1001,6 +1014,9 @@ ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(v) ==
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(v) == "{ { /"hello/" }, { /"world/" } }" for: "{ { "hello" }, { "world" } }"
==
"{ { "hello" }, { "world" } }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ }" for: "{ }" == "{ }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ true }" for: "{ true }" == "{ true }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(bools) == "{ true, false }" for: "{ true, false }" == "{ true, false }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ }" for: "{ }" == "{ }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ 42 }" for: "{ 42 }" == "{ 42 }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(vv) == "{ 42, 250 }" for: "{ 42, 250 }" == "{ 42, 250 }"
@ -1031,5 +1047,5 @@ Misc.tests.cpp:<line number>: passed: v.size() == 5 for: 5 == 5
Misc.tests.cpp:<line number>: passed: v.capacity() >= 5 for: 5 >= 5
Misc.tests.cpp:<line number>: passed:
Misc.tests.cpp:<line number>: passed:
Failed 50 test cases, failed 110 assertions.
Failed 49 test cases, failed 108 assertions.

View File

@ -1063,23 +1063,7 @@ Tricky.tests.cpp:<line number>: FAILED:
with expansion:
"first" == "second"
-------------------------------------------------------------------------------
toString(enum class)
-------------------------------------------------------------------------------
EnumToString.tests.cpp:<line number>
...............................................................................
EnumToString.tests.cpp:<line number>: FAILED:
CHECK( ::Catch::Detail::stringify(e0) == "0" )
with expansion:
"{?}" == "0"
EnumToString.tests.cpp:<line number>: FAILED:
CHECK( ::Catch::Detail::stringify(e1) == "1" )
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: 195 | 144 passed | 47 failed | 4 failed as expected
assertions: 983 | 857 passed | 105 failed | 21 failed as expected

View File

@ -6852,6 +6852,30 @@ PASSED:
with expansion:
"[\x7F]" == "[\x7F]"
-------------------------------------------------------------------------------
array<int, N> -> toString
-------------------------------------------------------------------------------
ToStringVector.tests.cpp:<line number>
...............................................................................
ToStringVector.tests.cpp:<line number>:
PASSED:
REQUIRE( Catch::Detail::stringify( empty ) == "{ }" )
with expansion:
"{ }" == "{ }"
ToStringVector.tests.cpp:<line number>:
PASSED:
REQUIRE( Catch::Detail::stringify( oneValue ) == "{ 42 }" )
with expansion:
"{ 42 }" == "{ 42 }"
ToStringVector.tests.cpp:<line number>:
PASSED:
REQUIRE( Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" )
with expansion:
"{ 42, 250 }" == "{ 42, 250 }"
-------------------------------------------------------------------------------
atomic if
-------------------------------------------------------------------------------
@ -7488,6 +7512,47 @@ with messages:
hi
i := 7
-------------------------------------------------------------------------------
std::map is convertible string
empty
-------------------------------------------------------------------------------
ToStringGeneral.tests.cpp:<line number>
...............................................................................
ToStringGeneral.tests.cpp:<line number>:
PASSED:
REQUIRE( Catch::Detail::stringify( emptyMap ) == "{ }" )
with expansion:
"{ }" == "{ }"
-------------------------------------------------------------------------------
std::map is convertible string
single item
-------------------------------------------------------------------------------
ToStringGeneral.tests.cpp:<line number>
...............................................................................
ToStringGeneral.tests.cpp:<line number>:
PASSED:
REQUIRE( Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" )
with expansion:
"{ { "one", 1 } }" == "{ { "one", 1 } }"
-------------------------------------------------------------------------------
std::map is convertible string
several items
-------------------------------------------------------------------------------
ToStringGeneral.tests.cpp:<line number>
...............................................................................
ToStringGeneral.tests.cpp:<line number>:
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<int,const std::string> -> toString
-------------------------------------------------------------------------------
@ -7512,6 +7577,47 @@ PASSED:
with expansion:
"{ 34, "xyzzy" }" == "{ 34, "xyzzy" }"
-------------------------------------------------------------------------------
std::set is convertible string
empty
-------------------------------------------------------------------------------
ToStringGeneral.tests.cpp:<line number>
...............................................................................
ToStringGeneral.tests.cpp:<line number>:
PASSED:
REQUIRE( Catch::Detail::stringify( emptySet ) == "{ }" )
with expansion:
"{ }" == "{ }"
-------------------------------------------------------------------------------
std::set is convertible string
single item
-------------------------------------------------------------------------------
ToStringGeneral.tests.cpp:<line number>
...............................................................................
ToStringGeneral.tests.cpp:<line number>:
PASSED:
REQUIRE( Catch::Detail::stringify( set ) == "{ \"one\" }" )
with expansion:
"{ "one" }" == "{ "one" }"
-------------------------------------------------------------------------------
std::set is convertible string
several items
-------------------------------------------------------------------------------
ToStringGeneral.tests.cpp:<line number>
...............................................................................
ToStringGeneral.tests.cpp:<line number>:
PASSED:
REQUIRE( Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" )
with expansion:
"{ "abc", "def", "ghi" }"
==
"{ "abc", "def", "ghi" }"
-------------------------------------------------------------------------------
std::vector<std::pair<std::string,int> > -> toString
-------------------------------------------------------------------------------
@ -7701,15 +7807,17 @@ toString(enum class)
EnumToString.tests.cpp:<line number>
...............................................................................
EnumToString.tests.cpp:<line number>: FAILED:
EnumToString.tests.cpp:<line number>:
PASSED:
CHECK( ::Catch::Detail::stringify(e0) == "0" )
with expansion:
"{?}" == "0"
"0" == "0"
EnumToString.tests.cpp:<line number>: FAILED:
EnumToString.tests.cpp:<line number>:
PASSED:
CHECK( ::Catch::Detail::stringify(e1) == "1" )
with expansion:
"{?}" == "1"
"1" == "1"
-------------------------------------------------------------------------------
toString(enum w/operator<<)
@ -7857,6 +7965,30 @@ with expansion:
==
"{ { "hello" }, { "world" } }"
-------------------------------------------------------------------------------
vector<bool> -> toString
-------------------------------------------------------------------------------
ToStringVector.tests.cpp:<line number>
...............................................................................
ToStringVector.tests.cpp:<line number>:
PASSED:
REQUIRE( ::Catch::Detail::stringify(bools) == "{ }" )
with expansion:
"{ }" == "{ }"
ToStringVector.tests.cpp:<line number>:
PASSED:
REQUIRE( ::Catch::Detail::stringify(bools) == "{ true }" )
with expansion:
"{ true }" == "{ true }"
ToStringVector.tests.cpp:<line number>:
PASSED:
REQUIRE( ::Catch::Detail::stringify(bools) == "{ true, false }" )
with expansion:
"{ true, false }" == "{ true, false }"
-------------------------------------------------------------------------------
vector<int,allocator> -> toString
-------------------------------------------------------------------------------
@ -8114,6 +8246,6 @@ Misc.tests.cpp:<line number>:
PASSED:
===============================================================================
test cases: 191 | 137 passed | 50 failed | 4 failed as expected
assertions: 970 | 839 passed | 110 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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="15" failures="96" tests="971" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="15" failures="94" tests="983" 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="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
@ -698,6 +698,7 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="XmlEncode/string with quotes" time="{duration}"/>
<testcase classname="<exe-name>.global" name="XmlEncode/string with control char (1)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="XmlEncode/string with control char (x7F)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="array&lt;int, N> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="atomic if" time="{duration}"/>
<testcase classname="<exe-name>.global" name="boolean member" time="{duration}"/>
<testcase classname="<exe-name>.global" name="checkedElse" time="{duration}"/>
@ -799,8 +800,14 @@ i := 7
Message.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="std::map is convertible string/empty" time="{duration}"/>
<testcase classname="<exe-name>.global" name="std::map is convertible string/single item" time="{duration}"/>
<testcase classname="<exe-name>.global" name="std::map is convertible string/several items" time="{duration}"/>
<testcase classname="<exe-name>.global" name="std::pair&lt;int,const std::string> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="std::pair&lt;int,std::string> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="std::set is convertible string/empty" time="{duration}"/>
<testcase classname="<exe-name>.global" name="std::set is convertible string/single item" time="{duration}"/>
<testcase classname="<exe-name>.global" name="std::set is convertible string/several items" time="{duration}"/>
<testcase classname="<exe-name>.global" name="std::vector&lt;std::pair&lt;std::string,int> > -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="string literals of different sizes can be compared" time="{duration}">
<failure message="&quot;first&quot; == &quot;second&quot;" type="REQUIRE">
@ -818,14 +825,7 @@ Tricky.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="toString( vectors&lt;has_maker_and_operator> )" time="{duration}"/>
<testcase classname="<exe-name>.global" name="toString( vectors&lt;has_operator> )" time="{duration}"/>
<testcase classname="<exe-name>.global" name="toString(enum class w/operator&lt;&lt;)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="toString(enum class)" time="{duration}">
<failure message="&quot;{?}&quot; == &quot;0&quot;" type="CHECK">
EnumToString.tests.cpp:<line number>
</failure>
<failure message="&quot;{?}&quot; == &quot;1&quot;" type="CHECK">
EnumToString.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="toString(enum class)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="toString(enum w/operator&lt;&lt;)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="toString(enum)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="tuple&lt;>" time="{duration}"/>
@ -835,6 +835,7 @@ EnumToString.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="tuple&lt;string,string>" time="{duration}"/>
<testcase classname="<exe-name>.global" name="tuple&lt;tuple&lt;int>,tuple&lt;>,float>" time="{duration}"/>
<testcase classname="<exe-name>.global" name="vec&lt;vec&lt;string,alloc>> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="vector&lt;bool> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="vector&lt;int,allocator> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="vector&lt;int> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="vector&lt;string> -> toString" time="{duration}"/>

View File

@ -7749,6 +7749,33 @@ Message from section two
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="array&lt;int, N> -> toString" tags="[array][containers][toString]" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
Catch::Detail::stringify( empty ) == "{ }"
</Original>
<Expanded>
"{ }" == "{ }"
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
Catch::Detail::stringify( oneValue ) == "{ 42 }"
</Original>
<Expanded>
"{ 42 }" == "{ 42 }"
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
Catch::Detail::stringify( twoValues ) == "{ 42, 250 }"
</Original>
<Expanded>
"{ 42, 250 }" == "{ 42, 250 }"
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="atomic if" tags="[0][failing]" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
<Original>
@ -8429,6 +8456,44 @@ loose text artifact
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="std::map is convertible string" tags="[toString]" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Section name="empty" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Original>
Catch::Detail::stringify( emptyMap ) == "{ }"
</Original>
<Expanded>
"{ }" == "{ }"
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="single item" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Original>
Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }"
</Original>
<Expanded>
"{ { "one", 1 } }" == "{ { "one", 1 } }"
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="several items" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Original>
Catch::Detail::stringify( map ) == "{ { \"abc\", 1 }, { \"def\", 2 }, { \"ghi\", 3 } }"
</Original>
<Expanded>
"{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }"
==
"{ { "abc", 1 }, { "def", 2 }, { "ghi", 3 } }"
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="std::pair&lt;int,const std::string> -> toString" tags="[pair][toString]" filename="projects/<exe-name>/UsageTests/ToStringPair.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringPair.tests.cpp" >
<Original>
@ -8451,6 +8516,44 @@ loose text artifact
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="std::set is convertible string" tags="[toString]" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Section name="empty" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Original>
Catch::Detail::stringify( emptySet ) == "{ }"
</Original>
<Expanded>
"{ }" == "{ }"
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="single item" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Original>
Catch::Detail::stringify( set ) == "{ \"one\" }"
</Original>
<Expanded>
"{ "one" }" == "{ "one" }"
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="several items" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringGeneral.tests.cpp" >
<Original>
Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }"
</Original>
<Expanded>
"{ "abc", "def", "ghi" }"
==
"{ "abc", "def", "ghi" }"
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="std::vector&lt;std::pair&lt;std::string,int> > -> toString" tags="[pair][toString]" filename="projects/<exe-name>/UsageTests/ToStringPair.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringPair.tests.cpp" >
<Original>
@ -8626,24 +8729,24 @@ loose text artifact
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="toString(enum class)" tags="[.][enum][enumClass][toString]" filename="projects/<exe-name>/UsageTests/EnumToString.tests.cpp" >
<Expression success="false" type="CHECK" filename="projects/<exe-name>/UsageTests/EnumToString.tests.cpp" >
<TestCase name="toString(enum class)" tags="[enum][enumClass][toString]" filename="projects/<exe-name>/UsageTests/EnumToString.tests.cpp" >
<Expression success="true" type="CHECK" filename="projects/<exe-name>/UsageTests/EnumToString.tests.cpp" >
<Original>
::Catch::Detail::stringify(e0) == "0"
</Original>
<Expanded>
"{?}" == "0"
"0" == "0"
</Expanded>
</Expression>
<Expression success="false" type="CHECK" filename="projects/<exe-name>/UsageTests/EnumToString.tests.cpp" >
<Expression success="true" type="CHECK" filename="projects/<exe-name>/UsageTests/EnumToString.tests.cpp" >
<Original>
::Catch::Detail::stringify(e1) == "1"
</Original>
<Expanded>
"{?}" == "1"
"1" == "1"
</Expanded>
</Expression>
<OverallResult success="false"/>
<OverallResult success="true"/>
</TestCase>
<TestCase name="toString(enum w/operator&lt;&lt;)" tags="[enum][toString]" filename="projects/<exe-name>/UsageTests/EnumToString.tests.cpp" >
<Expression success="true" type="CHECK" filename="projects/<exe-name>/UsageTests/EnumToString.tests.cpp" >
@ -8792,6 +8895,33 @@ loose text artifact
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="vector&lt;bool> -> toString" tags="[containers][toString][vector]" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
::Catch::Detail::stringify(bools) == "{ }"
</Original>
<Expanded>
"{ }" == "{ }"
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
::Catch::Detail::stringify(bools) == "{ true }"
</Original>
<Expanded>
"{ true }" == "{ true }"
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
::Catch::Detail::stringify(bools) == "{ true, false }"
</Original>
<Expanded>
"{ true, false }" == "{ true, false }"
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="vector&lt;int,allocator> -> toString" tags="[toString][vector,allocator]" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original>
@ -9038,7 +9168,7 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="839" failures="111" expectedFailures="21"/>
<OverallResults successes="853" failures="109" expectedFailures="21"/>
</Group>
<OverallResults successes="839" failures="110" expectedFailures="21"/>
<OverallResults successes="853" failures="108" expectedFailures="21"/>
</Catch>

View File

@ -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;

View File

@ -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 <map>
#include <set>
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<std::string, int> emptyMap;
REQUIRE( Catch::Detail::stringify( emptyMap ) == "{ }" );
}
SECTION( "single item" ) {
std::map<std::string, int> map = { { "one", 1 } };
REQUIRE( Catch::Detail::stringify( map ) == "{ { \"one\", 1 } }" );
}
SECTION( "several items" ) {
std::map<std::string, int> 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<std::string> emptySet;
REQUIRE( Catch::Detail::stringify( emptySet ) == "{ }" );
}
SECTION( "single item" ) {
std::set<std::string> set = { "one" };
REQUIRE( Catch::Detail::stringify( set ) == "{ \"one\" }" );
}
SECTION( "several items" ) {
std::set<std::string> set = { "abc", "def", "ghi" };
REQUIRE( Catch::Detail::stringify( set ) == "{ \"abc\", \"def\", \"ghi\" }" );
}
}

View File

@ -1,6 +1,6 @@
#include "catch.hpp"
#include <vector>
#include <array>
// vedctor
TEST_CASE( "vector<int> -> toString", "[toString][vector]" )
@ -66,3 +66,21 @@ TEST_CASE( "vec<vec<string,alloc>> -> 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<bool> -> toString", "[toString][containers][vector]" ) {
std::vector<bool> 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 }");
}
TEST_CASE( "array<int, N> -> toString", "[toString][containers][array]" ) {
std::array<int, 0> empty;
REQUIRE( Catch::Detail::stringify( empty ) == "{ }" );
std::array<int, 1> oneValue = {{ 42 }};
REQUIRE( Catch::Detail::stringify( oneValue ) == "{ 42 }" );
std::array<int, 2> twoValues = {{ 42, 250 }};
REQUIRE( Catch::Detail::stringify( twoValues ) == "{ 42, 250 }" );
}