Keep the Unit test suite free of Promise and Future
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 18 May 2016 00:04:40 +0000 (17:04 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Wed, 18 May 2016 00:08:27 +0000 (17:08 -0700)
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
folly/futures/test/PromiseTest.cpp
folly/futures/test/UnitTest.cpp

index 950400a32b23e00d18769b39447ed2df680191b2..2f1eaf129796c302720b4cc07fad56fb34ec9759 100644 (file)
@@ -17,6 +17,7 @@
 #include <gtest/gtest.h>
 
 #include <folly/futures/Future.h>
+#include <folly/futures/Unit.h>
 #include <folly/Memory.h>
 #include <folly/Executor.h>
 #include <folly/dynamic.h>
@@ -41,6 +42,42 @@ static eggs_t eggs("eggs");
 
 // Future
 
+TEST(Future, futureDefaultCtor) {
+  Future<Unit>();
+}
+
+TEST(Future, futureToUnit) {
+  Future<Unit> fu = makeFuture(42).unit();
+  fu.value();
+  EXPECT_TRUE(makeFuture<int>(eggs).unit().hasException());
+}
+
+TEST(Future, voidFutureToUnit) {
+  Future<Unit> fu = makeFuture().unit();
+  fu.value();
+  EXPECT_TRUE(makeFuture<Unit>(eggs).unit().hasException());
+}
+
+TEST(Future, unitFutureToUnitIdentity) {
+  Future<Unit> fu = makeFuture(Unit{}).unit();
+  fu.value();
+  EXPECT_TRUE(makeFuture<Unit>(eggs).unit().hasException());
+}
+
+TEST(Future, toUnitWhileInProgress) {
+  Promise<int> p;
+  Future<Unit> fu = p.getFuture().unit();
+  EXPECT_FALSE(fu.isReady());
+  p.setValue(42);
+  EXPECT_TRUE(fu.isReady());
+}
+
+TEST(Future, makeFutureWithUnit) {
+  int count = 0;
+  Future<Unit> fu = makeFutureWith([&] { count++; });
+  EXPECT_EQ(1, count);
+}
+
 TEST(Future, onError) {
   bool theFlag = false;
   auto flag = [&]{ theFlag = true; };
index 2f3d17a53110a32e56ca45387eb7d1d3ec25b049..126518c0fc54082f3c7b3bab73be931df637b4b8 100644 (file)
@@ -38,6 +38,11 @@ TEST(Promise, getFuture) {
   EXPECT_FALSE(f.isReady());
 }
 
+TEST(Promise, setValueUnit) {
+  Promise<Unit> p;
+  p.setValue();
+}
+
 TEST(Promise, setValue) {
   Promise<int> fund;
   auto ffund = fund.getFuture();
index 9eb74dc55e679a78cdc2d4674befb08dce52e8ad..ba372fbb8d321c3686811d93ee0bc08051752ae4 100644 (file)
 
 #include <gtest/gtest.h>
 
-#include <folly/futures/Future.h>
 #include <folly/futures/Unit.h>
 
 using namespace folly;
 
-std::runtime_error eggs("eggs");
-
-TEST(Unit, futureDefaultCtor) {
-  Future<Unit>();
-}
-
 TEST(Unit, operatorEq) {
   EXPECT_TRUE(Unit{} == Unit{});
 }
@@ -35,11 +28,6 @@ TEST(Unit, operatorNe) {
   EXPECT_FALSE(Unit{} != Unit{});
 }
 
-TEST(Unit, promiseSetValue) {
-  Promise<Unit> p;
-  p.setValue();
-}
-
 TEST(Unit, liftInt) {
   using lifted = Unit::Lift<int>;
   using actual = std::is_same<int, lifted::type>;
@@ -75,35 +63,3 @@ TEST(Unit, dropVoid) {
   using actual = std::is_same<void, dropped::type>;
   EXPECT_TRUE(actual::value);
 }
-
-TEST(Unit, futureToUnit) {
-  Future<Unit> fu = makeFuture(42).unit();
-  fu.value();
-  EXPECT_TRUE(makeFuture<int>(eggs).unit().hasException());
-}
-
-TEST(Unit, voidFutureToUnit) {
-  Future<Unit> fu = makeFuture().unit();
-  fu.value();
-  EXPECT_TRUE(makeFuture<Unit>(eggs).unit().hasException());
-}
-
-TEST(Unit, unitFutureToUnitIdentity) {
-  Future<Unit> fu = makeFuture(Unit{}).unit();
-  fu.value();
-  EXPECT_TRUE(makeFuture<Unit>(eggs).unit().hasException());
-}
-
-TEST(Unit, toUnitWhileInProgress) {
-  Promise<int> p;
-  Future<Unit> fu = p.getFuture().unit();
-  EXPECT_FALSE(fu.isReady());
-  p.setValue(42);
-  EXPECT_TRUE(fu.isReady());
-}
-
-TEST(Unit, makeFutureWith) {
-  int count = 0;
-  Future<Unit> fu = makeFutureWith([&]{ count++; });
-  EXPECT_EQ(1, count);
-}