2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-01-30 09:15:33 +00:00

Merge pull request #994 from jaztec/master

Match error message from sync File::create in async File::create
This commit is contained in:
Yosh 2022-03-22 18:49:16 +01:00 committed by GitHub
commit f201f4a7bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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))
@ -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));
})
}
}