-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- google::ParseCommandLineFlags(&argc, &argv, true);
- return RUN_ALL_TESTS();
+TEST(ScopeGuard, TEST_THROWING_CLEANUP_ACTION) {
+ struct ThrowingCleanupAction {
+ explicit ThrowingCleanupAction(int& scopeExitExecuted)
+ : scopeExitExecuted_(scopeExitExecuted) {}
+ ThrowingCleanupAction(const ThrowingCleanupAction& other)
+ : scopeExitExecuted_(other.scopeExitExecuted_) {
+ throw std::runtime_error("whoa");
+ }
+ void operator()() { ++scopeExitExecuted_; }
+
+ private:
+ int& scopeExitExecuted_;
+ };
+ int scopeExitExecuted = 0;
+ ThrowingCleanupAction onExit(scopeExitExecuted);
+ EXPECT_THROW(makeGuard(onExit), std::runtime_error);
+ EXPECT_EQ(scopeExitExecuted, 1);