Commit 5f99ab65 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

add a test case for SCOPE_FAIL with std::rethrow_exception()

Summary:
Make sure SCOPE_FAIL works with std::rethrow_exception().

When compiled with older versions of gcc this code would fail due to a gcc
bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62258
The gcc bug was fixed in 4.9.4, 5.3, and the 6.0 branch.

Reviewed By: meyering

Differential Revision: D3280778

fbshipit-source-id: 8fe1a9c1dc3ada61c8ebd7318538ae959b29a6b1
parent e9eae3ac
......@@ -18,8 +18,10 @@
#include <glog/logging.h>
#include <condition_variable>
#include <functional>
#include <stdexcept>
#include <thread>
#include <folly/portability/GTest.h>
......@@ -293,6 +295,30 @@ void testScopeFailAndScopeSuccess(ErrorBehavior error, bool expectFail) {
EXPECT_EQ(!expectFail, scopeSuccessExecuted);
}
TEST(ScopeGuard, TEST_SCOPE_FAIL_EXCEPTION_PTR) {
bool catchExecuted = false;
bool failExecuted = false;
try {
SCOPE_FAIL {
failExecuted = true;
};
std::exception_ptr ep;
try {
throw std::runtime_error("test");
} catch (...) {
ep = std::current_exception();
}
std::rethrow_exception(ep);
} catch (const std::exception& ex) {
catchExecuted = true;
}
EXPECT_TRUE(catchExecuted);
EXPECT_TRUE(failExecuted);
}
TEST(ScopeGuard, TEST_SCOPE_FAIL_AND_SCOPE_SUCCESS) {
testScopeFailAndScopeSuccess(ErrorBehavior::SUCCESS, false);
testScopeFailAndScopeSuccess(ErrorBehavior::HANDLED_ERROR, false);
......
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