Skip to content

Commit 214fc91

Browse files
kentfredriccramertj
authored andcommitted
futures: tests/try_join_all.rs: Don't break w/o "executor"
- Symbols/Imports pushed down / localised - Tests gated with cfg() - Tests now build and pass with all valid feature combinations See previous commits for details and rationale
1 parent 438cc20 commit 214fc91

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

futures/tests/try_join_all.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
use futures_util::future::*;
2-
use std::future::Future;
3-
use futures::executor::block_on;
4-
use std::fmt::Debug;
5-
6-
fn assert_done<T, F>(actual_fut: F, expected: T)
7-
where
8-
T: PartialEq + Debug,
9-
F: FnOnce() -> Box<dyn Future<Output = T> + Unpin>,
10-
{
11-
let output = block_on(actual_fut());
12-
assert_eq!(output, expected);
1+
#[cfg(feature = "executor")] // executor::
2+
mod util {
3+
use std::future::Future;
4+
use futures::executor::block_on;
5+
use std::fmt::Debug;
6+
7+
pub fn assert_done<T, F>(actual_fut: F, expected: T)
8+
where
9+
T: PartialEq + Debug,
10+
F: FnOnce() -> Box<dyn Future<Output = T> + Unpin>,
11+
{
12+
let output = block_on(actual_fut());
13+
assert_eq!(output, expected);
14+
}
1315
}
1416

17+
#[cfg(feature = "executor")] // assert_done
1518
#[test]
1619
fn collect_collects() {
20+
use futures_util::future::{err, ok, try_join_all};
21+
22+
use util::assert_done;
23+
1724
assert_done(|| Box::new(try_join_all(vec![ok(1), ok(2)])), Ok::<_, usize>(vec![1, 2]));
1825
assert_done(|| Box::new(try_join_all(vec![ok(1), err(2)])), Err(2));
1926
assert_done(|| Box::new(try_join_all(vec![ok(1)])), Ok::<_, usize>(vec![1]));
@@ -23,8 +30,14 @@ fn collect_collects() {
2330
// TODO: needs more tests
2431
}
2532

33+
#[cfg(feature = "executor")] // assert_done
2634
#[test]
2735
fn try_join_all_iter_lifetime() {
36+
use futures_util::future::{ok, try_join_all};
37+
use std::future::Future;
38+
39+
use util::assert_done;
40+
2841
// In futures-rs version 0.1, this function would fail to typecheck due to an overly
2942
// conservative type parameterization of `TryJoinAll`.
3043
fn sizes<'a>(bufs: Vec<&'a [u8]>) -> Box<dyn Future<Output = Result<Vec<usize>, ()>> + Unpin> {
@@ -35,8 +48,13 @@ fn try_join_all_iter_lifetime() {
3548
assert_done(|| sizes(vec![&[1,2,3], &[], &[0]]), Ok(vec![3 as usize, 0, 1]));
3649
}
3750

51+
#[cfg(feature = "executor")] // assert_done
3852
#[test]
3953
fn try_join_all_from_iter() {
54+
use futures_util::future::{ok, TryJoinAll};
55+
56+
use util::assert_done;
57+
4058
assert_done(
4159
|| Box::new(vec![ok(1), ok(2)].into_iter().collect::<TryJoinAll<_>>()),
4260
Ok::<_, usize>(vec![1, 2]),

0 commit comments

Comments
 (0)