diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-02-25 20:16:42 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-02-25 20:16:42 -0500 |
commit | f0710ededc80610fdaff3209f8b94fa0d7bb78ce (patch) | |
tree | 669db33fe8e316502dcad0486614a3f850f55757 /tests | |
parent | aca49b2f55df04142d4b2fcfcb361361e76d0820 (diff) | |
download | pty-process-f0710ededc80610fdaff3209f8b94fa0d7bb78ce.tar.gz pty-process-f0710ededc80610fdaff3209f8b94fa0d7bb78ce.zip |
ensure read_buf doesn't overflow the buffer
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/basic.rs b/tests/basic.rs index 6f276e6..ed75e60 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -51,3 +51,36 @@ fn test_cat_async() { }); assert_eq!(status.code().unwrap(), 0); } + +#[cfg(feature = "async")] +#[test] +fn test_yes_async() { + use tokio::io::AsyncReadExt as _; + + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(async { + let mut pty = pty_process::Pty::new().unwrap(); + let pts = pty.pts().unwrap(); + pty.resize(pty_process::Size::new(24, 80)).unwrap(); + let mut child = + pty_process::Command::new("yes").spawn(&pts).unwrap(); + + let mut buf = [0u8; 3]; + + let bytes = pty.read_buf(&mut &mut buf[..]).await.unwrap(); + assert_eq!(&buf[..bytes], b"y\r\n"); + + let (mut pty_r, _pty_w) = pty.split(); + let bytes = pty_r.read_buf(&mut &mut buf[..]).await.unwrap(); + assert_eq!(&buf[..bytes], b"y\r\n"); + + let (mut pty_r, _pty_w) = pty.into_split(); + let bytes = pty_r.read_buf(&mut &mut buf[..]).await.unwrap(); + assert_eq!(&buf[..bytes], b"y\r\n"); + + child.kill().await.unwrap() + }); +} |