aboutsummaryrefslogtreecommitdiffstats
path: root/tests/winch.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/winch.rs')
-rw-r--r--tests/winch.rs32
1 files changed, 14 insertions, 18 deletions
diff --git a/tests/winch.rs b/tests/winch.rs
index a189697..50447cb 100644
--- a/tests/winch.rs
+++ b/tests/winch.rs
@@ -1,8 +1,10 @@
+mod helpers;
+
#[test]
fn test_winch_std() {
- use std::io::{Read as _, Write as _};
+ use std::io::Write as _;
- let mut pty = pty_process::blocking::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::blocking::Command::new("perl")
.args(&[
@@ -12,16 +14,13 @@ fn test_winch_std() {
.spawn(&pty)
.unwrap();
- let mut buf = [0u8; 1024];
- let bytes = pty.read(&mut buf).unwrap();
- assert_eq!(&buf[..bytes], b"started\r\n");
+ let mut output = helpers::output(&pty);
+ assert_eq!(output.next().unwrap(), "started\r\n");
pty.resize(pty_process::Size::new(25, 80)).unwrap();
+ assert_eq!(output.next().unwrap(), "WINCH\r\n");
- let bytes = pty.read(&mut buf).unwrap();
- assert_eq!(&buf[..bytes], b"WINCH\r\n");
-
- pty.write_all(b"\n").unwrap();
+ (&pty).write_all(b"\n").unwrap();
let status = child.wait().unwrap();
assert_eq!(status.code().unwrap(), 0);
}
@@ -30,10 +29,10 @@ fn test_winch_std() {
#[test]
fn test_winch_async() {
use async_std::io::prelude::WriteExt as _;
- use async_std::io::ReadExt as _;
+ use futures::stream::StreamExt as _;
let status = async_std::task::block_on(async {
- let mut pty = pty_process::Pty::new().unwrap();
+ let pty = pty_process::Pty::new().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::Command::new("perl")
.args(&[
@@ -43,16 +42,13 @@ fn test_winch_async() {
.spawn(&pty)
.unwrap();
- let mut buf = [0u8; 1024];
- let bytes = pty.read(&mut buf).await.unwrap();
- assert_eq!(&buf[..bytes], b"started\r\n");
+ let mut output = helpers::output_async(&pty);
+ assert_eq!(output.next().await.unwrap(), "started\r\n");
pty.resize(pty_process::Size::new(25, 80)).unwrap();
+ assert_eq!(output.next().await.unwrap(), "WINCH\r\n");
- let bytes = pty.read(&mut buf).await.unwrap();
- assert_eq!(&buf[..bytes], b"WINCH\r\n");
-
- pty.write_all(b"\n").await.unwrap();
+ (&pty).write_all(b"\n").await.unwrap();
child.status().await.unwrap()
});
assert_eq!(status.code().unwrap(), 0);