Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPhil Nash2012-02-18 09:58:30 +0000
committerPhil Nash2012-02-18 09:58:30 +0000
commitdd5b9c2ae587cb2a79493af6ffa5045e9cb7c4e4 (patch)
tree6bc91b65c32a70166b450671f03d72470a47c725
parent333e6e625484a968b97dd5dd7e2eeea800c732f8 (diff)
downloadcatch3-dd5b9c2ae587cb2a79493af6ffa5045e9cb7c4e4.tar.gz
Added clean-up
Clean-up statics at the end of main to avoid added noise when looking for leaks
-rw-r--r--include/internal/catch_default_main.hpp6
-rw-r--r--include/internal/catch_hub.h6
-rw-r--r--include/internal/catch_hub_impl.hpp21
-rw-r--r--single_include/catch.hpp33
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
//////