mirror of
https://github.com/google/googletest.git
synced 2024-12-27 10:11:03 +08:00
Add a test to ensure that the Throws
matcher only invokes its argument once.
This commit is contained in:
parent
69c510fb51
commit
92d0a6f7e2
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user