"docs/static/img/README.md" did not exist on "eb77376e026657a1c5b1317104a46868629c3439"
Commit 92d0a6f7 authored by Vladimir Goncharov's avatar Vladimir Goncharov
Browse files

Add a test to ensure that the `Throws` matcher only invokes its argument once.

parent 69c510fb
......@@ -8145,6 +8145,36 @@ TEST(ThrowsTest, DoesNotGenerateDuplicateCatchClauseWarning) {
Throws<std::exception>());
}
TEST(ThrowsTest, CallableExecutedExactlyOnce) {
size_t a = 0;
EXPECT_THAT(
[&a]() { a++; throw 10; },
Throws<int>());
EXPECT_EQ(a, 1);
EXPECT_THAT(
[&a]() { a++; throw std::runtime_error("message"); },
Throws<std::runtime_error>());
EXPECT_EQ(a, 2);
EXPECT_THAT(
[&a]() { a++; throw std::runtime_error("message"); },
ThrowsMessage<std::runtime_error>(HasSubstr("message")));
EXPECT_EQ(a, 3);
EXPECT_THAT(
[&a]() { a++; throw std::runtime_error("message"); },
ThrowsMessageHasSubstr<std::runtime_error>("message"));
EXPECT_EQ(a, 4);
EXPECT_THAT(
[&a]() { a++; throw std::runtime_error("message"); },
Throws<std::runtime_error>(
Property(&std::runtime_error::what, HasSubstr("message"))));
EXPECT_EQ(a, 5);
}
TEST(ThrowsTest, Describe) {
Matcher<void (*)()> matcher = Throws<std::runtime_error>();
std::stringstream ss;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment