summaryrefslogtreecommitdiffstats
path: root/googlemock/test/gmock_link_test.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2023-11-27 21:31:59 (GMT)
committerCopybara-Service <copybara-worker@google.com>2023-11-27 21:32:49 (GMT)
commit76bb2afb8b522d24496ad1c757a49784fbfa2e42 (patch)
treedfc624e5c005a86b9a7680926625b1aaf881cd43 /googlemock/test/gmock_link_test.h
parentb10fad38c4026a29ea6561ab15fc4818170d1c10 (diff)
downloadgoogletest-76bb2afb8b522d24496ad1c757a49784fbfa2e42.zip
googletest-76bb2afb8b522d24496ad1c757a49784fbfa2e42.tar.gz
googletest-76bb2afb8b522d24496ad1c757a49784fbfa2e42.tar.bz2
Implement `testing::Rethrow` to throw exceptions more easily via `std::exception_ptr`
We avoid overloading or specializing `testing::Throw` as this is fundamentally a different operation than throwing the object. However, we disable the corresponding overload of `testing::Throw` to prevent likely mistakes in the usage. Fixes: #4412 PiperOrigin-RevId: 585745469 Change-Id: I03bb585427ce51983d914e88f2bf65a13545c920
Diffstat (limited to 'googlemock/test/gmock_link_test.h')
-rw-r--r--googlemock/test/gmock_link_test.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h
index db11c2d..cf0a985 100644
--- a/googlemock/test/gmock_link_test.h
+++ b/googlemock/test/gmock_link_test.h
@@ -187,6 +187,7 @@ using testing::SetErrnoAndReturn;
#if GTEST_HAS_EXCEPTIONS
using testing::Throw;
+using testing::Rethrow;
#endif
using testing::ContainsRegex;
@@ -416,6 +417,14 @@ TEST(LinkTest, TestThrow) {
EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
EXPECT_THROW(mock.VoidFromString(nullptr), int);
}
+// Tests the linkage of the Rethrow action.
+TEST(LinkTest, TestRethrow) {
+ Mock mock;
+
+ EXPECT_CALL(mock, VoidFromString(_))
+ .WillOnce(Rethrow(std::make_exception_ptr(42)));
+ EXPECT_THROW(mock.VoidFromString(nullptr), int);
+}
#endif // GTEST_HAS_EXCEPTIONS
// The ACTION*() macros trigger warning C4100 (unreferenced formal