From 723206127f727c66ec685038fdcaf72a9353e707 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 17 May 2016 17:04:40 -0700 Subject: [PATCH] Keep the Unit test suite free of Promise and Future Summary: [Folly] Keep the `Unit` test suite free of `Promise` and `Future`. Move the `Promise`-related tests to the `Promise` test suite and the `Future`-related tests to the `Future` test suite. Reviewed By: djwatson Differential Revision: D3313635 fbshipit-source-id: 05c82c8719719d7709063ad58a4806036ca10fb3 --- folly/futures/test/FutureTest.cpp | 37 +++++++++++++++++++++++++ folly/futures/test/PromiseTest.cpp | 5 ++++ folly/futures/test/UnitTest.cpp | 44 ------------------------------ 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index 950400a3..2f1eaf12 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,42 @@ static eggs_t eggs("eggs"); // Future +TEST(Future, futureDefaultCtor) { + Future(); +} + +TEST(Future, futureToUnit) { + Future fu = makeFuture(42).unit(); + fu.value(); + EXPECT_TRUE(makeFuture(eggs).unit().hasException()); +} + +TEST(Future, voidFutureToUnit) { + Future fu = makeFuture().unit(); + fu.value(); + EXPECT_TRUE(makeFuture(eggs).unit().hasException()); +} + +TEST(Future, unitFutureToUnitIdentity) { + Future fu = makeFuture(Unit{}).unit(); + fu.value(); + EXPECT_TRUE(makeFuture(eggs).unit().hasException()); +} + +TEST(Future, toUnitWhileInProgress) { + Promise p; + Future fu = p.getFuture().unit(); + EXPECT_FALSE(fu.isReady()); + p.setValue(42); + EXPECT_TRUE(fu.isReady()); +} + +TEST(Future, makeFutureWithUnit) { + int count = 0; + Future fu = makeFutureWith([&] { count++; }); + EXPECT_EQ(1, count); +} + TEST(Future, onError) { bool theFlag = false; auto flag = [&]{ theFlag = true; }; diff --git a/folly/futures/test/PromiseTest.cpp b/folly/futures/test/PromiseTest.cpp index 2f3d17a5..126518c0 100644 --- a/folly/futures/test/PromiseTest.cpp +++ b/folly/futures/test/PromiseTest.cpp @@ -38,6 +38,11 @@ TEST(Promise, getFuture) { EXPECT_FALSE(f.isReady()); } +TEST(Promise, setValueUnit) { + Promise p; + p.setValue(); +} + TEST(Promise, setValue) { Promise fund; auto ffund = fund.getFuture(); diff --git a/folly/futures/test/UnitTest.cpp b/folly/futures/test/UnitTest.cpp index 9eb74dc5..ba372fbb 100644 --- a/folly/futures/test/UnitTest.cpp +++ b/folly/futures/test/UnitTest.cpp @@ -16,17 +16,10 @@ #include -#include #include using namespace folly; -std::runtime_error eggs("eggs"); - -TEST(Unit, futureDefaultCtor) { - Future(); -} - TEST(Unit, operatorEq) { EXPECT_TRUE(Unit{} == Unit{}); } @@ -35,11 +28,6 @@ TEST(Unit, operatorNe) { EXPECT_FALSE(Unit{} != Unit{}); } -TEST(Unit, promiseSetValue) { - Promise p; - p.setValue(); -} - TEST(Unit, liftInt) { using lifted = Unit::Lift; using actual = std::is_same; @@ -75,35 +63,3 @@ TEST(Unit, dropVoid) { using actual = std::is_same; EXPECT_TRUE(actual::value); } - -TEST(Unit, futureToUnit) { - Future fu = makeFuture(42).unit(); - fu.value(); - EXPECT_TRUE(makeFuture(eggs).unit().hasException()); -} - -TEST(Unit, voidFutureToUnit) { - Future fu = makeFuture().unit(); - fu.value(); - EXPECT_TRUE(makeFuture(eggs).unit().hasException()); -} - -TEST(Unit, unitFutureToUnitIdentity) { - Future fu = makeFuture(Unit{}).unit(); - fu.value(); - EXPECT_TRUE(makeFuture(eggs).unit().hasException()); -} - -TEST(Unit, toUnitWhileInProgress) { - Promise p; - Future fu = p.getFuture().unit(); - EXPECT_FALSE(fu.isReady()); - p.setValue(42); - EXPECT_TRUE(fu.isReady()); -} - -TEST(Unit, makeFutureWith) { - int count = 0; - Future fu = makeFutureWith([&]{ count++; }); - EXPECT_EQ(1, count); -} -- 2.34.1