Commit 72320612 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot 5

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
parent e38ff539
......@@ -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; };
......
......@@ -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();
......
......@@ -16,17 +16,10 @@
#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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment