diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-02-08 04:53:35 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-02-08 04:53:35 +0000 |
commit | 886cafd4a37fd5e7325da1ae5a5a948b6c2bc895 (patch) | |
tree | 60066126086cffa26e87bf47ac8e566aadeb2836 /test/gtest_unittest.cc | |
parent | 37504994338c114247519331237831f88a9a7c40 (diff) | |
download | googletest-886cafd4a37fd5e7325da1ae5a5a948b6c2bc895.tar.gz googletest-886cafd4a37fd5e7325da1ae5a5a948b6c2bc895.tar.bz2 googletest-886cafd4a37fd5e7325da1ae5a5a948b6c2bc895.zip |
Fixes the definition of GTEST_HAS_EXCEPTIONS, allowing exception assertions to be used with gcc.
Diffstat (limited to 'test/gtest_unittest.cc')
-rw-r--r-- | test/gtest_unittest.cc | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index faf01a38..4bac8a69 100644 --- a/test/gtest_unittest.cc +++ b/test/gtest_unittest.cc @@ -2869,31 +2869,37 @@ TEST(AssertionTest, ASSERT_GT) { #if GTEST_HAS_EXCEPTIONS +void ThrowNothing() {} + + // Tests ASSERT_THROW. TEST(AssertionTest, ASSERT_THROW) { ASSERT_THROW(ThrowAnInteger(), int); - EXPECT_FATAL_FAILURE(ASSERT_THROW(ThrowAnInteger(), bool), - "Expected: ThrowAnInteger() throws an exception of type"\ - " bool.\n Actual: it throws a different type."); - EXPECT_FATAL_FAILURE(ASSERT_THROW(1, bool), - "Expected: 1 throws an exception of type bool.\n"\ - " Actual: it throws nothing."); + EXPECT_FATAL_FAILURE( + ASSERT_THROW(ThrowAnInteger(), bool), + "Expected: ThrowAnInteger() throws an exception of type bool.\n" + " Actual: it throws a different type."); + EXPECT_FATAL_FAILURE( + ASSERT_THROW(ThrowNothing(), bool), + "Expected: ThrowNothing() throws an exception of type bool.\n" + " Actual: it throws nothing."); } // Tests ASSERT_NO_THROW. TEST(AssertionTest, ASSERT_NO_THROW) { - ASSERT_NO_THROW(1); + ASSERT_NO_THROW(ThrowNothing()); EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()), - "Expected: ThrowAnInteger() doesn't throw an exception."\ + "Expected: ThrowAnInteger() doesn't throw an exception." "\n Actual: it throws."); } // Tests ASSERT_ANY_THROW. TEST(AssertionTest, ASSERT_ANY_THROW) { ASSERT_ANY_THROW(ThrowAnInteger()); - EXPECT_FATAL_FAILURE(ASSERT_ANY_THROW(1), - "Expected: 1 throws an exception.\n Actual: it "\ - "doesn't."); + EXPECT_FATAL_FAILURE( + ASSERT_ANY_THROW(ThrowNothing()), + "Expected: ThrowNothing() throws an exception.\n" + " Actual: it doesn't."); } #endif // GTEST_HAS_EXCEPTIONS @@ -3149,7 +3155,7 @@ TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) { TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) { if (false) - EXPECT_THROW(1, bool); + EXPECT_THROW(ThrowNothing(), bool); if (true) EXPECT_THROW(ThrowAnInteger(), int); @@ -3160,12 +3166,12 @@ TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) { EXPECT_NO_THROW(ThrowAnInteger()); if (true) - EXPECT_NO_THROW(1); + EXPECT_NO_THROW(ThrowNothing()); else ; if (false) - EXPECT_ANY_THROW(1); + EXPECT_ANY_THROW(ThrowNothing()); if (true) EXPECT_ANY_THROW(ThrowAnInteger()); @@ -3424,27 +3430,29 @@ TEST(ExpectTest, EXPECT_GT) { TEST(ExpectTest, EXPECT_THROW) { EXPECT_THROW(ThrowAnInteger(), int); EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool), - "Expected: ThrowAnInteger() throws an exception of "\ + "Expected: ThrowAnInteger() throws an exception of " "type bool.\n Actual: it throws a different type."); - EXPECT_NONFATAL_FAILURE(EXPECT_THROW(1, bool), - "Expected: 1 throws an exception of type bool.\n"\ - " Actual: it throws nothing."); + EXPECT_NONFATAL_FAILURE( + EXPECT_THROW(ThrowNothing(), bool), + "Expected: ThrowNothing() throws an exception of type bool.\n" + " Actual: it throws nothing."); } // Tests EXPECT_NO_THROW. TEST(ExpectTest, EXPECT_NO_THROW) { - EXPECT_NO_THROW(1); + EXPECT_NO_THROW(ThrowNothing()); EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()), - "Expected: ThrowAnInteger() doesn't throw an "\ + "Expected: ThrowAnInteger() doesn't throw an " "exception.\n Actual: it throws."); } // Tests EXPECT_ANY_THROW. TEST(ExpectTest, EXPECT_ANY_THROW) { EXPECT_ANY_THROW(ThrowAnInteger()); - EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(1), - "Expected: 1 throws an exception.\n Actual: it "\ - "doesn't."); + EXPECT_NONFATAL_FAILURE( + EXPECT_ANY_THROW(ThrowNothing()), + "Expected: ThrowNothing() throws an exception.\n" + " Actual: it doesn't."); } #endif // GTEST_HAS_EXCEPTIONS @@ -5056,8 +5064,8 @@ TEST(StreamingAssertionsTest, Throw) { } TEST(StreamingAssertionsTest, NoThrow) { - EXPECT_NO_THROW(1) << "unexpected failure"; - ASSERT_NO_THROW(1) << "unexpected failure"; + EXPECT_NO_THROW(ThrowNothing()) << "unexpected failure"; + ASSERT_NO_THROW(ThrowNothing()) << "unexpected failure"; EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()) << "expected failure", "expected failure"); EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()) << @@ -5067,9 +5075,9 @@ TEST(StreamingAssertionsTest, NoThrow) { TEST(StreamingAssertionsTest, AnyThrow) { EXPECT_ANY_THROW(ThrowAnInteger()) << "unexpected failure"; ASSERT_ANY_THROW(ThrowAnInteger()) << "unexpected failure"; - EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(1) << + EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(ThrowNothing()) << "expected failure", "expected failure"); - EXPECT_FATAL_FAILURE(ASSERT_ANY_THROW(1) << + EXPECT_FATAL_FAILURE(ASSERT_ANY_THROW(ThrowNothing()) << "expected failure", "expected failure"); } |