-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Darksonn
merged 30 commits into
tokio-rs:master
from
brodycj:add-some-missing-fs-function-tests
Feb 26, 2023
Merged
Changes from all 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 f1dd401
test tokio::fs::canonicalize()
brodycj 258278e
XXX comment out semver etc. from CI, will revert once fixed in master…
brodycj 1e40468
fix formatting in tokio/tests/fs_canonicalize_dir.rs
brodycj e8c1b40
test `tokio::fs::OpenOptions` functions for cross-platform & Unix - T…
brodycj ef295e4
FIX-UP custom flags testing
brodycj a18ad88
fixup! FIX-UP custom flags testing
brodycj 791e6cd
XXX comment out custom flags test with Linux for now - TODO resolve C…
brodycj c1eb005
test DirBuilder mode function
brodycj 81547eb
test some functions in tokio/src/fs/file.rs
brodycj 819d9fb
FIX-UP - formatting
brodycj f413ded
check info from fs::read_dir entry
brodycj b7413ee
test 3 more tokio::fs functions
brodycj 5ead02b
FIX-UP - clippy
brodycj 5d46fcf
another clippy fixup
brodycj 1b82f9f
update OpenOptions custom_flags testing for Linux/BSD/macOS
brodycj 47f4e2e
Revert "XXX comment out semver etc. from CI, will revert once fixed i…
brodycj 73eafdd
test OpenOptions custom_flags fn on Windows
brodycj e298ab9
Revert "test OpenOptions custom_flags fn on Windows"
brodycj f720ee3
Merge branch 'master' of https://github.com/tokio-rs/tokio into add-s…
brodycj 9f8595c
test Windows-specific OpenOptions functions
brodycj a134168
test fs::symlink_file() (for Windows only)
brodycj 71e7aeb
update tokio/tests/fs_open_options.rs
brodycj 83406d1
improve tokio/tests/fs_remove_dir_all.rs
brodycj f4b9ed2
add tokio/tests/fs_symlink_dir_windows.rs
brodycj b53c293
update WASI comment in fs tests
brodycj 1151724
improve testing in tokio/tests/fs_link.rs
brodycj 3ed730e
simplify test code in tokio/tests/fs_link.rs
brodycj b4cf96c
apply some minor touchups
brodycj df895bf
fixup & further minor touchup
brodycj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 all fs 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:\\")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations | ||
|
||
use std::io::Write; | ||
use tempfile::NamedTempFile; | ||
use tokio::fs::OpenOptions; | ||
use tokio::io::AsyncReadExt; | ||
|
||
const HELLO: &[u8] = b"hello world..."; | ||
|
||
#[tokio::test] | ||
async fn open_with_open_options_and_read() { | ||
let mut tempfile = NamedTempFile::new().unwrap(); | ||
tempfile.write_all(HELLO).unwrap(); | ||
|
||
let mut file = OpenOptions::new().read(true).open(tempfile).await.unwrap(); | ||
|
||
let mut buf = [0; 1024]; | ||
let n = file.read(&mut buf).await.unwrap(); | ||
|
||
assert_eq!(n, HELLO.len()); | ||
assert_eq!(&buf[..n], HELLO); | ||
} | ||
|
||
#[tokio::test] | ||
async fn open_options_write() { | ||
// TESTING HACK: use Debug output to check the stored data | ||
assert!(format!("{:?}", OpenOptions::new().write(true)).contains("write: true")); | ||
} | ||
|
||
#[tokio::test] | ||
async fn open_options_append() { | ||
// TESTING HACK: use Debug output to check the stored data | ||
assert!(format!("{:?}", OpenOptions::new().append(true)).contains("append: true")); | ||
} | ||
|
||
#[tokio::test] | ||
async fn open_options_truncate() { | ||
// TESTING HACK: use Debug output to check the stored data | ||
assert!(format!("{:?}", OpenOptions::new().truncate(true)).contains("truncate: true")); | ||
} | ||
|
||
#[tokio::test] | ||
async fn open_options_create() { | ||
// TESTING HACK: use Debug output to check the stored data | ||
assert!(format!("{:?}", OpenOptions::new().create(true)).contains("create: true")); | ||
} | ||
|
||
#[tokio::test] | ||
async fn open_options_create_new() { | ||
// TESTING HACK: use Debug output to check the stored data | ||
assert!(format!("{:?}", OpenOptions::new().create_new(true)).contains("create_new: true")); | ||
} | ||
|
||
#[tokio::test] | ||
#[cfg(unix)] | ||
async fn open_options_mode() { | ||
// TESTING HACK: use Debug output to check the stored data | ||
assert!(format!("{:?}", OpenOptions::new().mode(0o644)).contains("mode: 420 ")); | ||
} | ||
|
||
#[tokio::test] | ||
#[cfg(target_os = "linux")] | ||
async fn open_options_custom_flags_linux() { | ||
// TESTING HACK: use Debug output to check the stored data | ||
assert!( | ||
format!("{:?}", OpenOptions::new().custom_flags(libc::O_TRUNC)) | ||
.contains("custom_flags: 512,") | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
#[cfg(any(target_os = "freebsd", target_os = "macos"))] | ||
async fn open_options_custom_flags_bsd_family() { | ||
// TESTING HACK: use Debug output to check the stored data | ||
assert!( | ||
format!("{:?}", OpenOptions::new().custom_flags(libc::O_NOFOLLOW)) | ||
.contains("custom_flags: 256,") | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that this WASI comment that I copied was sometimes "file operations" and other times "directory operations". My apologies for possibly veering off-topic but from a little searching it looks to me like some fs operations may be possible with WASI but not all and WASI directory access would not work very easily with Tokio. I went ahead and used
sed
to apply a slightly more general statement across tokio/tests/fs_*.rs.