futures: tests/io_read.rs: Don't break w/o "std"
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
+#[cfg(feature = "std")]
+mod mock_reader {
use futures::io::AsyncRead;
-use futures_test::task::panic_context;
use std::io;
use std::pin::Pin;
use std::task::{Context, Poll};
-struct MockReader {
+ pub struct MockReader {
fun: Box<dyn FnMut(&mut [u8]) -> Poll<io::Result<usize>>>,
}
@@ -23,11 +24,21 @@ impl AsyncRead for MockReader {
(self.get_mut().fun)(buf)
}
}
+}
/// Verifies that the default implementation of `poll_read_vectored`
/// calls `poll_read` with an empty slice if no buffers are provided.
+#[cfg(feature = "std")]
#[test]
fn read_vectored_no_buffers() {
+ use futures::io::AsyncRead;
+ use futures_test::task::panic_context;
+ use std::io;
+ use std::pin::Pin;
+ use std::task::Poll;
+
+ use mock_reader::MockReader;
+
let mut reader = MockReader::new(|buf| {
assert_eq!(buf, b"");
Err(io::ErrorKind::BrokenPipe.into()).into()
@@ -42,8 +53,17 @@ fn read_vectored_no_buffers() {
/// Verifies that the default implementation of `poll_read_vectored`
/// calls `poll_read` with the first non-empty buffer.
+#[cfg(feature = "std")]
#[test]
fn read_vectored_first_non_empty() {
+ use futures::io::AsyncRead;
+ use futures_test::task::panic_context;
+ use std::io;
+ use std::pin::Pin;
+ use std::task::Poll;
+
+ use mock_reader::MockReader;
+
let mut reader = MockReader::new(|buf| {
assert_eq!(buf.len(), 4);
buf.copy_from_slice(b"four");
