From e0337dbbb0a919d2bff3c22b90d0f0f17bad775d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 29 Dec 2021 14:39:53 -0500 Subject: simplify --- tests/basic.rs | 38 +++++++++++++++++++------------------- tests/winch.rs | 46 +++++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 42 deletions(-) (limited to 'tests') 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 { -- cgit v1.2.3-54-g00ecf