Test that file EOF is not permanent: reading again should give new data

pull/1030/head
Josh Triplett 3 years ago
parent 64b7791ee5
commit dfdf56cc9a

@ -918,4 +918,40 @@ mod tests {
assert_eq!(format!("{}", expect), format!("{}", actual)); assert_eq!(format!("{}", expect), format!("{}", actual));
}) })
} }
#[test]
fn file_eof_is_not_permanent() -> crate::io::Result<()> {
let tempdir = tempfile::Builder::new()
.prefix("async-std-file-eof-test")
.tempdir()?;
let path = tempdir.path().join("testfile");
crate::task::block_on(async {
let mut file_w = File::create(&path).await?;
let mut file_r = File::open(&path).await?;
file_w.write_all(b"data").await?;
file_w.flush().await?;
let mut buf = [0u8; 4];
let mut len = file_r.read(&mut buf).await?;
assert_eq!(len, 4);
assert_eq!(&buf, b"data");
len = file_r.read(&mut buf).await?;
assert_eq!(len, 0);
file_w.write_all(b"more").await?;
file_w.flush().await?;
len = file_r.read(&mut buf).await?;
assert_eq!(len, 4);
assert_eq!(&buf, b"more");
len = file_r.read(&mut buf).await?;
assert_eq!(len, 0);
Ok(())
})
}
} }

Loading…
Cancel
Save