summaryrefslogtreecommitdiff
path: root/test/gtest_unittest.cc
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-02-08 04:53:35 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-02-08 04:53:35 +0000
commitac60cef37792a6cb7f3534d3f4e2c6d69ab4b5e6 (patch)
tree60066126086cffa26e87bf47ac8e566aadeb2836 /test/gtest_unittest.cc
parente0ca02f7b4175a1c21f7416039f9f06c028b544a (diff)
downloadgoogletest-ac60cef37792a6cb7f3534d3f4e2c6d69ab4b5e6.tar.gz
Fixes the definition of GTEST_HAS_EXCEPTIONS, allowing exception assertions to be used with gcc.
git-svn-id: http://googletest.googlecode.com/svn/trunk@186 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'test/gtest_unittest.cc')
-rw-r--r--test/gtest_unittest.cc62
1 files changed, 35 insertions, 27 deletions
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index faf01a3..4bac8a6 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");
}