Simplifies the tests using EXPECT_DEATH_IF_SUPPORTED.

This commit is contained in:
zhanyong.wan 2009-09-11 07:01:08 +00:00
parent d6ffd13698
commit 04d6ed817e
5 changed files with 23 additions and 60 deletions

View File

@ -199,26 +199,22 @@ TEST(BuiltInDefaultValueTest, UserTypeHasNoDefault) {
EXPECT_FALSE(BuiltInDefaultValue<UserType>::Exists());
}
#if GTEST_HAS_DEATH_TEST
// Tests that BuiltInDefaultValue<T&>::Get() aborts the program.
TEST(BuiltInDefaultValueDeathTest, IsUndefinedForReferences) {
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
BuiltInDefaultValue<int&>::Get();
}, "");
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
BuiltInDefaultValue<const char&>::Get();
}, "");
}
TEST(BuiltInDefaultValueDeathTest, IsUndefinedForUserTypes) {
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
BuiltInDefaultValue<UserType>::Get();
}, "");
}
#endif // GTEST_HAS_DEATH_TEST
// Tests that DefaultValue<T>::IsSet() is false initially.
TEST(DefaultValueTest, IsInitiallyUnset) {
EXPECT_FALSE(DefaultValue<int>::IsSet());
@ -260,11 +256,9 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
EXPECT_EQ(0, DefaultValue<int>::Get());
#if GTEST_HAS_DEATH_TEST
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
DefaultValue<UserType>::Get();
}, "");
#endif // GTEST_HAS_DEATH_TEST
}
// Tests that DefaultValue<void>::Get() returns void.
@ -316,14 +310,12 @@ TEST(DefaultValueOfReferenceDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
EXPECT_FALSE(DefaultValue<int&>::IsSet());
EXPECT_FALSE(DefaultValue<UserType&>::IsSet());
#if GTEST_HAS_DEATH_TEST
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
DefaultValue<int&>::Get();
}, "");
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
DefaultValue<UserType>::Get();
}, "");
#endif // GTEST_HAS_DEATH_TEST
}
// Tests that ActionInterface can be implemented by defining the
@ -559,15 +551,13 @@ TEST(DoDefaultTest, ReturnsBuiltInDefaultValueByDefault) {
EXPECT_EQ(0, mock.IntFunc(true));
}
#if GTEST_HAS_DEATH_TEST
// Tests that DoDefault() aborts the process when there is no built-in
// default value for the return type.
TEST(DoDefaultDeathTest, DiesForUnknowType) {
MockClass mock;
EXPECT_CALL(mock, Foo())
.WillRepeatedly(DoDefault());
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
mock.Foo();
}, "");
}
@ -587,13 +577,11 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) {
// EXPECT_DEATH() can only capture stderr, while Google Mock's
// errors are printed on stdout. Therefore we have to settle for
// not verifying the message.
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
mock.IntFunc(true);
}, "");
}
#endif // GTEST_HAS_DEATH_TEST
// Tests that DoDefault() returns the default value set by
// DefaultValue<T>::Set() when it's not overriden by an ON_CALL().
TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) {

View File

@ -472,21 +472,17 @@ TEST(AssertTest, SucceedsOnTrue) {
Assert(true, __FILE__, __LINE__); // This should succeed too.
}
#if GTEST_HAS_DEATH_TEST
// Tests that Assert(false, ...) generates a fatal failure.
TEST(AssertTest, FailsFatallyOnFalse) {
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
Assert(false, __FILE__, __LINE__, "This should fail.");
}, "");
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
Assert(false, __FILE__, __LINE__);
}, "");
}
#endif // GTEST_HAS_DEATH_TEST
// Tests that Expect(true, ...) succeeds.
TEST(ExpectTest, SucceedsOnTrue) {
Expect(true, __FILE__, __LINE__, "This should succeed.");

View File

@ -2678,15 +2678,13 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) {
EXPECT_FALSE(matcher.Matches(42));
}
#if GTEST_HAS_DEATH_TEST
// Tests that the program aborts when ResultOf is passed
// a NULL function pointer.
TEST(ResultOfDeathTest, DiesOnNullFunctionPointers) {
EXPECT_DEATH(
EXPECT_DEATH_IF_SUPPORTED(
ResultOf(static_cast<string(*)(int)>(NULL), Eq(string("foo"))),
"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
// function reference.

View File

@ -65,8 +65,6 @@ TEST(GmockCheckSyntaxTest, WorksWithSwitch) {
GMOCK_CHECK_(true) << "Check failed in switch case";
}
#if GTEST_HAS_DEATH_TEST
TEST(GmockCheckDeathTest, DiesWithCorrectOutputOnFailure) {
const bool a_false_condition = false;
// MSVC and gcc use different formats to print source file locations.
@ -81,9 +79,12 @@ TEST(GmockCheckDeathTest, DiesWithCorrectOutputOnFailure) {
#endif // _MSC_VER
".*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) {
EXPECT_EXIT({
GMOCK_CHECK_(true) << "Extra info";

View File

@ -197,19 +197,15 @@ TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
}, ".With() cannot appear more than once in an ON_CALL()");
}
#if GTEST_HAS_DEATH_TEST
TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) {
MockA a;
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
ON_CALL(a, DoA(5));
a.DoA(5);
}, "");
}
#endif // GTEST_HAS_DEATH_TEST
TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) {
MockA a;
@ -1018,18 +1014,14 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
#endif // GMOCK_HAS_REGEX
#if GTEST_HAS_DEATH_TEST
TEST(UndefinedReturnValueTest, ReturnValueIsMandatory) {
MockA a;
// TODO(wan@google.com): We should really verify the output message,
// but we cannot yet due to that EXPECT_DEATH only captures stderr
// 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
// matchers but is called too many times) performs the default action.
TEST(ExcessiveCallTest, DoesDefaultAction) {
@ -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
// is specified.
TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo) {
@ -1194,13 +1184,13 @@ TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo) {
.InSequence(s)
.WillOnce(Return(Result()));
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
a.ReturnResult(1);
a.ReturnResult(3);
a.ReturnResult(2);
}, "");
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
a.ReturnResult(2);
a.ReturnResult(1);
a.ReturnResult(3);
@ -1233,21 +1223,21 @@ TEST(SequenceTest, CallsMustConformToSpecifiedDag) {
.InSequence(x)
.WillOnce(Return(Result()));
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
a.ReturnResult(1);
b.DoB();
a.ReturnResult(2);
}, "");
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
a.ReturnResult(2);
}, "");
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
a.ReturnResult(3);
}, "");
EXPECT_DEATH({ // NOLINT
EXPECT_DEATH_IF_SUPPORTED({
a.ReturnResult(1);
b.DoB();
b.DoB();
@ -1261,8 +1251,6 @@ TEST(SequenceTest, CallsMustConformToSpecifiedDag) {
a.ReturnResult(3);
}
#endif // GTEST_HAS_DEATH_TEST
TEST(SequenceTest, Retirement) {
MockA a;
Sequence s;
@ -1429,8 +1417,6 @@ TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
a.DoA(2);
}
#if GTEST_HAS_DEATH_TEST
// Calls must be in strict order when specified so.
TEST(AfterDeathTest, CallsMustBeInStrictOrderWhenSpecifiedSo) {
MockA a;
@ -1498,8 +1484,6 @@ TEST(AfterDeathTest, CanBeUsedWithInSequence) {
a.ReturnResult(3);
}
#endif // GTEST_HAS_DEATH_TEST
// .After() can be called multiple times.
TEST(AfterTest, CanBeCalledManyTimes) {
MockA a;
@ -1536,8 +1520,6 @@ TEST(AfterTest, AcceptsUpToFiveArguments) {
a.DoA(6);
}
#if GTEST_HAS_DEATH_TEST
// .After() allows input to contain duplicated Expectations.
TEST(AfterTest, AcceptsDuplicatedInput) {
MockA a;
@ -1557,8 +1539,6 @@ TEST(AfterTest, AcceptsDuplicatedInput) {
a.ReturnResult(3);
}
#endif // GTEST_HAS_DEATH_TEST
// An Expectation added to an ExpectationSet after it has been used in
// an .After() has no effect.
TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) {