aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-29 14:39:53 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-29 14:39:53 -0500
commite0337dbbb0a919d2bff3c22b90d0f0f17bad775d (patch)
tree6b27af50f179441d784e02f85fc9392cc5dbd335 /tests
parentd6e938a3454f70d2b4177d9fb23092f47ad6bb18 (diff)
downloadpty-process-e0337dbbb0a919d2bff3c22b90d0f0f17bad775d.tar.gz
pty-process-e0337dbbb0a919d2bff3c22b90d0f0f17bad775d.zip
simplify
Diffstat (limited to 'tests')
-rw-r--r--tests/basic.rs38
-rw-r--r--tests/winch.rs46
2 files changed, 42 insertions, 42 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);
diff --git a/tests/winch.rs b/tests/winch.rs
index 9d26751..40ffaf4 100644
--- a/tests/winch.rs
+++ b/tests/winch.rs
@@ -2,26 +2,26 @@
fn test_winch_std() {
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("perl")
.args(&[
"-E",
"$|++; $SIG{WINCH} = sub { say 'WINCH' }; say 'started'; <>",
])
- .spawn(pty)
+ .spawn(&pty)
.unwrap();
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"started\r\n");
- child.pty().resize(pty_process::Size::new(25, 80)).unwrap();
+ pty.resize(pty_process::Size::new(25, 80)).unwrap();
- let bytes = child.pty().read(&mut buf).unwrap();
+ let bytes = pty.read(&mut buf).unwrap();
assert_eq!(&buf[..bytes], b"WINCH\r\n");
- child.pty().write_all(b"\n").unwrap();
+ pty.write_all(b"\n").unwrap();
let status = child.wait().unwrap();
assert_eq!(status.code().unwrap(), 0);
}
@@ -33,26 +33,26 @@ fn test_winch_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("perl")
.args(&[
"-E",
"$|++; $SIG{WINCH} = sub { say 'WINCH' }; say 'started'; <>",
])
- .spawn(pty)
+ .spawn(&pty)
.unwrap();
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"started\r\n");
- child.pty().resize(pty_process::Size::new(25, 80)).unwrap();
+ pty.resize(pty_process::Size::new(25, 80)).unwrap();
- let bytes = child.pty().read(&mut buf).await.unwrap();
+ let bytes = pty.read(&mut buf).await.unwrap();
assert_eq!(&buf[..bytes], b"WINCH\r\n");
- child.pty().write_all(b"\n").await.unwrap();
+ pty.write_all(b"\n").await.unwrap();
child.status().await.unwrap()
});
assert_eq!(status.code().unwrap(), 0);
@@ -64,26 +64,26 @@ fn test_winch_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("perl")
.args(&[
"-E",
"$|++; $SIG{WINCH} = sub { say 'WINCH' }; say 'started'; <>",
])
- .spawn(pty)
+ .spawn(&pty)
.unwrap();
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"started\r\n");
- child.pty().resize(pty_process::Size::new(25, 80)).unwrap();
+ pty.resize(pty_process::Size::new(25, 80)).unwrap();
- let bytes = child.pty().read(&mut buf).await.unwrap();
+ let bytes = pty.read(&mut buf).await.unwrap();
assert_eq!(&buf[..bytes], b"WINCH\r\n");
- child.pty().write_all(b"\n").await.unwrap();
+ pty.write_all(b"\n").await.unwrap();
child.status().await.unwrap()
});
assert_eq!(status.code().unwrap(), 0);
@@ -103,19 +103,19 @@ fn test_winch_tokio() {
"-E",
"$|++; $SIG{WINCH} = sub { say 'WINCH' }; say 'started'; <>",
])
- .spawn(pty)
+ .spawn(&pty)
.unwrap();
let mut buf = [0u8; 1024];
- let bytes = child.pty().compat().read(&mut buf).await.unwrap();
+ let bytes = pty.compat().read(&mut buf).await.unwrap();
assert_eq!(&buf[..bytes], b"started\r\n");
- child.pty().resize(pty_process::Size::new(25, 80)).unwrap();
+ pty.resize(pty_process::Size::new(25, 80)).unwrap();
- let bytes = child.pty().compat().read(&mut buf).await.unwrap();
+ let bytes = pty.compat().read(&mut buf).await.unwrap();
assert_eq!(&buf[..bytes], b"WINCH\r\n");
- child.pty().compat().write_all(b"\n").await.unwrap();
+ pty.compat().write_all(b"\n").await.unwrap();
child.status().await.unwrap()
}
tokio::runtime::Runtime::new().unwrap().block_on(async {