diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-30 15:43:21 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-30 15:43:21 -0500 |
commit | d1a9c4d1d878e7bcb4caac766fabcfb48fe418f2 (patch) | |
tree | f54c8030ea9fcdbd06da6c6c119575a0c142ce64 /tests/fds_async.rs | |
parent | 0eaa0416fe949d8b3f5273f2677725b113ce17d0 (diff) | |
download | pty-process-d1a9c4d1d878e7bcb4caac766fabcfb48fe418f2.tar.gz pty-process-d1a9c4d1d878e7bcb4caac766fabcfb48fe418f2.zip |
improve tests
Diffstat (limited to 'tests/fds_async.rs')
-rw-r--r-- | tests/fds_async.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/tests/fds_async.rs b/tests/fds_async.rs index e2c369d..7710789 100644 --- a/tests/fds_async.rs +++ b/tests/fds_async.rs @@ -1,7 +1,9 @@ +mod helpers; + #[cfg(feature = "async")] #[test] fn test_fds_async() { - use async_std::io::prelude::BufReadExt as _; + use futures::stream::StreamExt as _; check_open_fds(&[0, 1, 2]); @@ -14,12 +16,10 @@ fn test_fds_async() { .arg("-Efor my $fd (0..255) { open my $fh, \"<&=$fd\"; print $fd if stat $fh }; say") .spawn(&pty) .unwrap(); - let mut buf = vec![]; - async_std::io::BufReader::new(&pty) - .read_until(b'\n', &mut buf) - .await - .unwrap(); - assert_eq!(&buf, b"012\r\n"); + + let mut output = helpers::output_async(&pty); + assert_eq!(output.next().await.unwrap(), "012\r\n"); + let status = child.status().await.unwrap(); assert_eq!(status.code().unwrap(), 0); }); @@ -33,14 +33,13 @@ fn test_fds_async() { .arg("-Efor my $fd (0..255) { open my $fh, \"<&=$fd\"; print $fd if stat $fh }; say") .spawn(&pty) .unwrap(); - let mut buf = vec![]; - async_std::io::BufReader::new(&pty) - .read_until(b'\n', &mut buf) - .await - .unwrap(); - assert_eq!(&buf, b"012\r\n"); + + let mut output = helpers::output_async(&pty); + assert_eq!(output.next().await.unwrap(), "012\r\n"); + let status = child.status().await.unwrap(); assert_eq!(status.code().unwrap(), 0); + drop(output); drop(pty); check_open_fds(&fds); @@ -56,14 +55,13 @@ fn test_fds_async() { .stderr(Some(std::process::Stdio::null())) .spawn(&pty) .unwrap(); - let mut buf = vec![]; - async_std::io::BufReader::new(&pty) - .read_until(b'\n', &mut buf) - .await - .unwrap(); - assert_eq!(&buf, b"012\r\n"); + + let mut output = helpers::output_async(&pty); + assert_eq!(output.next().await.unwrap(), "012\r\n"); + let status = child.status().await.unwrap(); assert_eq!(status.code().unwrap(), 0); + drop(output); drop(pty); check_open_fds(&fds); |