Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2562)

Unified Diff: base/test/test_suite.cc

Issue 10735063: Create an AtExitManager around each test, to take care of stray singletons (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/test_suite.cc
diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc
index 0cca8fa25ba9093f87e6af7ebfdb66cc583acdcd..c1d110c546a98172217498f0ecb3159070119ed3 100644
--- a/base/test/test_suite.cc
+++ b/base/test/test_suite.cc
@@ -82,10 +82,19 @@ class TestWatchAtExitManager : public testing::EmptyTestEventListener {
virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
initial_top_manager_ = AtExitManager::current();
at_exit_stack_size_ = initial_top_manager_->CallbackStackSize();
+ per_test_manager_.reset(new base::AtExitManager);
}
virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
AtExitManager* new_top_manager = AtExitManager::current();
+ if (per_test_manager_.get() != new_top_manager) {
+ ADD_FAILURE() << "The current AtExitManager has changed across the "
+ "test " << test_info.test_case_name() << "." << test_info.name() <<
+ " most likely because one was created without being destroyed.";
Ryan Sleevi 2012/07/11 22:30:41 style nit: The << should be on the beginning of ea
+ }
+ per_test_manager_.reset();
+
+ new_top_manager = AtExitManager::current();
size_t new_stack_size = new_top_manager->CallbackStackSize();
if (initial_top_manager_ != new_top_manager) {
@@ -93,10 +102,7 @@ class TestWatchAtExitManager : public testing::EmptyTestEventListener {
"test " << test_info.test_case_name() << "." << test_info.name() <<
" most likely because one was created without being destroyed.";
} else if (new_stack_size != at_exit_stack_size_) {
- // TODO(scottbyer): clean up all the errors that result from this and
- // turn this into a test failure with
- // ADD_FAILURE(). http://crbug.com/133403
- LOG(WARNING) <<
+ ADD_FAILURE() <<
"AtExitManager: items were added to the callback list by " <<
test_info.test_case_name() << "." << test_info.name() <<
". Global state should be cleaned up before a test exits.";
@@ -105,6 +111,7 @@ class TestWatchAtExitManager : public testing::EmptyTestEventListener {
private:
AtExitManager* initial_top_manager_;
+ scoped_ptr<base::AtExitManager> per_test_manager_;
size_t at_exit_stack_size_;
DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698