Simplifies the tests using EXPECT_DEATH_IF_SUPPORTED.
diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc
index 9bf4c32..772f060 100644
--- a/test/gmock-actions_test.cc
+++ b/test/gmock-actions_test.cc
@@ -199,26 +199,22 @@
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 @@
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 @@
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 @@
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 @@
// 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) {
diff --git a/test/gmock-internal-utils_test.cc b/test/gmock-internal-utils_test.cc
index c949dd7..4867e11 100644
--- a/test/gmock-internal-utils_test.cc
+++ b/test/gmock-internal-utils_test.cc
@@ -472,21 +472,17 @@
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 ac5fd11..8926e94 100644
--- a/test/gmock-matchers_test.cc
+++ b/test/gmock-matchers_test.cc
@@ -2678,15 +2678,13 @@
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.
diff --git a/test/gmock-port_test.cc b/test/gmock-port_test.cc
index 2e85bcc..7335405 100644
--- a/test/gmock-port_test.cc
+++ b/test/gmock-port_test.cc
@@ -65,8 +65,6 @@
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 @@
#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 f9c595e..3f2918f 100644
--- a/test/gmock-spec-builders_test.cc
+++ b/test/gmock-spec-builders_test.cc
@@ -197,19 +197,15 @@
}, ".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 @@
#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 @@
}
}
-#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 @@
.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 @@
.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 @@
a.ReturnResult(3);
}
-#endif // GTEST_HAS_DEATH_TEST
-
TEST(SequenceTest, Retirement) {
MockA a;
Sequence s;
@@ -1429,8 +1417,6 @@
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 @@
a.ReturnResult(3);
}
-#endif // GTEST_HAS_DEATH_TEST
-
// .After() can be called multiple times.
TEST(AfterTest, CanBeCalledManyTimes) {
MockA a;
@@ -1536,8 +1520,6 @@
a.DoA(6);
}
-#if GTEST_HAS_DEATH_TEST
-
// .After() allows input to contain duplicated Expectations.
TEST(AfterTest, AcceptsDuplicatedInput) {
MockA a;
@@ -1557,8 +1539,6 @@
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) {