summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvladlosev <vladlosev@8415998a-534a-0410-bf83-d39667b30386>2011-02-11 23:50:38 +0000
committervladlosev <vladlosev@8415998a-534a-0410-bf83-d39667b30386>2011-02-11 23:50:38 +0000
commitafc487b688e01f30917d964f9b37a6c630cd5c24 (patch)
tree16c83bbbabf171bac8edf0ec0cda0e80ec1aaef2
parentb3a1093de46cab724b374939552355a38d1a79c8 (diff)
downloadgooglemock-afc487b688e01f30917d964f9b37a6c630cd5c24.tar.gz
Improves cross-platform compatibility of gmock output. This fixes issue 135.
git-svn-id: http://googlemock.googlecode.com/svn/trunk@356 8415998a-534a-0410-bf83-d39667b30386
-rw-r--r--include/gmock/gmock-spec-builders.h4
-rw-r--r--test/gmock-spec-builders_test.cc48
2 files changed, 40 insertions, 12 deletions
diff --git a/include/gmock/gmock-spec-builders.h b/include/gmock/gmock-spec-builders.h
index df2aef1..4f0b072 100644
--- a/include/gmock/gmock-spec-builders.h
+++ b/include/gmock/gmock-spec-builders.h
@@ -575,7 +575,7 @@ class ExpectationBase {
// Describes the source file location of this expectation.
void DescribeLocationTo(::std::ostream* os) const {
- *os << file() << ":" << line() << ": ";
+ *os << FormatFileLocation(file(), line()) << " ";
}
// Describes how many times a function call matching this
@@ -1527,7 +1527,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
"returning default value.\n");
} else {
*os << "taking default action specified at:\n"
- << spec->file() << ":" << spec->line() << ":\n";
+ << FormatFileLocation(spec->file(), spec->line()) << "\n";
}
}
diff --git a/test/gmock-spec-builders_test.cc b/test/gmock-spec-builders_test.cc
index 6c844e2..737bcff 100644
--- a/test/gmock-spec-builders_test.cc
+++ b/test/gmock-spec-builders_test.cc
@@ -43,6 +43,7 @@
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
+#include "gtest/internal/gtest-port.h"
namespace testing {
namespace internal {
@@ -88,6 +89,7 @@ using testing::Ne;
using testing::Return;
using testing::Sequence;
using testing::internal::ExpectationTester;
+using testing::internal::FormatFileLocation;
using testing::internal::g_gmock_mutex;
using testing::internal::kErrorVerbosity;
using testing::internal::kInfoVerbosity;
@@ -797,6 +799,19 @@ TEST(ExpectCallTest, NthMatchTakesNthAction) {
EXPECT_EQ(3, b.DoB());
}
+// Tests that the WillRepeatedly() action is taken when the WillOnce(...)
+// list is exhausted.
+TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
+ MockB b;
+ EXPECT_CALL(b, DoB())
+ .WillOnce(Return(1))
+ .WillRepeatedly(Return(2));
+
+ EXPECT_EQ(1, b.DoB());
+ EXPECT_EQ(2, b.DoB());
+ EXPECT_EQ(2, b.DoB());
+}
+
#if GTEST_HAS_STREAM_REDIRECTION
// Tests that the default action is taken when the WillOnce(...) list is
@@ -832,21 +847,34 @@ TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
" - returning default value."));
}
-#endif // GTEST_HAS_STREAM_REDIRECTION
-
-// Tests that the WillRepeatedly() action is taken when the WillOnce(...)
-// list is exhausted.
-TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
+TEST(FunctionMockerTest, ReportsExpectCallLocationForExhausedActions) {
MockB b;
- EXPECT_CALL(b, DoB())
- .WillOnce(Return(1))
- .WillRepeatedly(Return(2));
+ std::string expect_call_location = FormatFileLocation(__FILE__, __LINE__ + 1);
+ EXPECT_CALL(b, DoB()).Times(AnyNumber()).WillOnce(Return(1));
EXPECT_EQ(1, b.DoB());
- EXPECT_EQ(2, b.DoB());
- EXPECT_EQ(2, b.DoB());
+
+ CaptureStdout();
+ EXPECT_EQ(0, b.DoB());
+ const String output = GetCapturedStdout();
+ // The warning message should contain the call location.
+ EXPECT_PRED_FORMAT2(IsSubstring, expect_call_location, output);
}
+TEST(FunctionMockerTest, ReportsDefaultActionLocationOfUninterestingCalls) {
+ std::string on_call_location;
+ CaptureStdout();
+ {
+ MockB b;
+ on_call_location = FormatFileLocation(__FILE__, __LINE__ + 1);
+ ON_CALL(b, DoB(_)).WillByDefault(Return(0));
+ b.DoB(0);
+ }
+ EXPECT_PRED_FORMAT2(IsSubstring, on_call_location, GetCapturedStdout());
+}
+
+#endif // GTEST_HAS_STREAM_REDIRECTION
+
// Tests that an uninteresting call performs the default action.
TEST(UninterestingCallTest, DoesDefaultAction) {
// When there is an ON_CALL() statement, the action specified by it