proxygen
EnsureTest.cpp File Reference
#include <memory>
#include <unordered_set>
#include <folly/futures/Future.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Functions

 TEST (Ensure, basic)
 
 TEST (Ensure, mutableLambda)
 

Function Documentation

TEST ( Ensure  ,
basic   
)

Definition at line 25 of file EnsureTest.cpp.

References count, EXPECT_EQ, EXPECT_THROW, f, folly::makeFuture(), and folly::gen::move.

25  {
26  size_t count = 0;
27  auto cob = [&] { count++; };
28  auto f = makeFuture(42)
29  .ensure(cob)
30  .then([](int) { throw std::runtime_error("ensure"); })
31  .ensure(cob);
32 
33  EXPECT_THROW(std::move(f).get(), std::runtime_error);
34  EXPECT_EQ(2, count);
35 }
auto f
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
int * count
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Ensure  ,
mutableLambda   
)

Definition at line 37 of file EnsureTest.cpp.

References EXPECT_EQ, EXPECT_THROW, f, folly::makeFuture(), and folly::gen::move.

37  {
38  auto set = std::make_shared<std::unordered_set<int>>();
39  set->insert(1);
40  set->insert(2);
41 
42  auto f = makeFuture(4)
43  .ensure([set]() mutable { set->clear(); })
44  .thenValue([](auto&&) { throw std::runtime_error("ensure"); });
45 
46  EXPECT_EQ(0, set->size());
47  EXPECT_THROW(std::move(f).get(), std::runtime_error);
48 }
auto f
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Definition: Traits.h:592
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310