From 440a47011fc5052d15f82a82f8704fc5320f67f7 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Sat, 4 Jan 2014 19:12:05 +0000 Subject: [PATCH 1/5] Convert pointers to integrates when printing. - handles function pointers that way too (otherwise printed as 1 by gcc and clang) --- include/internal/catch_tostring.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp index cec4cfed..ae78e1f9 100644 --- a/include/internal/catch_tostring.hpp +++ b/include/internal/catch_tostring.hpp @@ -95,7 +95,7 @@ struct StringMaker { if( !p ) return INTERNAL_CATCH_STRINGIFY( NULL ); std::ostringstream oss; - oss << p; + oss << "0x" << std::hex << reinterpret_cast( p ); return oss.str(); } }; From e091018514bc7d63e672b360aff0df1340f5ce13 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 7 Jan 2014 17:25:27 +0000 Subject: [PATCH 2/5] Fixes toString() for function pointers and added support for member function pointers. - thanks to Malcolm Noyes for supplying sample code on which the solution here was based --- include/internal/catch_tostring.hpp | 34 +++++++++++++++++-- .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 18 ++++++++-- .../SelfTest/Baselines/junit.sw.approved.txt | 3 +- .../SelfTest/Baselines/xml.sw.approved.txt | 19 +++++++++-- projects/SelfTest/TrickyTests.cpp | 14 ++++++++ .../CatchSelfTest.xcodeproj/project.pbxproj | 4 +-- 7 files changed, 82 insertions(+), 12 deletions(-) diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp index ae78e1f9..b463e4ff 100644 --- a/include/internal/catch_tostring.hpp +++ b/include/internal/catch_tostring.hpp @@ -79,6 +79,25 @@ namespace Detail { } }; + // For display purposes only. + // Does not consider endian-ness + template + std::string rawMemoryToString( T value ) { + union + { + T value; + unsigned char bytes[sizeof(T)]; + } valueAsBuffer; + + valueAsBuffer.value = value; + + std::ostringstream oss; + oss << "0x"; + for( unsigned char* cp = valueAsBuffer.bytes; cp < valueAsBuffer.bytes+sizeof(T); ++cp ) + oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)*cp; + return oss.str(); + } + } // end namespace Detail template @@ -94,9 +113,18 @@ struct StringMaker { static std::string convert( U* p ) { if( !p ) return INTERNAL_CATCH_STRINGIFY( NULL ); - std::ostringstream oss; - oss << "0x" << std::hex << reinterpret_cast( p ); - return oss.str(); + else + return Detail::rawMemoryToString( p ); + } +}; + +template +struct StringMaker { + static std::string convert( R C::* p ) { + if( !p ) + return INTERNAL_CATCH_STRINGIFY( NULL ); + else + return Detail::rawMemoryToString( p ); } }; diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 52b4db55..3bf4d6c2 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -750,5 +750,5 @@ with expansion: "first" == "second" =============================================================================== -122 test cases - 36 failed (675 assertions - 91 failed) +123 test cases - 36 failed (676 assertions - 91 failed) diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 81ee03db..64ed0577 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -6366,7 +6366,21 @@ TrickyTests.cpp:: PASSED: REQUIRE( a == &foo ) with expansion: - 1 == 1 + 0x == 0x + +------------------------------------------------------------------------------- +Comparing member function pointers +------------------------------------------------------------------------------- +TrickyTests.cpp: +............................................................................... + +TrickyTests.cpp:: +PASSED: + CHECK( m == &S::f ) +with expansion: + 0x + == + 0x ------------------------------------------------------------------------------- pointer to class @@ -7144,5 +7158,5 @@ with expansion: true =============================================================================== -122 test cases - 51 failed (694 assertions - 110 failed) +123 test cases - 51 failed (695 assertions - 110 failed) diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index e28449ca..58a1d151 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,5 +1,5 @@ - + @@ -514,6 +514,7 @@ TrickyTests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 9bebc628..efbb16d3 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -6637,7 +6637,20 @@ there" a == &foo - 1 == 1 + 0x == 0x + + + + + + + + m == &S::f + + + 0x +== +0x @@ -7405,7 +7418,7 @@ there" - + - + diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index 624ba264..f8af61c2 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -356,6 +356,20 @@ TEST_CASE( "Comparing function pointers", "[Tricky][function pointer]" ) REQUIRE( a == &foo ); } +struct S +{ + void f() {} +}; + + +TEST_CASE( "Comparing member function pointers", "[Tricky][member function pointer]" ) +{ + typedef void (S::*MF)(); + MF m = &S::f; + + CHECK( m == &S::f ); +} + class ClassName {}; TEST_CASE( "pointer to class", "[Tricky]" ) diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index e8848237..e61b82de 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -581,7 +581,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = ""; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; USER_HEADER_SEARCH_PATHS = "\"$(PROJECT_DIR)/../../../include\""; @@ -624,7 +624,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = ""; SDKROOT = macosx; USER_HEADER_SEARCH_PATHS = "\"$(PROJECT_DIR)/../../../include\""; }; From be890d0c154099f83715e49f1ff331d097b56bde Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 7 Jan 2014 17:26:59 +0000 Subject: [PATCH 3/5] build 24 --- README.md | 2 +- include/internal/catch_version.hpp | 2 +- single_include/catch.hpp | 40 +++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index dba8e0c2..42767531 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![catch logo](catch-logo-small.png) -*v1.0 build 23 (master branch)* +*v1.0 build 24 (master branch)* Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) diff --git a/include/internal/catch_version.hpp b/include/internal/catch_version.hpp index f615b3ea..67390ce8 100644 --- a/include/internal/catch_version.hpp +++ b/include/internal/catch_version.hpp @@ -13,7 +13,7 @@ namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 23, "master" ); + Version libraryVersion( 1, 0, 24, "master" ); } #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 770b3537..031479b0 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* - * CATCH v1.0 build 23 (master branch) - * Generated: 2013-12-23 10:22:45.547645 + * CATCH v1.0 build 24 (master branch) + * Generated: 2014-01-07 17:26:42.421599 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -681,6 +681,25 @@ namespace Detail { } }; + // For display purposes only. + // Does not consider endian-ness + template + std::string rawMemoryToString( T value ) { + union + { + T value; + unsigned char bytes[sizeof(T)]; + } valueAsBuffer; + + valueAsBuffer.value = value; + + std::ostringstream oss; + oss << "0x"; + for( unsigned char* cp = valueAsBuffer.bytes; cp < valueAsBuffer.bytes+sizeof(T); ++cp ) + oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)*cp; + return oss.str(); + } + } // end namespace Detail template @@ -696,9 +715,18 @@ struct StringMaker { static std::string convert( U* p ) { if( !p ) return INTERNAL_CATCH_STRINGIFY( NULL ); - std::ostringstream oss; - oss << p; - return oss.str(); + else + return Detail::rawMemoryToString( p ); + } +}; + +template +struct StringMaker { + static std::string convert( R C::* p ) { + if( !p ) + return INTERNAL_CATCH_STRINGIFY( NULL ); + else + return Detail::rawMemoryToString( p ); } }; @@ -6179,7 +6207,7 @@ namespace Catch { namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 23, "master" ); + Version libraryVersion( 1, 0, 24, "master" ); } // #included from: catch_text.hpp From 46a1fc76159df9e19ead8bac6299fafceab65a13 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 7 Jan 2014 17:43:18 +0000 Subject: [PATCH 4/5] Removed unnecessary union name --- include/internal/catch_tostring.hpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp index b463e4ff..c081e944 100644 --- a/include/internal/catch_tostring.hpp +++ b/include/internal/catch_tostring.hpp @@ -83,17 +83,16 @@ namespace Detail { // Does not consider endian-ness template std::string rawMemoryToString( T value ) { - union - { - T value; + union { + T typedValue; unsigned char bytes[sizeof(T)]; - } valueAsBuffer; + }; - valueAsBuffer.value = value; + typedValue = value; std::ostringstream oss; oss << "0x"; - for( unsigned char* cp = valueAsBuffer.bytes; cp < valueAsBuffer.bytes+sizeof(T); ++cp ) + for( unsigned char* cp = bytes; cp < bytes+sizeof(T); ++cp ) oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)*cp; return oss.str(); } From 7eb5acc18357056bd3b0a94cb09f620e448cfbc7 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Wed, 8 Jan 2014 17:17:31 +0000 Subject: [PATCH 5/5] build 25 - fix for #231 --- README.md | 2 +- include/internal/catch_debugger.hpp | 7 ++++--- include/internal/catch_version.hpp | 2 +- single_include/catch.hpp | 24 ++++++++++++------------ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 42767531..14a391d0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![catch logo](catch-logo-small.png) -*v1.0 build 24 (master branch)* +*v1.0 build 25 (master branch)* Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) diff --git a/include/internal/catch_debugger.hpp b/include/internal/catch_debugger.hpp index f3ad100f..49c485ff 100644 --- a/include/internal/catch_debugger.hpp +++ b/include/internal/catch_debugger.hpp @@ -30,7 +30,6 @@ // running under the debugger or has a debugger attached post facto). bool isDebuggerActive(){ - int junk; int mib[4]; struct kinfo_proc info; size_t size; @@ -51,8 +50,10 @@ // Call sysctl. size = sizeof(info); - junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0); - assert(junk == 0); + if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0) != 0 ) { + std::cerr << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; + return false; + } // We're being debugged if the P_TRACED flag is set. diff --git a/include/internal/catch_version.hpp b/include/internal/catch_version.hpp index 67390ce8..2fcf72d1 100644 --- a/include/internal/catch_version.hpp +++ b/include/internal/catch_version.hpp @@ -13,7 +13,7 @@ namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 24, "master" ); + Version libraryVersion( 1, 0, 25, "master" ); } #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 031479b0..746e9f4e 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* - * CATCH v1.0 build 24 (master branch) - * Generated: 2014-01-07 17:26:42.421599 + * CATCH v1.0 build 25 (master branch) + * Generated: 2014-01-08 17:16:38.496390 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -685,17 +685,16 @@ namespace Detail { // Does not consider endian-ness template std::string rawMemoryToString( T value ) { - union - { - T value; + union { + T typedValue; unsigned char bytes[sizeof(T)]; - } valueAsBuffer; + }; - valueAsBuffer.value = value; + typedValue = value; std::ostringstream oss; oss << "0x"; - for( unsigned char* cp = valueAsBuffer.bytes; cp < valueAsBuffer.bytes+sizeof(T); ++cp ) + for( unsigned char* cp = bytes; cp < bytes+sizeof(T); ++cp ) oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)*cp; return oss.str(); } @@ -6207,7 +6206,7 @@ namespace Catch { namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 24, "master" ); + Version libraryVersion( 1, 0, 25, "master" ); } // #included from: catch_text.hpp @@ -6626,7 +6625,6 @@ namespace Catch { // running under the debugger or has a debugger attached post facto). bool isDebuggerActive(){ - int junk; int mib[4]; struct kinfo_proc info; size_t size; @@ -6647,8 +6645,10 @@ namespace Catch { // Call sysctl. size = sizeof(info); - junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0); - assert(junk == 0); + if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0) != 0 ) { + std::cerr << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; + return false; + } // We're being debugged if the P_TRACED flag is set.