From dd5b9c2ae587cb2a79493af6ffa5045e9cb7c4e4 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Sat, 18 Feb 2012 09:58:30 +0000 Subject: [PATCH] Added clean-up Clean-up statics at the end of main to avoid added noise when looking for leaks --- include/internal/catch_default_main.hpp | 6 ++--- include/internal/catch_hub.h | 6 +++++ include/internal/catch_hub_impl.hpp | 21 +++++++++++++++- single_include/catch.hpp | 33 ++++++++++++++++++++++--- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/include/internal/catch_default_main.hpp b/include/internal/catch_default_main.hpp index 017a4f11..01d7105e 100644 --- a/include/internal/catch_default_main.hpp +++ b/include/internal/catch_default_main.hpp @@ -24,14 +24,14 @@ int main (int argc, char * const argv[]) int result = Catch::Main( argc, (char* const*)argv ); [pool drain]; - return result; #else - return Catch::Main( argc, argv ); + int result =Catch::Main( argc, argv ); #endif + Catch::Hub::cleanUp(); + return result; } - #endif // TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED diff --git a/include/internal/catch_hub.h b/include/internal/catch_hub.h index 63e4468e..f84056fe 100644 --- a/include/internal/catch_hub.h +++ b/include/internal/catch_hub.h @@ -77,7 +77,13 @@ namespace Catch static bool advanceGeneratorsForCurrentTest (); + static void cleanUp + (); + private: + + static Hub*& singleInstance(); + GeneratorsForTest* findGeneratorsForCurrentTest (); diff --git a/include/internal/catch_hub_impl.hpp b/include/internal/catch_hub_impl.hpp index 437bc427..d9472d9a 100644 --- a/include/internal/catch_hub_impl.hpp +++ b/include/internal/catch_hub_impl.hpp @@ -32,8 +32,27 @@ namespace Catch Hub& Hub::me () { - static Hub hub; + Hub*& hub = singleInstance(); + if( !hub ) + hub = new Hub(); + return *hub; + } + + /////////////////////////////////////////////////////////////////////////// + void Hub::cleanUp + () + { + Hub*& hub = singleInstance(); + delete hub; + hub = NULL; + } + + /////////////////////////////////////////////////////////////////////////// + Hub*& Hub::singleInstance() + { + static Hub* hub = NULL; return hub; + } /////////////////////////////////////////////////////////////////////////// diff --git a/single_include/catch.hpp b/single_include/catch.hpp index c2970f82..a2796013 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -370,7 +370,13 @@ namespace Catch static bool advanceGeneratorsForCurrentTest (); + static void cleanUp + (); + private: + + static Hub*& singleInstance(); + GeneratorsForTest* findGeneratorsForCurrentTest (); @@ -4513,8 +4519,27 @@ namespace Catch Hub& Hub::me () { - static Hub hub; + Hub*& hub = singleInstance(); + if( !hub ) + hub = new Hub(); + return *hub; + } + + /////////////////////////////////////////////////////////////////////////// + void Hub::cleanUp + () + { + Hub*& hub = singleInstance(); + delete hub; + hub = NULL; + } + + /////////////////////////////////////////////////////////////////////////// + Hub*& Hub::singleInstance() + { + static Hub* hub = NULL; return hub; + } /////////////////////////////////////////////////////////////////////////// @@ -6276,16 +6301,16 @@ int main (int argc, char * const argv[]) int result = Catch::Main( argc, (char* const*)argv ); [pool drain]; - return result; #else - return Catch::Main( argc, argv ); + int result =Catch::Main( argc, argv ); #endif + Catch::Hub::cleanUp(); + return result; } - #endif //////