From 04d6ed817e40f676225e0bf20ff1470d8f0c4a20 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 11 Sep 2009 07:01:08 +0000 Subject: [PATCH] Simplifies the tests using EXPECT_DEATH_IF_SUPPORTED. --- test/gmock-actions_test.cc | 28 +++++++----------------- test/gmock-internal-utils_test.cc | 8 ++----- test/gmock-matchers_test.cc | 4 +--- test/gmock-port_test.cc | 7 +++--- test/gmock-spec-builders_test.cc | 36 +++++++------------------------ 5 files changed, 23 insertions(+), 60 deletions(-) diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc index 9bf4c32d..772f0605 100644 --- a/test/gmock-actions_test.cc +++ b/test/gmock-actions_test.cc @@ -199,26 +199,22 @@ TEST(BuiltInDefaultValueTest, UserTypeHasNoDefault) { EXPECT_FALSE(BuiltInDefaultValue::Exists()); } -#if GTEST_HAS_DEATH_TEST - // Tests that BuiltInDefaultValue::Get() aborts the program. TEST(BuiltInDefaultValueDeathTest, IsUndefinedForReferences) { - EXPECT_DEATH({ // NOLINT + EXPECT_DEATH_IF_SUPPORTED({ BuiltInDefaultValue::Get(); }, ""); - EXPECT_DEATH({ // NOLINT + EXPECT_DEATH_IF_SUPPORTED({ BuiltInDefaultValue::Get(); }, ""); } TEST(BuiltInDefaultValueDeathTest, IsUndefinedForUserTypes) { - EXPECT_DEATH({ // NOLINT + EXPECT_DEATH_IF_SUPPORTED({ BuiltInDefaultValue::Get(); }, ""); } -#endif // GTEST_HAS_DEATH_TEST - // Tests that DefaultValue::IsSet() is false initially. TEST(DefaultValueTest, IsInitiallyUnset) { EXPECT_FALSE(DefaultValue::IsSet()); @@ -260,11 +256,9 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) { EXPECT_EQ(0, DefaultValue::Get()); -#if GTEST_HAS_DEATH_TEST - EXPECT_DEATH({ // NOLINT + EXPECT_DEATH_IF_SUPPORTED({ DefaultValue::Get(); }, ""); -#endif // GTEST_HAS_DEATH_TEST } // Tests that DefaultValue::Get() returns void. @@ -316,14 +310,12 @@ TEST(DefaultValueOfReferenceDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) { EXPECT_FALSE(DefaultValue::IsSet()); EXPECT_FALSE(DefaultValue::IsSet()); -#if GTEST_HAS_DEATH_TEST - EXPECT_DEATH({ // NOLINT + EXPECT_DEATH_IF_SUPPORTED({ DefaultValue::Get(); }, ""); - EXPECT_DEATH({ // NOLINT + EXPECT_DEATH_IF_SUPPORTED({ DefaultValue::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::Set() when it's not overriden by an ON_CALL(). TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) { diff --git a/test/gmock-internal-utils_test.cc b/test/gmock-internal-utils_test.cc index c949dd75..4867e119 100644 --- a/test/gmock-internal-utils_test.cc +++ b/test/gmock-internal-utils_test.cc @@ -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."); diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc index ac5fd110..8926e944 100644 --- a/test/gmock-matchers_test.cc +++ b/test/gmock-matchers_test.cc @@ -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(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. diff --git a/test/gmock-port_test.cc b/test/gmock-port_test.cc index 2e85bccd..7335405c 100644 --- a/test/gmock-port_test.cc +++ b/test/gmock-port_test.cc @@ -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"; diff --git a/test/gmock-spec-builders_test.cc b/test/gmock-spec-builders_test.cc index f9c595eb..3f2918fa 100644 --- a/test/gmock-spec-builders_test.cc +++ b/test/gmock-spec-builders_test.cc @@ -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) {