X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Ffutures%2Ftest%2FEnsureTest.cpp;h=99ed4602fc67081248ee4872895f6dc779c8e50f;hp=b3fa6b0cc302d6906d66c96685a50c6836508fc5;hb=9ca0389d8d29d27aceef3f86e21d75af6737cbd5;hpb=c23b7977ce59f1888e75770059a745b5889a96c7 diff --git a/folly/futures/test/EnsureTest.cpp b/folly/futures/test/EnsureTest.cpp index b3fa6b0c..99ed4602 100644 --- a/folly/futures/test/EnsureTest.cpp +++ b/folly/futures/test/EnsureTest.cpp @@ -14,15 +14,19 @@ * limitations under the License. */ +#include +#include + #include +#include #include using namespace folly; TEST(Ensure, basic) { size_t count = 0; - auto cob = [&]{ count++; }; + auto cob = [&] { count++; }; auto f = makeFuture(42) .ensure(cob) .then([](int) { throw std::runtime_error("ensure"); }) @@ -31,3 +35,16 @@ TEST(Ensure, basic) { EXPECT_THROW(f.get(), std::runtime_error); EXPECT_EQ(2, count); } + +TEST(Ensure, mutableLambda) { + auto set = std::make_shared>(); + set->insert(1); + set->insert(2); + + auto f = makeFuture(4) + .ensure([set]() mutable { set->clear(); }) + .then([]() { throw std::runtime_error("ensure"); }); + + EXPECT_EQ(0, set->size()); + EXPECT_THROW(f.get(), std::runtime_error); +}