aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-29 23:55:32 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-29 23:55:32 -0500
commit06080c4d87766a717ab2b7f31f5d418b651e6969 (patch)
tree45612c521dd39bc96a93a3193be444fae95b2486 /tests
parentbdeb9c86f7adbb277715442bc341c360af6c03f8 (diff)
downloadpty-process-06080c4d87766a717ab2b7f31f5d418b651e6969.tar.gz
pty-process-06080c4d87766a717ab2b7f31f5d418b651e6969.zip
test
Diffstat (limited to 'tests')
-rw-r--r--tests/fds.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/fds.rs b/tests/fds.rs
new file mode 100644
index 0000000..7ef802d
--- /dev/null
+++ b/tests/fds.rs
@@ -0,0 +1,47 @@
+#[test]
+fn test_fds() {
+ use std::io::BufRead as _;
+
+ check_open_fds();
+
+ 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")
+ .arg("-Efor my $fd (0..255) { open my $fh, \"<&=$fd\"; print $fd if stat $fh }; say")
+ .spawn(&pty)
+ .unwrap();
+ let mut buf = vec![];
+ std::io::BufReader::new(&pty)
+ .read_until(b'\n', &mut buf)
+ .unwrap();
+ assert_eq!(&buf, b"012\r\n");
+ let status = child.wait().unwrap();
+ assert_eq!(status.code().unwrap(), 0);
+ drop(pty);
+ check_open_fds();
+
+ 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")
+ .arg("-Efor my $fd (0..255) { open my $fh, \"<&=$fd\"; print $fd if stat $fh }; say")
+ .stderr(Some(std::process::Stdio::null()))
+ .spawn(&pty)
+ .unwrap();
+ let mut buf = vec![];
+ std::io::BufReader::new(&pty)
+ .read_until(b'\n', &mut buf)
+ .unwrap();
+ assert_eq!(&buf, b"012\r\n");
+ let status = child.wait().unwrap();
+ assert_eq!(status.code().unwrap(), 0);
+ drop(pty);
+ check_open_fds();
+}
+
+#[track_caller]
+fn check_open_fds() {
+ let open: Vec<_> = (0..=255)
+ .filter(|fd| nix::sys::stat::fstat(*fd).is_ok())
+ .collect();
+ assert_eq!(open, vec![0, 1, 2]);
+}