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
04d6ed81
Commit
04d6ed81
authored
Sep 11, 2009
by
zhanyong.wan
Browse files
Simplifies the tests using EXPECT_DEATH_IF_SUPPORTED.
parent
d6ffd136
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
60 deletions
+23
-60
test/gmock-actions_test.cc
test/gmock-actions_test.cc
+8
-20
test/gmock-internal-utils_test.cc
test/gmock-internal-utils_test.cc
+2
-6
test/gmock-matchers_test.cc
test/gmock-matchers_test.cc
+1
-3
test/gmock-port_test.cc
test/gmock-port_test.cc
+4
-3
test/gmock-spec-builders_test.cc
test/gmock-spec-builders_test.cc
+8
-28
No files found.
test/gmock-actions_test.cc
View file @
04d6ed81
...
@@ -199,26 +199,22 @@ TEST(BuiltInDefaultValueTest, UserTypeHasNoDefault) {
...
@@ -199,26 +199,22 @@ TEST(BuiltInDefaultValueTest, UserTypeHasNoDefault) {
EXPECT_FALSE
(
BuiltInDefaultValue
<
UserType
>::
Exists
());
EXPECT_FALSE
(
BuiltInDefaultValue
<
UserType
>::
Exists
());
}
}
#if GTEST_HAS_DEATH_TEST
// Tests that BuiltInDefaultValue<T&>::Get() aborts the program.
// Tests that BuiltInDefaultValue<T&>::Get() aborts the program.
TEST
(
BuiltInDefaultValueDeathTest
,
IsUndefinedForReferences
)
{
TEST
(
BuiltInDefaultValueDeathTest
,
IsUndefinedForReferences
)
{
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
BuiltInDefaultValue
<
int
&>::
Get
();
BuiltInDefaultValue
<
int
&>::
Get
();
},
""
);
},
""
);
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
BuiltInDefaultValue
<
const
char
&>::
Get
();
BuiltInDefaultValue
<
const
char
&>::
Get
();
},
""
);
},
""
);
}
}
TEST
(
BuiltInDefaultValueDeathTest
,
IsUndefinedForUserTypes
)
{
TEST
(
BuiltInDefaultValueDeathTest
,
IsUndefinedForUserTypes
)
{
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
BuiltInDefaultValue
<
UserType
>::
Get
();
BuiltInDefaultValue
<
UserType
>::
Get
();
},
""
);
},
""
);
}
}
#endif // GTEST_HAS_DEATH_TEST
// Tests that DefaultValue<T>::IsSet() is false initially.
// Tests that DefaultValue<T>::IsSet() is false initially.
TEST
(
DefaultValueTest
,
IsInitiallyUnset
)
{
TEST
(
DefaultValueTest
,
IsInitiallyUnset
)
{
EXPECT_FALSE
(
DefaultValue
<
int
>::
IsSet
());
EXPECT_FALSE
(
DefaultValue
<
int
>::
IsSet
());
...
@@ -260,11 +256,9 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
...
@@ -260,11 +256,9 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
EXPECT_EQ
(
0
,
DefaultValue
<
int
>::
Get
());
EXPECT_EQ
(
0
,
DefaultValue
<
int
>::
Get
());
#if GTEST_HAS_DEATH_TEST
EXPECT_DEATH_IF_SUPPORTED
({
EXPECT_DEATH
({
// NOLINT
DefaultValue
<
UserType
>::
Get
();
DefaultValue
<
UserType
>::
Get
();
},
""
);
},
""
);
#endif // GTEST_HAS_DEATH_TEST
}
}
// Tests that DefaultValue<void>::Get() returns void.
// Tests that DefaultValue<void>::Get() returns void.
...
@@ -316,14 +310,12 @@ TEST(DefaultValueOfReferenceDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
...
@@ -316,14 +310,12 @@ TEST(DefaultValueOfReferenceDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
EXPECT_FALSE
(
DefaultValue
<
int
&>::
IsSet
());
EXPECT_FALSE
(
DefaultValue
<
int
&>::
IsSet
());
EXPECT_FALSE
(
DefaultValue
<
UserType
&>::
IsSet
());
EXPECT_FALSE
(
DefaultValue
<
UserType
&>::
IsSet
());
#if GTEST_HAS_DEATH_TEST
EXPECT_DEATH_IF_SUPPORTED
({
EXPECT_DEATH
({
// NOLINT
DefaultValue
<
int
&>::
Get
();
DefaultValue
<
int
&>::
Get
();
},
""
);
},
""
);
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
DefaultValue
<
UserType
>::
Get
();
DefaultValue
<
UserType
>::
Get
();
},
""
);
},
""
);
#endif // GTEST_HAS_DEATH_TEST
}
}
// Tests that ActionInterface can be implemented by defining the
// Tests that ActionInterface can be implemented by defining the
...
@@ -559,15 +551,13 @@ TEST(DoDefaultTest, ReturnsBuiltInDefaultValueByDefault) {
...
@@ -559,15 +551,13 @@ TEST(DoDefaultTest, ReturnsBuiltInDefaultValueByDefault) {
EXPECT_EQ
(
0
,
mock
.
IntFunc
(
true
));
EXPECT_EQ
(
0
,
mock
.
IntFunc
(
true
));
}
}
#if GTEST_HAS_DEATH_TEST
// Tests that DoDefault() aborts the process when there is no built-in
// Tests that DoDefault() aborts the process when there is no built-in
// default value for the return type.
// default value for the return type.
TEST
(
DoDefaultDeathTest
,
DiesForUnknowType
)
{
TEST
(
DoDefaultDeathTest
,
DiesForUnknowType
)
{
MockClass
mock
;
MockClass
mock
;
EXPECT_CALL
(
mock
,
Foo
())
EXPECT_CALL
(
mock
,
Foo
())
.
WillRepeatedly
(
DoDefault
());
.
WillRepeatedly
(
DoDefault
());
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
mock
.
Foo
();
mock
.
Foo
();
},
""
);
},
""
);
}
}
...
@@ -587,13 +577,11 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) {
...
@@ -587,13 +577,11 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) {
// EXPECT_DEATH() can only capture stderr, while Google Mock's
// EXPECT_DEATH() can only capture stderr, while Google Mock's
// errors are printed on stdout. Therefore we have to settle for
// errors are printed on stdout. Therefore we have to settle for
// not verifying the message.
// not verifying the message.
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
mock
.
IntFunc
(
true
);
mock
.
IntFunc
(
true
);
},
""
);
},
""
);
}
}
#endif // GTEST_HAS_DEATH_TEST
// Tests that DoDefault() returns the default value set by
// Tests that DoDefault() returns the default value set by
// DefaultValue<T>::Set() when it's not overriden by an ON_CALL().
// DefaultValue<T>::Set() when it's not overriden by an ON_CALL().
TEST
(
DoDefaultTest
,
ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne
)
{
TEST
(
DoDefaultTest
,
ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne
)
{
...
...
test/gmock-internal-utils_test.cc
View file @
04d6ed81
...
@@ -472,21 +472,17 @@ TEST(AssertTest, SucceedsOnTrue) {
...
@@ -472,21 +472,17 @@ TEST(AssertTest, SucceedsOnTrue) {
Assert
(
true
,
__FILE__
,
__LINE__
);
// This should succeed too.
Assert
(
true
,
__FILE__
,
__LINE__
);
// This should succeed too.
}
}
#if GTEST_HAS_DEATH_TEST
// Tests that Assert(false, ...) generates a fatal failure.
// Tests that Assert(false, ...) generates a fatal failure.
TEST
(
AssertTest
,
FailsFatallyOnFalse
)
{
TEST
(
AssertTest
,
FailsFatallyOnFalse
)
{
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
Assert
(
false
,
__FILE__
,
__LINE__
,
"This should fail."
);
Assert
(
false
,
__FILE__
,
__LINE__
,
"This should fail."
);
},
""
);
},
""
);
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
Assert
(
false
,
__FILE__
,
__LINE__
);
Assert
(
false
,
__FILE__
,
__LINE__
);
},
""
);
},
""
);
}
}
#endif // GTEST_HAS_DEATH_TEST
// Tests that Expect(true, ...) succeeds.
// Tests that Expect(true, ...) succeeds.
TEST
(
ExpectTest
,
SucceedsOnTrue
)
{
TEST
(
ExpectTest
,
SucceedsOnTrue
)
{
Expect
(
true
,
__FILE__
,
__LINE__
,
"This should succeed."
);
Expect
(
true
,
__FILE__
,
__LINE__
,
"This should succeed."
);
...
...
test/gmock-matchers_test.cc
View file @
04d6ed81
...
@@ -2678,15 +2678,13 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) {
...
@@ -2678,15 +2678,13 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) {
EXPECT_FALSE
(
matcher
.
Matches
(
42
));
EXPECT_FALSE
(
matcher
.
Matches
(
42
));
}
}
#if GTEST_HAS_DEATH_TEST
// Tests that the program aborts when ResultOf is passed
// Tests that the program aborts when ResultOf is passed
// a NULL function pointer.
// a NULL function pointer.
TEST
(
ResultOfDeathTest
,
DiesOnNullFunctionPointers
)
{
TEST
(
ResultOfDeathTest
,
DiesOnNullFunctionPointers
)
{
EXPECT_DEATH
(
EXPECT_DEATH
_IF_SUPPORTED
(
ResultOf
(
static_cast
<
string
(
*
)(
int
)
>
(
NULL
),
Eq
(
string
(
"foo"
))),
ResultOf
(
static_cast
<
string
(
*
)(
int
)
>
(
NULL
),
Eq
(
string
(
"foo"
))),
"NULL function pointer is passed into ResultOf
\\
(
\\
)
\\
."
);
"NULL function pointer is passed into ResultOf
\\
(
\\
)
\\
."
);
}
}
#endif // GTEST_HAS_DEATH_TEST
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// Tests that ResultOf(f, ...) compiles and works as expected when f is a
// function reference.
// function reference.
...
...
test/gmock-port_test.cc
View file @
04d6ed81
...
@@ -65,8 +65,6 @@ TEST(GmockCheckSyntaxTest, WorksWithSwitch) {
...
@@ -65,8 +65,6 @@ TEST(GmockCheckSyntaxTest, WorksWithSwitch) {
GMOCK_CHECK_
(
true
)
<<
"Check failed in switch case"
;
GMOCK_CHECK_
(
true
)
<<
"Check failed in switch case"
;
}
}
#if GTEST_HAS_DEATH_TEST
TEST
(
GmockCheckDeathTest
,
DiesWithCorrectOutputOnFailure
)
{
TEST
(
GmockCheckDeathTest
,
DiesWithCorrectOutputOnFailure
)
{
const
bool
a_false_condition
=
false
;
const
bool
a_false_condition
=
false
;
// MSVC and gcc use different formats to print source file locations.
// MSVC and gcc use different formats to print source file locations.
...
@@ -81,9 +79,12 @@ TEST(GmockCheckDeathTest, DiesWithCorrectOutputOnFailure) {
...
@@ -81,9 +79,12 @@ TEST(GmockCheckDeathTest, DiesWithCorrectOutputOnFailure) {
#endif // _MSC_VER
#endif // _MSC_VER
".*a_false_condition.*Extra info"
;
".*a_false_condition.*Extra info"
;
EXPECT_DEATH
(
GMOCK_CHECK_
(
a_false_condition
)
<<
"Extra info"
,
regex
);
EXPECT_DEATH_IF_SUPPORTED
(
GMOCK_CHECK_
(
a_false_condition
)
<<
"Extra info"
,
regex
);
}
}
#if GTEST_HAS_DEATH_TEST
TEST
(
GmockCheckDeathTest
,
LivesSilentlyOnSuccess
)
{
TEST
(
GmockCheckDeathTest
,
LivesSilentlyOnSuccess
)
{
EXPECT_EXIT
({
EXPECT_EXIT
({
GMOCK_CHECK_
(
true
)
<<
"Extra info"
;
GMOCK_CHECK_
(
true
)
<<
"Extra info"
;
...
...
test/gmock-spec-builders_test.cc
View file @
04d6ed81
...
@@ -197,19 +197,15 @@ TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
...
@@ -197,19 +197,15 @@ TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
},
".With() cannot appear more than once in an ON_CALL()"
);
},
".With() cannot appear more than once in an ON_CALL()"
);
}
}
#if GTEST_HAS_DEATH_TEST
TEST
(
OnCallSyntaxTest
,
WillByDefaultIsMandatory
)
{
TEST
(
OnCallSyntaxTest
,
WillByDefaultIsMandatory
)
{
MockA
a
;
MockA
a
;
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
ON_CALL
(
a
,
DoA
(
5
));
ON_CALL
(
a
,
DoA
(
5
));
a
.
DoA
(
5
);
a
.
DoA
(
5
);
},
""
);
},
""
);
}
}
#endif // GTEST_HAS_DEATH_TEST
TEST
(
OnCallSyntaxTest
,
WillByDefaultCanAppearAtMostOnce
)
{
TEST
(
OnCallSyntaxTest
,
WillByDefaultCanAppearAtMostOnce
)
{
MockA
a
;
MockA
a
;
...
@@ -1018,18 +1014,14 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
...
@@ -1018,18 +1014,14 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
#endif // GMOCK_HAS_REGEX
#endif // GMOCK_HAS_REGEX
#if GTEST_HAS_DEATH_TEST
TEST
(
UndefinedReturnValueTest
,
ReturnValueIsMandatory
)
{
TEST
(
UndefinedReturnValueTest
,
ReturnValueIsMandatory
)
{
MockA
a
;
MockA
a
;
// TODO(wan@google.com): We should really verify the output message,
// TODO(wan@google.com): We should really verify the output message,
// but we cannot yet due to that EXPECT_DEATH only captures stderr
// but we cannot yet due to that EXPECT_DEATH only captures stderr
// while Google Mock logs to stdout.
// while Google Mock logs to stdout.
EXPECT_DEATH
(
a
.
ReturnResult
(
1
),
""
);
EXPECT_DEATH
_IF_SUPPORTED
(
a
.
ReturnResult
(
1
),
""
);
}
}
#endif // GTEST_HAS_DEATH_TEST
// Tests that an excessive call (one whose arguments match the
// Tests that an excessive call (one whose arguments match the
// matchers but is called too many times) performs the default action.
// matchers but is called too many times) performs the default action.
TEST
(
ExcessiveCallTest
,
DoesDefaultAction
)
{
TEST
(
ExcessiveCallTest
,
DoesDefaultAction
)
{
...
@@ -1174,8 +1166,6 @@ TEST(SequenceTest, AnyOrderIsOkByDefault) {
...
@@ -1174,8 +1166,6 @@ TEST(SequenceTest, AnyOrderIsOkByDefault) {
}
}
}
}
#if GTEST_HAS_DEATH_TEST
// Tests that the calls must be in strict order when a complete order
// Tests that the calls must be in strict order when a complete order
// is specified.
// is specified.
TEST
(
SequenceTest
,
CallsMustBeInStrictOrderWhenSaidSo
)
{
TEST
(
SequenceTest
,
CallsMustBeInStrictOrderWhenSaidSo
)
{
...
@@ -1194,13 +1184,13 @@ TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo) {
...
@@ -1194,13 +1184,13 @@ TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo) {
.
InSequence
(
s
)
.
InSequence
(
s
)
.
WillOnce
(
Return
(
Result
()));
.
WillOnce
(
Return
(
Result
()));
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
a
.
ReturnResult
(
1
);
a
.
ReturnResult
(
1
);
a
.
ReturnResult
(
3
);
a
.
ReturnResult
(
3
);
a
.
ReturnResult
(
2
);
a
.
ReturnResult
(
2
);
},
""
);
},
""
);
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
a
.
ReturnResult
(
2
);
a
.
ReturnResult
(
2
);
a
.
ReturnResult
(
1
);
a
.
ReturnResult
(
1
);
a
.
ReturnResult
(
3
);
a
.
ReturnResult
(
3
);
...
@@ -1233,21 +1223,21 @@ TEST(SequenceTest, CallsMustConformToSpecifiedDag) {
...
@@ -1233,21 +1223,21 @@ TEST(SequenceTest, CallsMustConformToSpecifiedDag) {
.
InSequence
(
x
)
.
InSequence
(
x
)
.
WillOnce
(
Return
(
Result
()));
.
WillOnce
(
Return
(
Result
()));
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
a
.
ReturnResult
(
1
);
a
.
ReturnResult
(
1
);
b
.
DoB
();
b
.
DoB
();
a
.
ReturnResult
(
2
);
a
.
ReturnResult
(
2
);
},
""
);
},
""
);
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
a
.
ReturnResult
(
2
);
a
.
ReturnResult
(
2
);
},
""
);
},
""
);
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
a
.
ReturnResult
(
3
);
a
.
ReturnResult
(
3
);
},
""
);
},
""
);
EXPECT_DEATH
({
// NOLINT
EXPECT_DEATH
_IF_SUPPORTED
({
a
.
ReturnResult
(
1
);
a
.
ReturnResult
(
1
);
b
.
DoB
();
b
.
DoB
();
b
.
DoB
();
b
.
DoB
();
...
@@ -1261,8 +1251,6 @@ TEST(SequenceTest, CallsMustConformToSpecifiedDag) {
...
@@ -1261,8 +1251,6 @@ TEST(SequenceTest, CallsMustConformToSpecifiedDag) {
a
.
ReturnResult
(
3
);
a
.
ReturnResult
(
3
);
}
}
#endif // GTEST_HAS_DEATH_TEST
TEST
(
SequenceTest
,
Retirement
)
{
TEST
(
SequenceTest
,
Retirement
)
{
MockA
a
;
MockA
a
;
Sequence
s
;
Sequence
s
;
...
@@ -1429,8 +1417,6 @@ TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
...
@@ -1429,8 +1417,6 @@ TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
a
.
DoA
(
2
);
a
.
DoA
(
2
);
}
}
#if GTEST_HAS_DEATH_TEST
// Calls must be in strict order when specified so.
// Calls must be in strict order when specified so.
TEST
(
AfterDeathTest
,
CallsMustBeInStrictOrderWhenSpecifiedSo
)
{
TEST
(
AfterDeathTest
,
CallsMustBeInStrictOrderWhenSpecifiedSo
)
{
MockA
a
;
MockA
a
;
...
@@ -1498,8 +1484,6 @@ TEST(AfterDeathTest, CanBeUsedWithInSequence) {
...
@@ -1498,8 +1484,6 @@ TEST(AfterDeathTest, CanBeUsedWithInSequence) {
a
.
ReturnResult
(
3
);
a
.
ReturnResult
(
3
);
}
}
#endif // GTEST_HAS_DEATH_TEST
// .After() can be called multiple times.
// .After() can be called multiple times.
TEST
(
AfterTest
,
CanBeCalledManyTimes
)
{
TEST
(
AfterTest
,
CanBeCalledManyTimes
)
{
MockA
a
;
MockA
a
;
...
@@ -1536,8 +1520,6 @@ TEST(AfterTest, AcceptsUpToFiveArguments) {
...
@@ -1536,8 +1520,6 @@ TEST(AfterTest, AcceptsUpToFiveArguments) {
a
.
DoA
(
6
);
a
.
DoA
(
6
);
}
}
#if GTEST_HAS_DEATH_TEST
// .After() allows input to contain duplicated Expectations.
// .After() allows input to contain duplicated Expectations.
TEST
(
AfterTest
,
AcceptsDuplicatedInput
)
{
TEST
(
AfterTest
,
AcceptsDuplicatedInput
)
{
MockA
a
;
MockA
a
;
...
@@ -1557,8 +1539,6 @@ TEST(AfterTest, AcceptsDuplicatedInput) {
...
@@ -1557,8 +1539,6 @@ TEST(AfterTest, AcceptsDuplicatedInput) {
a
.
ReturnResult
(
3
);
a
.
ReturnResult
(
3
);
}
}
#endif // GTEST_HAS_DEATH_TEST
// An Expectation added to an ExpectationSet after it has been used in
// An Expectation added to an ExpectationSet after it has been used in
// an .After() has no effect.
// an .After() has no effect.
TEST
(
AfterTest
,
ChangesToExpectationSetHaveNoEffectAfterwards
)
{
TEST
(
AfterTest
,
ChangesToExpectationSetHaveNoEffectAfterwards
)
{
...
...
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