diff options
author | Gennadiy Civil <gennadiycivil@users.noreply.github.com> | 2018-09-25 07:10:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-25 07:10:15 (GMT) |
commit | a4f57cf49a4533cbc6e21c5eb6d964eda6898bda (patch) | |
tree | 06d264f0b035b73c1269e03fba8b739f8d19221c /googletest/test | |
parent | 90943525c5d1fa4362cbc5c4b313dab761c02295 (diff) | |
parent | b19266a3e3fda6ff9c97b2c1655ef5e7b4444c46 (diff) | |
download | googletest-a4f57cf49a4533cbc6e21c5eb6d964eda6898bda.zip googletest-a4f57cf49a4533cbc6e21c5eb6d964eda6898bda.tar.gz googletest-a4f57cf49a4533cbc6e21c5eb6d964eda6898bda.tar.bz2 |
Merge branch 'master' into python3-tests
Diffstat (limited to 'googletest/test')
-rw-r--r-- | googletest/test/gtest_unittest.cc | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index c03b367..f2c4435 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3328,6 +3328,7 @@ TEST_F(SingleEvaluationTest, OtherCases) { void ThrowAnInteger() { throw 1; } +void ThrowAnException(const char* what) { throw std::runtime_error(what); } // Tests that assertion arguments are evaluated exactly once. TEST_F(SingleEvaluationTest, ExceptionTests) { @@ -3370,6 +3371,26 @@ 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 @@ -3802,6 +3823,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("b"), bool), + "Expected: ThrowAnException(\"b\") throws an exception of type bool.\n" + " Actual: it throws a different type with message: b"); } // Tests ASSERT_NO_THROW. @@ -3810,6 +3836,9 @@ TEST(AssertionTest, ASSERT_NO_THROW) { EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an exception." "\n Actual: it throws."); + EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnException("blablubb")), + "Expected: ThrowAnException(\"blablubb\") doesn't throw" + " an exception.\n Actual: it throws: blablubb"); } // Tests ASSERT_ANY_THROW. @@ -4536,13 +4565,17 @@ 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."); + 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. @@ -4551,6 +4584,9 @@ TEST(ExpectTest, EXPECT_NO_THROW) { EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an " "exception.\n Actual: it throws."); + EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnException("blah")), + "Expected: ThrowAnException(\"blah\") doesn't " + "throw an exception.\n Actual: it throws: blah"); } // Tests EXPECT_ANY_THROW. |