Suppresses the stack trace in a warning for uninteresting call by default; the stack trace will still be printed when --gmock_verbose=info is printed.

This commit is contained in:
kosak 2015-02-14 22:05:58 +00:00
parent d478a1f46d
commit 5625dd333a
3 changed files with 27 additions and 13 deletions

View File

@ -245,9 +245,12 @@ GTEST_API_ ThreadLocal<Sequence*> g_gmock_implicit_sequence;
// Reports an uninteresting call (whose description is in msg) in the // Reports an uninteresting call (whose description is in msg) in the
// manner specified by 'reaction'. // manner specified by 'reaction'.
void ReportUninterestingCall(CallReaction reaction, const string& msg) { void ReportUninterestingCall(CallReaction reaction, const string& msg) {
// Include a stack trace only if --gmock_verbose=info is specified.
const int stack_frames_to_skip =
GMOCK_FLAG(verbose) == kInfoVerbosity ? 3 : -1;
switch (reaction) { switch (reaction) {
case kAllow: case kAllow:
Log(kInfo, msg, 3); Log(kInfo, msg, stack_frames_to_skip);
break; break;
case kWarn: case kWarn:
Log(kWarning, Log(kWarning,
@ -256,8 +259,8 @@ void ReportUninterestingCall(CallReaction reaction, const string& msg) {
"call should not happen. Do not suppress it by blindly adding " "call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. " "an EXPECT_CALL() if you don't mean to enforce the call. "
"See http://code.google.com/p/googlemock/wiki/CookBook#" "See http://code.google.com/p/googlemock/wiki/CookBook#"
"Knowing_When_to_Expect for details.", "Knowing_When_to_Expect for details.\n",
3); stack_frames_to_skip);
break; break;
default: // FAIL default: // FAIL
Expect(false, NULL, -1, msg); Expect(false, NULL, -1, msg);

View File

@ -81,6 +81,7 @@ using testing::Gt;
using testing::InSequence; using testing::InSequence;
using testing::Invoke; using testing::Invoke;
using testing::InvokeWithoutArgs; using testing::InvokeWithoutArgs;
using testing::IsNotSubstring;
using testing::IsSubstring; using testing::IsSubstring;
using testing::Lt; using testing::Lt;
using testing::Message; using testing::Message;
@ -1977,9 +1978,25 @@ class VerboseFlagPreservingFixture : public testing::Test {
#if GTEST_HAS_STREAM_REDIRECTION #if GTEST_HAS_STREAM_REDIRECTION
// Tests that an uninteresting mock function call on a naggy mock // Tests that an uninteresting mock function call on a naggy mock
// generates a warning containing the stack trace. // generates a warning without the stack trace when
// --gmock_verbose=warning is specified.
TEST(FunctionCallMessageTest, TEST(FunctionCallMessageTest,
UninterestingCallOnNaggyMockGeneratesFyiWithStackTrace) { UninterestingCallOnNaggyMockGeneratesNoStackTraceWhenVerboseWarning) {
GMOCK_FLAG(verbose) = kWarningVerbosity;
NaggyMock<MockC> c;
CaptureStdout();
c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable());
const std::string output = GetCapturedStdout();
EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output);
EXPECT_PRED_FORMAT2(IsNotSubstring, "Stack trace:", output);
}
// Tests that an uninteresting mock function call on a naggy mock
// generates a warning containing the stack trace when
// --gmock_verbose=info is specified.
TEST(FunctionCallMessageTest,
UninterestingCallOnNaggyMockGeneratesFyiWithStackTraceWhenVerboseInfo) {
GMOCK_FLAG(verbose) = kInfoVerbosity;
NaggyMock<MockC> c; NaggyMock<MockC> c;
CaptureStdout(); CaptureStdout();
c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable()); c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable());
@ -2112,8 +2129,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
"\nGMOCK WARNING:\n" "\nGMOCK WARNING:\n"
"Uninteresting mock function call - returning directly.\n" "Uninteresting mock function call - returning directly.\n"
" Function call: DoA(5)\n" + " Function call: DoA(5)\n" +
note + note,
"\nStack trace:\n",
"DoA"); "DoA");
// A non-void-returning function. // A non-void-returning function.
@ -2126,8 +2142,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
"Uninteresting mock function call - returning default value.\n" "Uninteresting mock function call - returning default value.\n"
" Function call: Binary(2, 1)\n" " Function call: Binary(2, 1)\n"
" Returns: false\n" + " Returns: false\n" +
note + note,
"\nStack trace:\n",
"Binary"); "Binary");
} }
}; };

View File

@ -76,7 +76,6 @@ Uninteresting mock function call - returning default value.
Function call: Bar2(0, 1) Function call: Bar2(0, 1)
Returns: false Returns: false
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://code.google.com/p/googlemock/wiki/CookBook#Knowing_When_to_Expect for details. NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://code.google.com/p/googlemock/wiki/CookBook#Knowing_When_to_Expect for details.
Stack trace:
[ OK ] GMockOutputTest.UninterestingCall [ OK ] GMockOutputTest.UninterestingCall
[ RUN ] GMockOutputTest.UninterestingCallToVoidFunction [ RUN ] GMockOutputTest.UninterestingCallToVoidFunction
@ -84,7 +83,6 @@ GMOCK WARNING:
Uninteresting mock function call - returning directly. Uninteresting mock function call - returning directly.
Function call: Bar3(0, 1) Function call: Bar3(0, 1)
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://code.google.com/p/googlemock/wiki/CookBook#Knowing_When_to_Expect for details. NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://code.google.com/p/googlemock/wiki/CookBook#Knowing_When_to_Expect for details.
Stack trace:
[ OK ] GMockOutputTest.UninterestingCallToVoidFunction [ OK ] GMockOutputTest.UninterestingCallToVoidFunction
[ RUN ] GMockOutputTest.RetiredExpectation [ RUN ] GMockOutputTest.RetiredExpectation
unknown file: Failure unknown file: Failure
@ -269,7 +267,6 @@ FILE:#:
Function call: Bar2(2, 2) Function call: Bar2(2, 2)
Returns: true Returns: true
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://code.google.com/p/googlemock/wiki/CookBook#Knowing_When_to_Expect for details. NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://code.google.com/p/googlemock/wiki/CookBook#Knowing_When_to_Expect for details.
Stack trace:
GMOCK WARNING: GMOCK WARNING:
Uninteresting mock function call - taking default action specified at: Uninteresting mock function call - taking default action specified at:
@ -277,7 +274,6 @@ FILE:#:
Function call: Bar2(1, 1) Function call: Bar2(1, 1)
Returns: false Returns: false
NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://code.google.com/p/googlemock/wiki/CookBook#Knowing_When_to_Expect for details. NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See http://code.google.com/p/googlemock/wiki/CookBook#Knowing_When_to_Expect for details.
Stack trace:
[ OK ] GMockOutputTest.UninterestingCallWithDefaultAction [ OK ] GMockOutputTest.UninterestingCallWithDefaultAction
[ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction [ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction