summaryrefslogtreecommitdiffstats
path: root/googletest/test
diff options
context:
space:
mode:
authorJonny007-MKD <me@jonny007-mkd.de>2018-09-14 21:22:04 (GMT)
committerJonny007-MKD <me@jonny007-mkd.de>2018-09-14 21:22:04 (GMT)
commit6494f5232b130a29321e661166442bac324c4383 (patch)
treea641bcc7d9d5513c83d463a6194950aeb5344df0 /googletest/test
parent631e3a58389a21bec310470b7788b30dfa17a217 (diff)
downloadgoogletest-6494f5232b130a29321e661166442bac324c4383.zip
googletest-6494f5232b130a29321e661166442bac324c4383.tar.gz
googletest-6494f5232b130a29321e661166442bac324c4383.tar.bz2
Print message of unexpected std::exception in EXPECT_THROW, too
Diffstat (limited to 'googletest/test')
-rw-r--r--googletest/test/gtest_unittest.cc34
1 files changed, 28 insertions, 6 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index bd1117b..6b75ab4 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -3373,6 +3373,20 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
// failed EXPECT_ANY_THROW
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't");
EXPECT_EQ(7, a_);
+
+ // failed EXPECT_THROW std::exception, throws different
+ EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT
+ a_++;
+ ThrowAnInteger();
+ }, std::exception), "throws a different type");
+ EXPECT_EQ(8, a_);
+
+ // failed EXPECT_THROW, throws std::exception
+ EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT
+ a_++;
+ ThrowAnException("blablubb");
+ }, bool), "throws a different type with message: blablubb");
+ EXPECT_EQ(9, a_);
}
#endif // GTEST_HAS_EXCEPTIONS
@@ -3805,6 +3819,11 @@ TEST(AssertionTest, ASSERT_THROW) {
ASSERT_THROW(ThrowNothing(), bool),
"Expected: ThrowNothing() throws an exception of type bool.\n"
" Actual: it throws nothing.");
+
+ EXPECT_FATAL_FAILURE(
+ ASSERT_THROW(ThrowAnException("buuh"), bool),
+ "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n"
+ " Actual: it throws a different type with message: buuh");
}
// Tests ASSERT_NO_THROW.
@@ -4542,13 +4561,16 @@ TEST(ExpectTest, EXPECT_GT) {
// Tests EXPECT_THROW.
TEST(ExpectTest, EXPECT_THROW) {
EXPECT_THROW(ThrowAnInteger(), int);
+ EXPECT_THROW(ThrowAnException(""), std::exception);
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
- "Expected: ThrowAnInteger() throws an exception of "
- "type bool.\n Actual: it throws a different type.");
- EXPECT_NONFATAL_FAILURE(
- EXPECT_THROW(ThrowNothing(), bool),
- "Expected: ThrowNothing() throws an exception of type bool.\n"
- " Actual: it throws nothing.");
+ "Expected: ThrowAnInteger() throws an exception of type bool.\n"
+ " Actual: it throws a different type.");
+ EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowNothing(), bool),
+ "Expected: ThrowNothing() throws an exception of type bool.\n"
+ " Actual: it throws nothing.");
+ EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnException("buuh"), bool),
+ "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n"
+ " Actual: it throws a different type with message: buuh");
}
// Tests EXPECT_NO_THROW.