- non-SFINAE IsStreamInsertable
This commit is contained in:
Phil Nash 2013-04-20 23:20:05 +01:00
parent 9fff9e47d3
commit dd52044374
4 changed files with 84 additions and 60 deletions

View File

@ -1,6 +1,6 @@
![catch logo](https://raw.github.com/philsquared/Catch/Integration/catch-logo-small.png) ![catch logo](https://raw.github.com/philsquared/Catch/Integration/catch-logo-small.png)
## CATCH v0.9 build 34 (integration branch) ## CATCH v0.9 build 35 (integration branch)
An automated test framework for C, C++ and Objective-C. An automated test framework for C, C++ and Objective-C.
This branch may contain code that is experimental or not yet fully tested. This branch may contain code that is experimental or not yet fully tested.

View File

@ -13,7 +13,7 @@
namespace Catch { namespace Catch {
// These numbers are maintained by a script // These numbers are maintained by a script
Version libraryVersion( 0, 9, 34, "integration" ); Version libraryVersion( 0, 9, 35, "integration" );
} }
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED

View File

@ -1,6 +1,6 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CatchSelfTest is a CATCH v0.9 b34 (integration) host application. CatchSelfTest is a CATCH v0.9 b35 (integration) host application.
Run with -? for options Run with -? for options
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -5263,6 +5263,18 @@ PASSED:
with expansion: with expansion:
true true
-------------------------------------------------------------------------------
non streamable - with conv. op
-------------------------------------------------------------------------------
TrickyTests.cpp:345
...............................................................................
TrickyTests.cpp:349:
PASSED:
REQUIRE( s == "7" )
with expansion:
"7" == "7"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Anonymous test case 1 Anonymous test case 1
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -5519,11 +5531,11 @@ with message:
boo! boo!
=============================================================================== ===============================================================================
111 test cases - 49 failed (705 assertions - 106 failed) 112 test cases - 49 failed (706 assertions - 106 failed)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CatchSelfTest is a CATCH v0.9 b34 (integration) host application. CatchSelfTest is a CATCH v0.9 b35 (integration) host application.
Run with -? for options Run with -? for options
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -5840,7 +5852,7 @@ with expansion:
13 test cases - 3 failed (40 assertions - 4 failed) 13 test cases - 3 failed (40 assertions - 4 failed)
<testsuites> <testsuites>
<testsuite name="~dummy" errors="10" failures="78" tests="705" hostname="tbd" time="tbd" timestamp="tbd"> <testsuite name="~dummy" errors="10" failures="78" tests="706" hostname="tbd" time="tbd" timestamp="tbd">
<testcase classname="global" name="./succeeding/Approx/simple" time="tbd"/> <testcase classname="global" name="./succeeding/Approx/simple" time="tbd"/>
<testcase classname="global" name="./succeeding/Approx/epsilon" time="tbd"/> <testcase classname="global" name="./succeeding/Approx/epsilon" time="tbd"/>
<testcase classname="global" name="./succeeding/Approx/float" time="tbd"/> <testcase classname="global" name="./succeeding/Approx/float" time="tbd"/>
@ -6339,6 +6351,7 @@ TrickyTests.cpp:106
<testcase classname="global" name="./succeeding/unimplemented static bool" time="tbd"/> <testcase classname="global" name="./succeeding/unimplemented static bool" time="tbd"/>
<testcase classname="global" name="./succeeding/SafeBool" time="tbd"/> <testcase classname="global" name="./succeeding/SafeBool" time="tbd"/>
<testcase classname="global" name="Assertions then sections" time="tbd"/> <testcase classname="global" name="Assertions then sections" time="tbd"/>
<testcase classname="global" name="non streamable - with conv. op" time="tbd"/>
<testcase classname="global" name="Anonymous test case 1" time="tbd"/> <testcase classname="global" name="Anonymous test case 1" time="tbd"/>
<testcase classname="global" name="Test case with one argument" time="tbd"/> <testcase classname="global" name="Test case with one argument" time="tbd"/>
<testcase classname="global" name="Variadic macros" time="tbd"/> <testcase classname="global" name="Variadic macros" time="tbd"/>
@ -12023,6 +12036,17 @@ TrickyTests.cpp" line="335">
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="non streamable - with conv. op">
TrickyTests.cpp" line="349">
<Original>
s == &quot;7&quot;
</Original>
<Expanded>
&quot;7&quot; == &quot;7&quot;
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Anonymous test case 1"> <TestCase name="Anonymous test case 1">
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
@ -12252,9 +12276,9 @@ BDDTests.cpp" line="54">
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="599" failures="106"/> <OverallResults successes="600" failures="106"/>
</Group> </Group>
<OverallResults successes="599" failures="106"/> <OverallResults successes="600" failures="106"/>
</Catch> </Catch>
[Started testing: CatchSelfTest] [Started testing: CatchSelfTest]
[Started group: '~dummy'] [Started group: '~dummy']
@ -13980,6 +14004,10 @@ TrickyTests.cpp:335: Catch::isTrue( true ) succeeded for: true
[Finished: 'Assertions then sections' All tests passed (6 assertions in 1 test case)] [Finished: 'Assertions then sections' All tests passed (6 assertions in 1 test case)]
[Running: non streamable - with conv. op]
TrickyTests.cpp:349: s == "7" succeeded for: "7" == "7"
[Finished: 'non streamable - with conv. op' All tests passed (1 assertion in 1 test case)]
[Running: Anonymous test case 1] [Running: Anonymous test case 1]
VariadicMacrosTests.cpp:14: succeeded VariadicMacrosTests.cpp:14: succeeded
[with message: anonymous test case] [with message: anonymous test case]
@ -14091,10 +14119,10 @@ BDDTests.cpp:67: succeeded
[End of section: ' Given: A section name that is so long that it cannot fit in a single console width' 1 assertion passed] [End of section: ' Given: A section name that is so long that it cannot fit in a single console width' 1 assertion passed]
[Finished: 'Scenario: This is a really long scenario name to see how the list command deals with wrapping' All tests passed (1 assertion in 1 test case)] [Finished: 'Scenario: This is a really long scenario name to see how the list command deals with wrapping' All tests passed (1 assertion in 1 test case)]
[End of group: '~dummy'. 49 of 111 test cases failed (106 of 705 assertions failed)] [End of group: '~dummy'. 49 of 112 test cases failed (106 of 706 assertions failed)]
[Testing completed. 49 of 111 test cases failed (106 of 705 assertions failed)] [Testing completed. 49 of 112 test cases failed (106 of 706 assertions failed)]
[Started testing: CatchSelfTest] [Started testing: CatchSelfTest]
[Started group: '~dummy'] [Started group: '~dummy']

View File

@ -1,6 +1,6 @@
/* /*
* CATCH v0.9 build 34 (integration branch) * CATCH v0.9 build 35 (integration branch)
* Generated: 2013-04-20 21:05:02.595019 * Generated: 2013-04-20 23:19:15.811241
* ---------------------------------------------------------- * ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly * This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@ -555,7 +555,7 @@ private:
#elif __GNUC__ >= 3 #elif __GNUC__ >= 3
#define CATCH_SFINAE // #define CATCH_SFINAE // Taking this out completely for now
#endif // __GNUC__ < 3 #endif // __GNUC__ < 3
@ -572,8 +572,6 @@ private:
#endif // _MSC_VER #endif // _MSC_VER
#ifdef CATCH_SFINAE
namespace Catch { namespace Catch {
struct TrueType { struct TrueType {
@ -587,6 +585,8 @@ namespace Catch {
char sizer[2]; char sizer[2];
}; };
#ifdef CATCH_SFINAE
template<bool> struct NotABooleanExpression; template<bool> struct NotABooleanExpression;
template<bool c> struct If : NotABooleanExpression<c> {}; template<bool c> struct If : NotABooleanExpression<c> {};
@ -597,10 +597,10 @@ namespace Catch {
template<> struct SizedIf<sizeof(TrueType)> : TrueType {}; template<> struct SizedIf<sizeof(TrueType)> : TrueType {};
template<> struct SizedIf<sizeof(FalseType)> : FalseType {}; template<> struct SizedIf<sizeof(FalseType)> : FalseType {};
} // end namespace Catch
#endif // CATCH_SFINAE #endif // CATCH_SFINAE
} // end namespace Catch
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <limits> #include <limits>
@ -652,11 +652,13 @@ inline id performOptionalSelector( id obj, SEL sel ) {
#endif #endif
namespace Catch { namespace Catch {
#ifdef CATCH_SFINAE
namespace Detail { namespace Detail {
// SFINAE is currently disabled by default for all compilers.
// If the non SFINAE version of IsStreamInsertable is ambiguous for you
// and your compiler supports SFINAE, try #defining CATCH_SFINAE
#ifdef CATCH_SFINAE
template<typename T> template<typename T>
class IsStreamInsertableHelper { class IsStreamInsertableHelper {
template<int N> struct TrueIfSizeable : TrueType {}; template<int N> struct TrueIfSizeable : TrueType {};
@ -672,53 +674,47 @@ namespace Detail {
template<typename T> template<typename T>
struct IsStreamInsertable : IsStreamInsertableHelper<T>::type {}; struct IsStreamInsertable : IsStreamInsertableHelper<T>::type {};
template<typename T>
void toStream( std::ostream& os, T const& value, typename IsStreamInsertable<T>::Enable* = 0 ) {
os << value;
}
template<typename T>
void toStream( std::ostream& os, T const&, typename IsStreamInsertable<T>::Disable* = 0 ) {
os << "{?}";
}
}
template<typename T>
struct StringMaker {
static std::string convert( T const& value ) {
std::ostringstream oss;
Detail::toStream( oss, value );
return oss.str();
}
};
#else #else
namespace Detail { struct BorgType {
template<typename T> BorgType( T const& );
};
struct NonStreamable { TrueType& testStreamable( std::ostream& );
template<typename T> NonStreamable( const T& ){} FalseType testStreamable( FalseType );
FalseType operator<<( std::ostream const&, BorgType const& );
template<typename T>
struct IsStreamInsertable {
static std::ostream &s;
static T const &t;
enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) };
};
#endif
template<bool C>
struct StringMakerBase {
template<typename T>
static std::string convert( T const& ) { return "{?}"; }
};
template<>
struct StringMakerBase<true> {
template<typename T>
static std::string convert( T const& _value ) {
std::ostringstream oss;
oss << _value;
return oss.str();
}
}; };
} // end namespace Detail } // end namespace Detail
// If the type does not have its own << overload for ostream then
// this one will be used instead
inline std::ostream& operator << ( std::ostream& ss, Detail::NonStreamable ){
return ss << "{?}";
}
template<typename T> template<typename T>
struct StringMaker { struct StringMaker :
static std::string convert( T const& value ) { Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {};
std::ostringstream oss;
oss << value;
return oss.str();
}
};
#endif
template<typename T> template<typename T>
struct StringMaker<T*> { struct StringMaker<T*> {
@ -6159,7 +6155,7 @@ namespace Catch {
namespace Catch { namespace Catch {
// These numbers are maintained by a script // These numbers are maintained by a script
Version libraryVersion( 0, 9, 34, "integration" ); Version libraryVersion( 0, 9, 35, "integration" );
} }
// #included from: catch_text.hpp // #included from: catch_text.hpp