diff options
Diffstat (limited to 'tests/basic.rs')
-rw-r--r-- | tests/basic.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/tests/basic.rs b/tests/basic.rs index a623f13..f73b39e 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -2,13 +2,13 @@ fn test_cat_blocking() { use std::io::{Read as _, Write as _}; - let pty = pty_process::blocking::Pty::new().unwrap(); + let mut pty = pty_process::blocking::Pty::new().unwrap(); pty.resize(pty_process::Size::new(24, 80)).unwrap(); let mut child = pty_process::blocking::Command::new("cat") - .spawn(pty) + .spawn(&pty) .unwrap(); - child.pty().write_all(b"foo\n").unwrap(); + pty.write_all(b"foo\n").unwrap(); // the pty will echo the written bytes back immediately, but the // subprocess needs to generate its own output, which takes time, so we // can't just read immediately (we may just get the echoed bytes). because @@ -18,10 +18,10 @@ fn test_cat_blocking() { std::thread::sleep(std::time::Duration::from_secs(1)); let mut buf = [0u8; 1024]; - let bytes = child.pty().read(&mut buf).unwrap(); + let bytes = pty.read(&mut buf).unwrap(); assert_eq!(&buf[..bytes], b"foo\r\nfoo\r\n"); - child.pty().write_all(&[4u8]).unwrap(); + pty.write_all(&[4u8]).unwrap(); let status = child.wait().unwrap(); assert_eq!(status.code().unwrap(), 0); } @@ -33,11 +33,11 @@ fn test_cat_async_std() { use async_std::io::ReadExt as _; let status = async_std::task::block_on(async { - let pty = pty_process::Pty::new().unwrap(); + let mut pty = pty_process::Pty::new().unwrap(); pty.resize(pty_process::Size::new(24, 80)).unwrap(); - let mut child = pty_process::Command::new("cat").spawn(pty).unwrap(); + let mut child = pty_process::Command::new("cat").spawn(&pty).unwrap(); - child.pty().write_all(b"foo\n").await.unwrap(); + pty.write_all(b"foo\n").await.unwrap(); // the pty will echo the written bytes back immediately, but the // subprocess needs to generate its own output, which takes time, so // we can't just read immediately (we may just get the echoed bytes). @@ -47,10 +47,10 @@ fn test_cat_async_std() { async_std::task::sleep(std::time::Duration::from_secs(1)).await; let mut buf = [0u8; 1024]; - let bytes = child.pty().read(&mut buf).await.unwrap(); + let bytes = pty.read(&mut buf).await.unwrap(); assert_eq!(&buf[..bytes], b"foo\r\nfoo\r\n"); - child.pty().write_all(&[4u8]).await.unwrap(); + pty.write_all(&[4u8]).await.unwrap(); child.status().await.unwrap() }); assert_eq!(status.code().unwrap(), 0); @@ -62,11 +62,11 @@ fn test_cat_smol() { use smol::io::{AsyncReadExt as _, AsyncWriteExt as _}; let status = smol::block_on(async { - let pty = pty_process::Pty::new().unwrap(); + let mut pty = pty_process::Pty::new().unwrap(); pty.resize(pty_process::Size::new(24, 80)).unwrap(); - let mut child = pty_process::Command::new("cat").spawn(pty).unwrap(); + let mut child = pty_process::Command::new("cat").spawn(&pty).unwrap(); - child.pty().write_all(b"foo\n").await.unwrap(); + pty.write_all(b"foo\n").await.unwrap(); // the pty will echo the written bytes back immediately, but the // subprocess needs to generate its own output, which takes time, so // we can't just read immediately (we may just get the echoed bytes). @@ -76,10 +76,10 @@ fn test_cat_smol() { smol::Timer::after(std::time::Duration::from_secs(1)).await; let mut buf = [0u8; 1024]; - let bytes = child.pty().read(&mut buf).await.unwrap(); + let bytes = pty.read(&mut buf).await.unwrap(); assert_eq!(&buf[..bytes], b"foo\r\nfoo\r\n"); - child.pty().write_all(&[4u8]).await.unwrap(); + pty.write_all(&[4u8]).await.unwrap(); child.status().await.unwrap() }); assert_eq!(status.code().unwrap(), 0); @@ -94,9 +94,9 @@ fn test_cat_tokio() { async fn async_test_cat_tokio() { let pty = pty_process::Pty::new().unwrap(); pty.resize(pty_process::Size::new(24, 80)).unwrap(); - let mut child = pty_process::Command::new("cat").spawn(pty).unwrap(); + let mut child = pty_process::Command::new("cat").spawn(&pty).unwrap(); - child.pty_mut().compat().write_all(b"foo\n").await.unwrap(); + pty.compat().write_all(b"foo\n").await.unwrap(); // the pty will echo the written bytes back immediately, but the // subprocess needs to generate its own output, which takes time, so // we can't just read immediately (we may just get the echoed bytes). @@ -106,10 +106,10 @@ fn test_cat_tokio() { tokio::time::sleep(std::time::Duration::from_secs(1)).await; let mut buf = [0u8; 1024]; - let bytes = child.pty_mut().compat().read(&mut buf).await.unwrap(); + let bytes = pty.compat().read(&mut buf).await.unwrap(); assert_eq!(&buf[..bytes], b"foo\r\nfoo\r\n"); - child.pty_mut().compat().write_all(&[4u8]).await.unwrap(); + pty.compat().write_all(&[4u8]).await.unwrap(); let status = child.status().await.unwrap(); assert_eq!(status.code().unwrap(), 0); |