Chromium Code Reviews| Index: base/test/test_suite.cc |
| diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc |
| index 07b9964578a4a860712524443bf977505ef7119c..6bde1fab8d7b24ff7792d810829564c85102f14a 100644 |
| --- a/base/test/test_suite.cc |
| +++ b/base/test/test_suite.cc |
| @@ -76,6 +76,29 @@ class TestClientInitializer : public testing::EmptyTestEventListener { |
| DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); |
| }; |
| +// This class forces the destruction of all Singletons and LazyInstances |
| +// between tests. |
|
Paweł Hajdan Jr.
2013/05/08 16:32:25
nit: Let's add some text here that it helps preven
Robert Sesek
2013/05/08 16:42:11
Done.
|
| +class SingletonDestructor : public testing::EmptyTestEventListener { |
| + public: |
| + SingletonDestructor() {} |
| + virtual ~SingletonDestructor() {} |
| + |
| + // testing::EmptyTestEventListener: |
| + virtual void OnTestStart( |
| + const testing::TestInfo& test_info) OVERRIDE { |
| + at_exit_manager_.reset(new base::ShadowingAtExitManager); |
| + } |
| + |
| + virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { |
| + at_exit_manager_.reset(); |
| + } |
| + |
| + private: |
| + scoped_ptr<base::ShadowingAtExitManager> at_exit_manager_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SingletonDestructor); |
| +}; |
| + |
| } // namespace |
| TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
| @@ -252,6 +275,12 @@ void TestSuite::Initialize() { |
| CatchMaybeTests(); |
| ResetCommandLine(); |
| + // Add a listener to destroy all Singletons and LazyInstances between each |
| + // test. |
|
Paweł Hajdan Jr.
2013/05/08 16:32:25
nit: Also expand this comment. To avoid duplicatio
Robert Sesek
2013/05/08 16:42:11
Done.
|
| + testing::TestEventListeners& listeners = |
| + testing::UnitTest::GetInstance()->listeners(); |
| + listeners.Append(new SingletonDestructor); |
| + |
| TestTimeouts::Initialize(); |
| } |