Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
76c1c612
Commit
76c1c612
authored
May 05, 2010
by
vladlosev
Browse files
Fixes tests leaking altered values of GMOCK_FLAG(verbose) (issue 110).
parent
54af9ba5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
15 deletions
+25
-15
test/gmock-internal-utils_test.cc
test/gmock-internal-utils_test.cc
+2
-0
test/gmock-nice-strict_test.cc
test/gmock-nice-strict_test.cc
+2
-0
test/gmock-spec-builders_test.cc
test/gmock-spec-builders_test.cc
+21
-15
No files found.
test/gmock-internal-utils_test.cc
View file @
76c1c612
...
@@ -565,10 +565,12 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
...
@@ -565,10 +565,12 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
// Tests that when the stack_frames_to_skip parameter is negative,
// Tests that when the stack_frames_to_skip parameter is negative,
// Log() doesn't include the stack trace in the output.
// Log() doesn't include the stack trace in the output.
TEST
(
LogTest
,
NoStackTraceWhenStackFramesToSkipIsNegative
)
{
TEST
(
LogTest
,
NoStackTraceWhenStackFramesToSkipIsNegative
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
kInfoVerbosity
;
GMOCK_FLAG
(
verbose
)
=
kInfoVerbosity
;
CaptureStdout
();
CaptureStdout
();
Log
(
INFO
,
"Test log.
\n
"
,
-
1
);
Log
(
INFO
,
"Test log.
\n
"
,
-
1
);
EXPECT_STREQ
(
"
\n
Test log.
\n
"
,
GetCapturedStdout
().
c_str
());
EXPECT_STREQ
(
"
\n
Test log.
\n
"
,
GetCapturedStdout
().
c_str
());
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
}
}
// Tests that in opt mode, a positive stack_frames_to_skip argument is
// Tests that in opt mode, a positive stack_frames_to_skip argument is
...
...
test/gmock-nice-strict_test.cc
View file @
76c1c612
...
@@ -137,6 +137,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
...
@@ -137,6 +137,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
TEST
(
NiceMockTest
,
InfoForUninterestingCall
)
{
TEST
(
NiceMockTest
,
InfoForUninterestingCall
)
{
NiceMock
<
MockFoo
>
nice_foo
;
NiceMock
<
MockFoo
>
nice_foo
;
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
"info"
;
GMOCK_FLAG
(
verbose
)
=
"info"
;
CaptureStdout
();
CaptureStdout
();
nice_foo
.
DoThis
();
nice_foo
.
DoThis
();
...
@@ -147,6 +148,7 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
...
@@ -147,6 +148,7 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
nice_foo
.
DoThat
(
true
);
nice_foo
.
DoThat
(
true
);
EXPECT_THAT
(
GetCapturedStdout
(),
EXPECT_THAT
(
GetCapturedStdout
(),
HasSubstr
(
"Uninteresting mock function call"
));
HasSubstr
(
"Uninteresting mock function call"
));
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
}
}
#endif // GTEST_HAS_STREAM_REDIRECTION_
#endif // GTEST_HAS_STREAM_REDIRECTION_
...
...
test/gmock-spec-builders_test.cc
View file @
76c1c612
...
@@ -1783,6 +1783,25 @@ class MockC {
...
@@ -1783,6 +1783,25 @@ class MockC {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockC
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockC
);
};
};
class
VerboseFlagPreservingFixture
:
public
testing
::
Test
{
protected:
// The code needs to work when both ::string and ::std::string are defined
// and the flag is implemented as a testing::internal::String. In this
// case, without the call to c_str(), the compiler will complain that it
// cannot figure out what overload of string constructor to use.
// TODO(vladl@google.com): Use internal::string instead of String for
// string flags in Google Test.
VerboseFlagPreservingFixture
()
:
saved_verbose_flag_
(
GMOCK_FLAG
(
verbose
).
c_str
())
{}
~
VerboseFlagPreservingFixture
()
{
GMOCK_FLAG
(
verbose
)
=
saved_verbose_flag_
;
}
private:
const
string
saved_verbose_flag_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
VerboseFlagPreservingFixture
);
};
#if GTEST_HAS_STREAM_REDIRECTION_
#if GTEST_HAS_STREAM_REDIRECTION_
// Tests that an uninteresting mock function call generates a warning
// Tests that an uninteresting mock function call generates a warning
...
@@ -1842,7 +1861,7 @@ TEST(FunctionCallMessageTest, UninterestingCallPrintsArgumentsAndReturnValue) {
...
@@ -1842,7 +1861,7 @@ TEST(FunctionCallMessageTest, UninterestingCallPrintsArgumentsAndReturnValue) {
// Tests how the --gmock_verbose flag affects Google Mock's output.
// Tests how the --gmock_verbose flag affects Google Mock's output.
class
GMockVerboseFlagTest
:
public
testing
::
Test
{
class
GMockVerboseFlagTest
:
public
VerboseFlagPreservingFixture
{
public:
public:
// Verifies that the given Google Mock output is correct. (When
// Verifies that the given Google Mock output is correct. (When
// should_print is true, the output should match the given regex and
// should_print is true, the output should match the given regex and
...
@@ -1982,22 +2001,9 @@ class LogTestHelper {
...
@@ -1982,22 +2001,9 @@ class LogTestHelper {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
LogTestHelper
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
LogTestHelper
);
};
};
class
GMockLogTest
:
public
::
testing
::
Test
{
class
GMockLogTest
:
public
VerboseFlagPreservingFixture
{
protected:
protected:
virtual
void
SetUp
()
{
// The code needs to work when both ::string and ::std::string are
// defined and the flag is implemented as a
// testing::internal::String. In this case, without the call to
// c_str(), the compiler will complain that it cannot figure out
// whether the String flag should be converted to a ::string or an
// ::std::string before being assigned to original_verbose_.
original_verbose_
=
GMOCK_FLAG
(
verbose
).
c_str
();
}
virtual
void
TearDown
()
{
GMOCK_FLAG
(
verbose
)
=
original_verbose_
;
}
LogTestHelper
helper_
;
LogTestHelper
helper_
;
string
original_verbose_
;
};
};
TEST_F
(
GMockLogTest
,
DoesNotPrintGoodCallInternallyIfVerbosityIsWarning
)
{
TEST_F
(
GMockLogTest
,
DoesNotPrintGoodCallInternallyIfVerbosityIsWarning
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment