Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize tokio::fs::file's mock tests. #3988

Merged
merged 5 commits into from
Jul 31, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't use cfg-if
  • Loading branch information
asomers committed Jul 26, 2021
commit b06ac05099eab0055c1e9189550a107ba8ea3b96
3 changes: 1 addition & 2 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ full = [
"time",
]

fs = ["cfg-if"]
fs = []
io-util = ["memchr", "bytes"]
# stdin, stdout, stderr
io-std = []
@@ -92,7 +92,6 @@ pin-project-lite = "0.2.0"

# Everything else is optional...
bytes = { version = "1.0.0", optional = true }
cfg-if = { version = "1.0", optional = true }
once_cell = { version = "1.5.2", optional = true }
memchr = { version = "2.2", optional = true }
mio = { version = "0.7.6", optional = true }
24 changes: 12 additions & 12 deletions tokio/src/fs/file.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ use crate::io::blocking::Buf;
use crate::io::{AsyncRead, AsyncSeek, AsyncWrite, ReadBuf};
use crate::sync::Mutex;

use cfg_if::cfg_if;
use std::fmt;
use std::fs::{Metadata, Permissions};
use std::future::Future;
@@ -20,17 +19,18 @@ use std::task::Context;
use std::task::Poll;
use std::task::Poll::*;

cfg_if! {
if #[cfg(test)] {
use super::mocks::MockFile as StdFile;
use super::mocks::JoinHandle;
use super::mocks::spawn_blocking;
} else {
use std::fs::File as StdFile;
use crate::blocking::spawn_blocking;
use crate::blocking::JoinHandle;
}
}
#[cfg(test)]
use super::mocks::MockFile as StdFile;
#[cfg(test)]
use super::mocks::JoinHandle;
#[cfg(test)]
use super::mocks::spawn_blocking;
#[cfg(not(test))]
use std::fs::File as StdFile;
#[cfg(not(test))]
use crate::blocking::spawn_blocking;
#[cfg(not(test))]
use crate::blocking::JoinHandle;

/// A reference to an open file on the filesystem.
///
13 changes: 4 additions & 9 deletions tokio/src/fs/mod.rs
Original file line number Diff line number Diff line change
@@ -24,8 +24,6 @@
//!
//! [`AsyncRead`]: trait@crate::io::AsyncRead

use cfg_if::cfg_if;

mod canonicalize;
pub use self::canonicalize::canonicalize;

@@ -108,13 +106,10 @@ feature! {

use std::io;

cfg_if! {
if #[cfg(test)] {
use mocks::spawn_blocking;
} else {
use crate::blocking::spawn_blocking;
}
}
#[cfg(test)]
use mocks::spawn_blocking;
#[cfg(not(test))]
use crate::blocking::spawn_blocking;

pub(crate) async fn asyncify<F, T>(f: F) -> io::Result<T>
where
15 changes: 6 additions & 9 deletions tokio/src/fs/open_options.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use crate::fs::{asyncify, File};

use cfg_if::cfg_if;
use std::io;
use std::path::Path;

cfg_if! {
if #[cfg(test)] {
mod mock_open_options;
use mock_open_options::MockOpenOptions as StdOpenOptions;
} else {
use std::fs::OpenOptions as StdOpenOptions;
}
}
#[cfg(test)]
mod mock_open_options;
#[cfg(test)]
use mock_open_options::MockOpenOptions as StdOpenOptions;
#[cfg(not(test))]
use std::fs::OpenOptions as StdOpenOptions;

/// Options and flags which can be used to configure how a file is opened.
///
18 changes: 8 additions & 10 deletions tokio/src/fs/read_dir.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::fs::asyncify;

use cfg_if::cfg_if;
use std::ffi::OsString;
use std::fs::{FileType, Metadata};
use std::future::Future;
@@ -11,15 +10,14 @@ use std::sync::Arc;
use std::task::Context;
use std::task::Poll;

cfg_if! {
if #[cfg(test)] {
use super::mocks::JoinHandle;
use super::mocks::spawn_blocking;
} else {
use crate::blocking::spawn_blocking;
use crate::blocking::JoinHandle;
}
}
#[cfg(test)]
use super::mocks::JoinHandle;
#[cfg(test)]
use super::mocks::spawn_blocking;
#[cfg(not(test))]
use crate::blocking::spawn_blocking;
#[cfg(not(test))]
use crate::blocking::JoinHandle;

/// Returns a stream over the entries within a directory.
///