aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2009-05-05 23:14:47 +0000
committerzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2009-05-05 23:14:47 +0000
commite7bb5ededa4df6ec430c1e84154bc01bf84d4ecc (patch)
tree26a95c5d0237def74e51c633877d5cfc308db19d /src
parent125783fb87488239c062422bece2a9302489aafd (diff)
downloadgoogletest-e7bb5ededa4df6ec430c1e84154bc01bf84d4ecc.tar.gz
googletest-e7bb5ededa4df6ec430c1e84154bc01bf84d4ecc.tar.bz2
googletest-e7bb5ededa4df6ec430c1e84154bc01bf84d4ecc.zip
Improves the error message for leaked mocks to include the test name (by Zhanyong Wan).
Diffstat (limited to 'src')
-rw-r--r--src/gmock-spec-builders.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/gmock-spec-builders.cc b/src/gmock-spec-builders.cc
index 2bb72954..65a74b81 100644
--- a/src/gmock-spec-builders.cc
+++ b/src/gmock-spec-builders.cc
@@ -168,6 +168,8 @@ struct MockObjectState {
// invoked on this mock object.
const char* first_used_file;
int first_used_line;
+ ::std::string first_used_test_case;
+ ::std::string first_used_test;
bool leakable; // true iff it's OK to leak the object.
FunctionMockers function_mockers; // All registered methods of the object.
};
@@ -203,8 +205,13 @@ class MockObjectRegistry {
const MockObjectState& state = it->second;
internal::FormatFileLocation(
state.first_used_file, state.first_used_line, &cout);
- cout << " ERROR: this mock object should be deleted but never is. "
- << "Its address is @" << it->first << ".";
+ cout << " ERROR: this mock object";
+ if (state.first_used_test != "") {
+ cout << " (used in test " << state.first_used_test_case << "."
+ << state.first_used_test << ")";
+ }
+ cout << " should be deleted but never is. Its address is @"
+ << it->first << ".";
leaked_count++;
}
if (leaked_count > 0) {
@@ -357,6 +364,15 @@ void Mock::RegisterUseByOnCallOrExpectCall(
if (state.first_used_file == NULL) {
state.first_used_file = file;
state.first_used_line = line;
+ const TestInfo* const test_info =
+ UnitTest::GetInstance()->current_test_info();
+ if (test_info != NULL) {
+ // TODO(wan@google.com): record the test case name when the
+ // ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or
+ // TearDownTestCase().
+ state.first_used_test_case = test_info->test_case_name();
+ state.first_used_test = test_info->name();
+ }
}
}