Skip to content

Commit

Permalink
Merge pull request #994 from jaztec/master
Browse files Browse the repository at this point in the history
Match error message from sync File::create in async File::create
  • Loading branch information
yoshuawuyts authored Mar 22, 2022
2 parents 7e455db + 6f61c9d commit f201f4a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ impl File {
let path = path.as_ref().to_owned();
let file = spawn_blocking(move || {
std::fs::File::create(&path)
.context(|| format!("could not create `{}`", path.display()))
})
.await?;
Ok(File::new(file, true))
Expand Down Expand Up @@ -903,4 +902,15 @@ mod tests {
assert_eq!(len as u64, file.metadata().await.unwrap().len());
});
}

#[test]
fn async_file_create_error () {
let file_name = Path::new("/tmp/does_not_exist/test");
let expect = std::fs::File::create(file_name).unwrap_err();

crate::task::block_on(async move {
let actual = File::create(file_name).await.unwrap_err();
assert_eq!(format!("{}", expect), format!("{}", actual));
})
}
}

0 comments on commit f201f4a

Please sign in to comment.