Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
92d0a6f7
Commit
92d0a6f7
authored
Jul 07, 2020
by
Vladimir Goncharov
Browse files
Add a test to ensure that the `Throws` matcher only invokes its argument once.
parent
69c510fb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
googlemock/test/gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+30
-0
No files found.
googlemock/test/gmock-matchers_test.cc
View file @
92d0a6f7
...
...
@@ -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;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment