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

add some missing tokio::fs function tests etc. #5493

Merged
merged 30 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ace8cee
XXX add code to panic in some untested tokio::fs functions - TEMPORAR…
brodycj Feb 22, 2023
f1dd401
test tokio::fs::canonicalize()
brodycj Feb 22, 2023
258278e
XXX comment out semver etc. from CI, will revert once fixed in master…
brodycj Feb 22, 2023
1e40468
fix formatting in tokio/tests/fs_canonicalize_dir.rs
brodycj Feb 22, 2023
e8c1b40
test `tokio::fs::OpenOptions` functions for cross-platform & Unix - T…
brodycj Feb 22, 2023
ef295e4
FIX-UP custom flags testing
brodycj Feb 22, 2023
a18ad88
fixup! FIX-UP custom flags testing
brodycj Feb 22, 2023
791e6cd
XXX comment out custom flags test with Linux for now - TODO resolve C…
brodycj Feb 22, 2023
c1eb005
test DirBuilder mode function
brodycj Feb 22, 2023
81547eb
test some functions in tokio/src/fs/file.rs
brodycj Feb 22, 2023
819d9fb
FIX-UP - formatting
brodycj Feb 22, 2023
f413ded
check info from fs::read_dir entry
brodycj Feb 22, 2023
b7413ee
test 3 more tokio::fs functions
brodycj Feb 22, 2023
5ead02b
FIX-UP - clippy
brodycj Feb 22, 2023
5d46fcf
another clippy fixup
brodycj Feb 22, 2023
1b82f9f
update OpenOptions custom_flags testing for Linux/BSD/macOS
brodycj Feb 22, 2023
47f4e2e
Revert "XXX comment out semver etc. from CI, will revert once fixed i…
brodycj Feb 22, 2023
73eafdd
test OpenOptions custom_flags fn on Windows
brodycj Feb 22, 2023
e298ab9
Revert "test OpenOptions custom_flags fn on Windows"
brodycj Feb 22, 2023
f720ee3
Merge branch 'master' of https://github.com/tokio-rs/tokio into add-s…
brodycj Feb 22, 2023
9f8595c
test Windows-specific OpenOptions functions
brodycj Feb 22, 2023
a134168
test fs::symlink_file() (for Windows only)
brodycj Feb 22, 2023
71e7aeb
update tokio/tests/fs_open_options.rs
brodycj Feb 22, 2023
83406d1
improve tokio/tests/fs_remove_dir_all.rs
brodycj Feb 22, 2023
f4b9ed2
add tokio/tests/fs_symlink_dir_windows.rs
brodycj Feb 22, 2023
b53c293
update WASI comment in fs tests
brodycj Feb 23, 2023
1151724
improve testing in tokio/tests/fs_link.rs
brodycj Feb 23, 2023
3ed730e
simplify test code in tokio/tests/fs_link.rs
brodycj Feb 23, 2023
b4cf96c
apply some minor touchups
brodycj Feb 23, 2023
df895bf
fixup & further minor touchup
brodycj Feb 23, 2023
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
102 changes: 51 additions & 51 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,35 @@ permissions:

jobs:
# Depends on all action sthat are required for a "successful" CI run.
tests-pass:
name: all systems go
runs-on: ubuntu-latest
needs:
- test
- test-parking_lot
- valgrind
- test-unstable
- miri
- asan
- semver
- cross-check
- cross-test
- no-atomic-u64
- features
- minrust
- minimal-versions
- fmt
- clippy
- docs
- loom-compile
- check-readme
- test-hyper
- x86_64-fortanix-unknown-sgx
- wasm32-unknown-unknown
- wasm32-wasi
- check-external-types
steps:
- run: exit 0
#tests-pass:
# name: all systems go
# runs-on: ubuntu-latest
# needs:
# - test
# - test-parking_lot
# - valgrind
# - test-unstable
# - miri
# - asan
# #- semver
brodycj marked this conversation as resolved.
Show resolved Hide resolved
# - cross-check
# - cross-test
# - no-atomic-u64
# - features
# - minrust
# - minimal-versions
# - fmt
# - clippy
# - docs
# - loom-compile
# - check-readme
# - test-hyper
# - x86_64-fortanix-unknown-sgx
# - wasm32-unknown-unknown
# - wasm32-wasi
# - check-external-types
# steps:
# - run: exit 0

test:
name: test tokio full
Expand Down Expand Up @@ -230,28 +230,28 @@ jobs:
# Ignore `trybuild` errors as they are irrelevant and flaky on nightly
TRYBUILD: overwrite

semver:
name: semver
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.rust_stable }}
- name: Install cargo-semver-checks
uses: taiki-e/install-action@v2
with:
tool: cargo-semver-checks
- name: Check semver compatibility
run: |
cargo semver-checks check-release \
--release-type minor \
--exclude benches \
--exclude examples \
--exclude stress-test \
--exclude tests-build \
--exclude tests-integration
# semver:
# name: semver
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Install Rust ${{ env.rust_stable }}
# uses: dtolnay/rust-toolchain@master
# with:
# toolchain: ${{ env.rust_stable }}
# - name: Install cargo-semver-checks
# uses: taiki-e/install-action@v2
# with:
# tool: cargo-semver-checks
# - name: Check semver compatibility
# run: |
# cargo semver-checks check-release \
# --release-type minor \
# --exclude benches \
# --exclude examples \
# --exclude stress-test \
# --exclude tests-build \
# --exclude tests-integration

cross-check:
name: cross-check
Expand Down
1 change: 1 addition & 0 deletions tokio/src/fs/dir_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ feature! {
/// builder.mode(0o775);
/// ```
pub fn mode(&mut self, mode: u32) -> &mut Self {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.mode = Some(mode);
self
}
Expand Down
6 changes: 6 additions & 0 deletions tokio/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ impl File {
/// # }
/// ```
pub async fn try_clone(&self) -> io::Result<File> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
let std = self.std.clone();
let std_file = asyncify(move || std.try_clone()).await?;
Ok(File::from_std(std_file))
Expand All @@ -423,6 +424,7 @@ impl File {
/// # }
/// ```
pub async fn into_std(mut self) -> StdFile {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.inner.get_mut().complete_inflight().await;
Arc::try_unwrap(self.std).expect("Arc::try_unwrap failed")
}
Expand All @@ -448,6 +450,7 @@ impl File {
/// # }
/// ```
pub fn try_into_std(mut self) -> Result<StdFile, Self> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
match Arc::try_unwrap(self.std) {
Ok(file) => Ok(file),
Err(std_file_arc) => {
Expand Down Expand Up @@ -706,12 +709,14 @@ impl AsyncWrite for File {

impl From<StdFile> for File {
fn from(std: StdFile) -> Self {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
Self::from_std(std)
}
}

impl fmt::Debug for File {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
fmt.debug_struct("tokio::fs::File")
.field("std", &self.std)
.finish()
Expand All @@ -728,6 +733,7 @@ impl std::os::unix::io::AsRawFd for File {
#[cfg(unix)]
impl std::os::unix::io::FromRawFd for File {
unsafe fn from_raw_fd(fd: std::os::unix::io::RawFd) -> Self {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
StdFile::from_raw_fd(fd).into()
}
}
Expand Down
16 changes: 16 additions & 0 deletions tokio/src/fs/open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl OpenOptions {
/// let future = options.read(true).open("foo.txt");
/// ```
pub fn new() -> OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
OpenOptions(StdOpenOptions::new())
}

Expand Down Expand Up @@ -125,6 +126,7 @@ impl OpenOptions {
/// }
/// ```
pub fn read(&mut self, read: bool) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.0.read(read);
self
}
Expand Down Expand Up @@ -155,6 +157,7 @@ impl OpenOptions {
/// }
/// ```
pub fn write(&mut self, write: bool) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.0.write(write);
self
}
Expand Down Expand Up @@ -214,6 +217,7 @@ impl OpenOptions {
/// }
/// ```
pub fn append(&mut self, append: bool) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.0.append(append);
self
}
Expand Down Expand Up @@ -247,6 +251,7 @@ impl OpenOptions {
/// }
/// ```
pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.0.truncate(truncate);
self
}
Expand Down Expand Up @@ -283,6 +288,7 @@ impl OpenOptions {
/// }
/// ```
pub fn create(&mut self, create: bool) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.0.create(create);
self
}
Expand Down Expand Up @@ -326,6 +332,7 @@ impl OpenOptions {
/// }
/// ```
pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.0.create_new(create_new);
self
}
Expand Down Expand Up @@ -383,6 +390,7 @@ impl OpenOptions {
/// [`Other`]: std::io::ErrorKind::Other
/// [`PermissionDenied`]: std::io::ErrorKind::PermissionDenied
pub async fn open(&self, path: impl AsRef<Path>) -> io::Result<File> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
let path = path.as_ref().to_owned();
let opts = self.0.clone();

Expand All @@ -392,6 +400,7 @@ impl OpenOptions {

/// Returns a mutable reference to the underlying `std::fs::OpenOptions`
pub(super) fn as_inner_mut(&mut self) -> &mut StdOpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
&mut self.0
}
}
Expand Down Expand Up @@ -426,6 +435,7 @@ feature! {
/// }
/// ```
pub fn mode(&mut self, mode: u32) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.as_inner_mut().mode(mode);
self
}
Expand Down Expand Up @@ -458,6 +468,7 @@ feature! {
/// }
/// ```
pub fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.as_inner_mut().custom_flags(flags);
self
}
Expand Down Expand Up @@ -494,6 +505,7 @@ feature! {
///
/// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
pub fn access_mode(&mut self, access: u32) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.as_inner_mut().access_mode(access);
self
}
Expand Down Expand Up @@ -527,6 +539,7 @@ feature! {
///
/// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
pub fn share_mode(&mut self, share: u32) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.as_inner_mut().share_mode(share);
self
}
Expand Down Expand Up @@ -559,6 +572,7 @@ feature! {
/// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
/// [`CreateFile2`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2
pub fn custom_flags(&mut self, flags: u32) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.as_inner_mut().custom_flags(flags);
self
}
Expand Down Expand Up @@ -598,6 +612,7 @@ feature! {
/// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
/// [`CreateFile2`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2
pub fn attributes(&mut self, attributes: u32) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.as_inner_mut().attributes(attributes);
self
}
Expand Down Expand Up @@ -646,6 +661,7 @@ feature! {
/// [Impersonation Levels]:
/// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-security_impersonation_level
pub fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.as_inner_mut().security_qos_flags(flags);
self
}
Expand Down
4 changes: 4 additions & 0 deletions tokio/src/fs/read_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl DirEntry {
///
/// The exact text, of course, depends on what files you have in `.`.
pub fn path(&self) -> PathBuf {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
self.std.path()
}

Expand Down Expand Up @@ -293,6 +294,7 @@ impl DirEntry {
/// # }
/// ```
pub async fn metadata(&self) -> io::Result<Metadata> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
let std = self.std.clone();
asyncify(move || std.metadata()).await
}
Expand Down Expand Up @@ -328,6 +330,8 @@ impl DirEntry {
/// # }
/// ```
pub async fn file_type(&self) -> io::Result<FileType> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());

#[cfg(not(any(
target_os = "solaris",
target_os = "illumos",
Expand Down
1 change: 1 addition & 0 deletions tokio/src/fs/remove_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::Path;
///
/// [std]: fn@std::fs::remove_dir_all
pub async fn remove_dir_all(path: impl AsRef<Path>) -> io::Result<()> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
let path = path.as_ref().to_owned();
asyncify(move || std::fs::remove_dir_all(path)).await
}
1 change: 1 addition & 0 deletions tokio/src/fs/remove_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::path::Path;
///
/// [std]: std::fs::remove_file
pub async fn remove_file(path: impl AsRef<Path>) -> io::Result<()> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
let path = path.as_ref().to_owned();
asyncify(move || std::fs::remove_file(path)).await
}
1 change: 1 addition & 0 deletions tokio/src/fs/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::path::Path;
///
/// This is an async version of [`std::fs::rename`](std::fs::rename)
pub async fn rename(from: impl AsRef<Path>, to: impl AsRef<Path>) -> io::Result<()> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
let from = from.as_ref().to_owned();
let to = to.as_ref().to_owned();

Expand Down
1 change: 1 addition & 0 deletions tokio/src/fs/symlink_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::path::Path;
///
/// [std]: std::os::windows::fs::symlink_dir
pub async fn symlink_dir(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
let src = src.as_ref().to_owned();
let dst = dst.as_ref().to_owned();

Expand Down
1 change: 1 addition & 0 deletions tokio/src/fs/symlink_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::path::Path;
///
/// [std]: std::os::windows::fs::symlink_file
pub async fn symlink_file(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
assert!(std::env::var("XXX_KEEP_UNTESTED_XXX").is_ok());
let src = src.as_ref().to_owned();
let dst = dst.as_ref().to_owned();

Expand Down
22 changes: 22 additions & 0 deletions tokio/tests/fs_canonicalize_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support directory operations

use tokio::fs;

#[tokio::test]
#[cfg(unix)]
async fn canonicalize_root_dir_unix() {
assert_eq!(fs::canonicalize("/.").await.unwrap().to_str().unwrap(), "/");
}

#[tokio::test]
#[cfg(windows)]
async fn canonicalize_root_dir_windows() {
// 2-step let bindings due to Rust memory semantics
let dir_path = fs::canonicalize("C:\\.\\").await.unwrap();

let dir_name = dir_path.to_str().unwrap();

assert!(dir_name.starts_with("\\\\"));
assert!(dir_name.ends_with("C:\\"));
}