Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
470df42b
Commit
470df42b
authored
Feb 02, 2010
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enables tests depending on stdout capturing (by Vlad Losev).
parent
db22c227
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
40 deletions
+42
-40
gmock-internal-utils_test.cc
test/gmock-internal-utils_test.cc
+27
-29
gmock-nice-strict_test.cc
test/gmock-nice-strict_test.cc
+15
-11
gmock-spec-builders_test.cc
test/gmock-spec-builders_test.cc
+0
-0
No files found.
test/gmock-internal-utils_test.cc
View file @
470df42b
...
@@ -538,8 +538,7 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
...
@@ -538,8 +538,7 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
EXPECT_TRUE
(
LogIsVisible
(
WARNING
));
EXPECT_TRUE
(
LogIsVisible
(
WARNING
));
}
}
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// Tests the Log() function.
// Tests the Log() function.
...
@@ -549,16 +548,16 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
...
@@ -549,16 +548,16 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
bool
should_print
)
{
bool
should_print
)
{
const
string
old_flag
=
GMOCK_FLAG
(
verbose
);
const
string
old_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
verbosity
;
GMOCK_FLAG
(
verbose
)
=
verbosity
;
Capture
Test
Stdout();
CaptureStdout
();
Log
(
severity
,
"Test log.
\n
"
,
0
);
Log
(
severity
,
"Test log.
\n
"
,
0
);
if
(
should_print
)
{
if
(
should_print
)
{
EXPECT_
PRED2(RE::FullMatch
,
EXPECT_
THAT
(
GetCapturedStdout
().
c_str
()
,
GetCapturedTestStdout(),
ContainsRegex
(
severity == WARNING ?
severity
==
WARNING
?
"\nGMOCK WARNING:\nTest log\\.\nStack trace:\n[\\s\\S]*
" :
"^
\n
GMOCK WARNING:
\n
Test log
\\
.
\n
Stack trace:
\n
"
:
"\nTest log\\.\nStack trace:\n[\\s\\S]*"
);
"^
\n
Test log
\\
.
\n
Stack trace:
\n
"
)
);
}
else
{
}
else
{
EXPECT_
EQ("", GetCapturedTestStdout
());
EXPECT_
STREQ
(
""
,
GetCapturedStdout
().
c_str
());
}
}
GMOCK_FLAG
(
verbose
)
=
old_flag
;
GMOCK_FLAG
(
verbose
)
=
old_flag
;
}
}
...
@@ -567,18 +566,18 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
...
@@ -567,18 +566,18 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
// 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
)
{
GMOCK_FLAG
(
verbose
)
=
kInfoVerbosity
;
GMOCK_FLAG
(
verbose
)
=
kInfoVerbosity
;
Capture
Test
Stdout();
CaptureStdout
();
Log
(
INFO
,
"Test log.
\n
"
,
-
1
);
Log
(
INFO
,
"Test log.
\n
"
,
-
1
);
EXPECT_
EQ("\nTest log.\n", GetCapturedTestStdout
());
EXPECT_
STREQ
(
"
\n
Test log.
\n
"
,
GetCapturedStdout
().
c_str
());
}
}
// 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
// treated as 0.
// treated as 0.
TEST
(
LogTest
,
NoSkippingStackFrameInOptMode
)
{
TEST
(
LogTest
,
NoSkippingStackFrameInOptMode
)
{
Capture
Test
Stdout();
CaptureStdout
();
Log
(
WARNING
,
"Test log.
\n
"
,
100
);
Log
(
WARNING
,
"Test log.
\n
"
,
100
);
const
string log = GetCapturedTest
Stdout();
const
String
log
=
GetCaptured
Stdout
();
#if
def NDEBUG
#if
defined(NDEBUG) && GTEST_GOOGLE3_MODE_
// In opt mode, no stack frame should be skipped.
// In opt mode, no stack frame should be skipped.
EXPECT_THAT
(
log
,
ContainsRegex
(
"
\n
GMOCK WARNING:
\n
"
EXPECT_THAT
(
log
,
ContainsRegex
(
"
\n
GMOCK WARNING:
\n
"
"Test log
\\
.
\n
"
"Test log
\\
.
\n
"
...
@@ -586,10 +585,10 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
...
@@ -586,10 +585,10 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
".+"
));
".+"
));
#else
#else
// In dbg mode, the stack frames should be skipped.
// In dbg mode, the stack frames should be skipped.
EXPECT_EQ("\nGMOCK WARNING:\n"
EXPECT_
STR
EQ
(
"
\n
GMOCK WARNING:
\n
"
"Test log.\n"
"Test log.
\n
"
"Stack trace:\n", log
);
"Stack trace:
\n
"
,
log
.
c_str
()
);
#endif
// NDEBUG
#endif
}
}
// Tests that all logs are printed when the value of the
// Tests that all logs are printed when the value of the
...
@@ -620,7 +619,7 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
...
@@ -620,7 +619,7 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
TestLogWithSeverity
(
"invalid"
,
WARNING
,
true
);
TestLogWithSeverity
(
"invalid"
,
WARNING
,
true
);
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
TEST
(
TypeTraitsTest
,
true_type
)
{
TEST
(
TypeTraitsTest
,
true_type
)
{
EXPECT_TRUE
(
true_type
::
value
);
EXPECT_TRUE
(
true_type
::
value
);
...
@@ -657,18 +656,17 @@ TEST(TypeTraitsTest, remove_reference) {
...
@@ -657,18 +656,17 @@ TEST(TypeTraitsTest, remove_reference) {
EXPECT_TRUE
((
type_equals
<
double
*
,
remove_reference
<
double
*>::
type
>::
value
));
EXPECT_TRUE
((
type_equals
<
double
*
,
remove_reference
<
double
*>::
type
>::
value
));
}
}
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// Verifies that Log() behaves correctly for the given verbosity level
// Verifies that Log() behaves correctly for the given verbosity level
// and log severity.
// and log severity.
s
tring GrabOutput(void(*logger)(), const char* verbosity) {
S
tring
GrabOutput
(
void
(
*
logger
)(),
const
char
*
verbosity
)
{
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
const
string
saved_flag
=
GMOCK_FLAG
(
verbose
);
GMOCK_FLAG
(
verbose
)
=
verbosity
;
GMOCK_FLAG
(
verbose
)
=
verbosity
;
Capture
Test
Stdout();
CaptureStdout
();
logger
();
logger
();
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
GMOCK_FLAG
(
verbose
)
=
saved_flag
;
return GetCaptured
Test
Stdout();
return
GetCapturedStdout
();
}
}
class
DummyMock
{
class
DummyMock
{
...
@@ -692,13 +690,13 @@ TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
...
@@ -692,13 +690,13 @@ TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
// Verifies that EXPECT_CALL doesn't log
// Verifies that EXPECT_CALL doesn't log
// if the --gmock_verbose flag is set to "warning".
// if the --gmock_verbose flag is set to "warning".
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsWarning
)
{
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsWarning
)
{
EXPECT_
EQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity
));
EXPECT_
STREQ
(
""
,
GrabOutput
(
ExpectCallLogger
,
kWarningVerbosity
).
c_str
(
));
}
}
// Verifies that EXPECT_CALL doesn't log
// Verifies that EXPECT_CALL doesn't log
// if the --gmock_verbose flag is set to "error".
// if the --gmock_verbose flag is set to "error".
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
TEST
(
ExpectCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
EXPECT_
EQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity
));
EXPECT_
STREQ
(
""
,
GrabOutput
(
ExpectCallLogger
,
kErrorVerbosity
).
c_str
(
));
}
}
void
OnCallLogger
()
{
void
OnCallLogger
()
{
...
@@ -715,13 +713,13 @@ TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
...
@@ -715,13 +713,13 @@ TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
// Verifies that ON_CALL doesn't log
// Verifies that ON_CALL doesn't log
// if the --gmock_verbose flag is set to "warning".
// if the --gmock_verbose flag is set to "warning".
TEST
(
OnCallTest
,
DoesNotLogWhenVerbosityIsWarning
)
{
TEST
(
OnCallTest
,
DoesNotLogWhenVerbosityIsWarning
)
{
EXPECT_
EQ("", GrabOutput(OnCallLogger, kWarningVerbosity
));
EXPECT_
STREQ
(
""
,
GrabOutput
(
OnCallLogger
,
kWarningVerbosity
).
c_str
(
));
}
}
// Verifies that ON_CALL doesn't log if
// Verifies that ON_CALL doesn't log if
// the --gmock_verbose flag is set to "error".
// the --gmock_verbose flag is set to "error".
TEST
(
OnCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
TEST
(
OnCallTest
,
DoesNotLogWhenVerbosityIsError
)
{
EXPECT_
EQ("", GrabOutput(OnCallLogger, kErrorVerbosity
));
EXPECT_
STREQ
(
""
,
GrabOutput
(
OnCallLogger
,
kErrorVerbosity
).
c_str
(
));
}
}
void
OnCallAnyArgumentLogger
()
{
void
OnCallAnyArgumentLogger
()
{
...
@@ -735,7 +733,7 @@ TEST(OnCallTest, LogsAnythingArgument) {
...
@@ -735,7 +733,7 @@ TEST(OnCallTest, LogsAnythingArgument) {
HasSubstr
(
"ON_CALL(mock, TestMethodArg(_)"
));
HasSubstr
(
"ON_CALL(mock, TestMethodArg(_)"
));
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
// Tests ArrayEq().
// Tests ArrayEq().
...
...
test/gmock-nice-strict_test.cc
View file @
470df42b
...
@@ -57,6 +57,11 @@ using testing::HasSubstr;
...
@@ -57,6 +57,11 @@ using testing::HasSubstr;
using
testing
::
NiceMock
;
using
testing
::
NiceMock
;
using
testing
::
StrictMock
;
using
testing
::
StrictMock
;
#if GTEST_HAS_STREAM_REDIRECTION_
using
testing
::
internal
::
CaptureStdout
;
using
testing
::
internal
::
GetCapturedStdout
;
#endif // GTEST_HAS_STREAM_REDIRECTION_
// Defines some mock classes needed by the tests.
// Defines some mock classes needed by the tests.
class
Foo
{
class
Foo
{
...
@@ -102,17 +107,16 @@ class MockBar {
...
@@ -102,17 +107,16 @@ class MockBar {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
MockBar
);
};
};
// TODO(wan@google.com): find a way to re-enable these tests.
#if GTEST_HAS_STREAM_REDIRECTION_
#if 0
// Tests that a nice mock generates no warning for uninteresting calls.
// Tests that a nice mock generates no warning for uninteresting calls.
TEST
(
NiceMockTest
,
NoWarningForUninterestingCall
)
{
TEST
(
NiceMockTest
,
NoWarningForUninterestingCall
)
{
NiceMock
<
MockFoo
>
nice_foo
;
NiceMock
<
MockFoo
>
nice_foo
;
Capture
Test
Stdout();
CaptureStdout
();
nice_foo
.
DoThis
();
nice_foo
.
DoThis
();
nice_foo
.
DoThat
(
true
);
nice_foo
.
DoThat
(
true
);
EXPECT_
EQ("", GetCapturedTestStdout
());
EXPECT_
STREQ
(
""
,
GetCapturedStdout
().
c_str
());
}
}
// Tests that a nice mock generates no warning for uninteresting calls
// Tests that a nice mock generates no warning for uninteresting calls
...
@@ -123,9 +127,9 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
...
@@ -123,9 +127,9 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
ON_CALL
(
*
nice_foo
,
DoThis
())
ON_CALL
(
*
nice_foo
,
DoThis
())
.
WillByDefault
(
Invoke
(
nice_foo
,
&
MockFoo
::
Delete
));
.
WillByDefault
(
Invoke
(
nice_foo
,
&
MockFoo
::
Delete
));
Capture
Test
Stdout();
CaptureStdout
();
nice_foo
->
DoThis
();
nice_foo
->
DoThis
();
EXPECT_
EQ("", GetCapturedTestStdout
());
EXPECT_
STREQ
(
""
,
GetCapturedStdout
().
c_str
());
}
}
// Tests that a nice mock generates informational logs for
// Tests that a nice mock generates informational logs for
...
@@ -134,18 +138,18 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
...
@@ -134,18 +138,18 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
NiceMock
<
MockFoo
>
nice_foo
;
NiceMock
<
MockFoo
>
nice_foo
;
GMOCK_FLAG
(
verbose
)
=
"info"
;
GMOCK_FLAG
(
verbose
)
=
"info"
;
Capture
Test
Stdout();
CaptureStdout
();
nice_foo
.
DoThis
();
nice_foo
.
DoThis
();
EXPECT_THAT(GetCaptured
Test
Stdout(),
EXPECT_THAT
(
GetCapturedStdout
(),
HasSubstr
(
"Uninteresting mock function call"
));
HasSubstr
(
"Uninteresting mock function call"
));
Capture
Test
Stdout();
CaptureStdout
();
nice_foo
.
DoThat
(
true
);
nice_foo
.
DoThat
(
true
);
EXPECT_THAT(GetCaptured
Test
Stdout(),
EXPECT_THAT
(
GetCapturedStdout
(),
HasSubstr
(
"Uninteresting mock function call"
));
HasSubstr
(
"Uninteresting mock function call"
));
}
}
#endif //
0
#endif //
GTEST_HAS_STREAM_REDIRECTION_
// Tests that a nice mock allows expected calls.
// Tests that a nice mock allows expected calls.
TEST
(
NiceMockTest
,
AllowsExpectedCall
)
{
TEST
(
NiceMockTest
,
AllowsExpectedCall
)
{
...
...
test/gmock-spec-builders_test.cc
View file @
470df42b
This diff is collapsed.
Click to expand it.
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