diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-29 02:55:24 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-29 03:52:12 -0500 |
commit | 3b550f5d3dad77a56455352579fae3071b42e86d (patch) | |
tree | 393de5f206d227ec71149f478db900291357c456 /tests/basic.rs | |
parent | f8780ca1e76286688b74d8a6c64d5fadf3cfd2a1 (diff) | |
download | pty-process-3b550f5d3dad77a56455352579fae3071b42e86d.tar.gz pty-process-3b550f5d3dad77a56455352579fae3071b42e86d.zip |
wip another complete refactor
Diffstat (limited to 'tests/basic.rs')
-rw-r--r-- | tests/basic.rs | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/tests/basic.rs b/tests/basic.rs index e164357..a623f13 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,11 +1,12 @@ -#[cfg(feature = "backend-std")] #[test] -fn test_cat_std() { +fn test_cat_blocking() { use std::io::{Read as _, Write as _}; - let pty = pty_process::std::Pty::new().unwrap(); + let pty = pty_process::blocking::Pty::new().unwrap(); pty.resize(pty_process::Size::new(24, 80)).unwrap(); - let mut child = pty_process::std::Command::new("cat").spawn(pty).unwrap(); + let mut child = pty_process::blocking::Command::new("cat") + .spawn(pty) + .unwrap(); child.pty().write_all(b"foo\n").unwrap(); // the pty will echo the written bytes back immediately, but the @@ -25,16 +26,16 @@ fn test_cat_std() { assert_eq!(status.code().unwrap(), 0); } -#[cfg(feature = "backend-smol")] +#[cfg(feature = "async")] #[test] -fn test_cat_smol() { - use smol::io::{AsyncReadExt as _, AsyncWriteExt as _}; +fn test_cat_async_std() { + use async_std::io::prelude::WriteExt as _; + use async_std::io::ReadExt as _; - let status = smol::block_on(async { - let pty = pty_process::smol::Pty::new().unwrap(); + let status = async_std::task::block_on(async { + let pty = pty_process::Pty::new().unwrap(); pty.resize(pty_process::Size::new(24, 80)).unwrap(); - let mut child = - pty_process::smol::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(); // the pty will echo the written bytes back immediately, but the @@ -43,7 +44,7 @@ fn test_cat_smol() { // because the output generation is happening in the subprocess, we // also don't have any way to know when (or if!) the subprocess will // decide to send its output, so sleeping is the best we can do. - smol::Timer::after(std::time::Duration::from_secs(1)).await; + 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(); @@ -55,18 +56,15 @@ fn test_cat_smol() { assert_eq!(status.code().unwrap(), 0); } -#[cfg(feature = "backend-async-std")] +#[cfg(feature = "async")] #[test] -fn test_cat_async_std() { - use async_std::io::prelude::WriteExt as _; - use async_std::io::ReadExt as _; +fn test_cat_smol() { + use smol::io::{AsyncReadExt as _, AsyncWriteExt as _}; - let status = async_std::task::block_on(async { - let pty = pty_process::async_std::Pty::new().unwrap(); + let status = smol::block_on(async { + let pty = pty_process::Pty::new().unwrap(); pty.resize(pty_process::Size::new(24, 80)).unwrap(); - let mut child = pty_process::async_std::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(); // the pty will echo the written bytes back immediately, but the @@ -75,7 +73,7 @@ fn test_cat_async_std() { // because the output generation is happening in the subprocess, we // also don't have any way to know when (or if!) the subprocess will // decide to send its output, so sleeping is the best we can do. - async_std::task::sleep(std::time::Duration::from_secs(1)).await; + smol::Timer::after(std::time::Duration::from_secs(1)).await; let mut buf = [0u8; 1024]; let bytes = child.pty().read(&mut buf).await.unwrap(); @@ -87,18 +85,18 @@ fn test_cat_async_std() { assert_eq!(status.code().unwrap(), 0); } -#[cfg(feature = "backend-tokio")] +#[cfg(feature = "async")] #[test] fn test_cat_tokio() { use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _}; + use tokio_util::compat::FuturesAsyncReadCompatExt as _; async fn async_test_cat_tokio() { - let pty = pty_process::tokio::Pty::new().unwrap(); + let pty = pty_process::Pty::new().unwrap(); pty.resize(pty_process::Size::new(24, 80)).unwrap(); - let mut child = - pty_process::tokio::Command::new("cat").spawn(pty).unwrap(); + let mut child = pty_process::Command::new("cat").spawn(pty).unwrap(); - child.pty_mut().write_all(b"foo\n").await.unwrap(); + child.pty_mut().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). @@ -108,12 +106,12 @@ fn test_cat_tokio() { tokio::time::sleep(std::time::Duration::from_secs(1)).await; let mut buf = [0u8; 1024]; - let bytes = child.pty_mut().read(&mut buf).await.unwrap(); + let bytes = child.pty_mut().compat().read(&mut buf).await.unwrap(); assert_eq!(&buf[..bytes], b"foo\r\nfoo\r\n"); - child.pty_mut().write_all(&[4u8]).await.unwrap(); + child.pty_mut().compat().write_all(&[4u8]).await.unwrap(); - let status = child.wait().await.unwrap(); + let status = child.status().await.unwrap(); assert_eq!(status.code().unwrap(), 0); } tokio::runtime::Runtime::new().unwrap().block_on(async { |