diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index cd89d81e..21ade890 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -8145,6 +8145,36 @@ TEST(ThrowsTest, DoesNotGenerateDuplicateCatchClauseWarning) { Throws()); } +TEST(ThrowsTest, CallableExecutedExactlyOnce) { + size_t a = 0; + + EXPECT_THAT( + [&a]() { a++; throw 10; }, + Throws()); + EXPECT_EQ(a, 1); + + EXPECT_THAT( + [&a]() { a++; throw std::runtime_error("message"); }, + Throws()); + EXPECT_EQ(a, 2); + + EXPECT_THAT( + [&a]() { a++; throw std::runtime_error("message"); }, + ThrowsMessage(HasSubstr("message"))); + EXPECT_EQ(a, 3); + + EXPECT_THAT( + [&a]() { a++; throw std::runtime_error("message"); }, + ThrowsMessageHasSubstr("message")); + EXPECT_EQ(a, 4); + + EXPECT_THAT( + [&a]() { a++; throw std::runtime_error("message"); }, + Throws( + Property(&std::runtime_error::what, HasSubstr("message")))); + EXPECT_EQ(a, 5); +} + TEST(ThrowsTest, Describe) { Matcher matcher = Throws(); std::stringstream ss;