From 6f61c9dc7e15f96ce0520d89775f2ef329e17174 Mon Sep 17 00:00:00 2001 From: Jasper van Herpt Date: Wed, 13 Oct 2021 21:49:07 +0200 Subject: [PATCH] Match error message from async File::create std File::create --- src/fs/file.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index e8cad7ad7..aae201b6d 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -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)); + }) + } }