From 506d17f6caebcb9c72471a496a5cc0d9d852eb2b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 6 Aug 2023 19:54:16 -0400 Subject: handle the test runner having other fds open --- tests/fds.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/fds.rs b/tests/fds.rs index a641f46..61fd472 100644 --- a/tests/fds.rs +++ b/tests/fds.rs @@ -2,7 +2,7 @@ mod helpers; #[test] fn test_fds() { - check_open_fds(); + let fds = check_open_fds(None); let pty = pty_process::blocking::Pty::new().unwrap(); let pts = pty.pts().unwrap(); @@ -19,7 +19,7 @@ fn test_fds() { assert_eq!(status.code().unwrap(), 0); drop(pty); drop(pts); - check_open_fds(); + check_open_fds(Some(&fds)); let pty = pty_process::blocking::Pty::new().unwrap(); let pts = pty.pts().unwrap(); @@ -37,13 +37,19 @@ fn test_fds() { assert_eq!(status.code().unwrap(), 0); drop(pty); drop(pts); - check_open_fds(); + check_open_fds(Some(&fds)); } #[track_caller] -fn check_open_fds() { +fn check_open_fds(expected: Option<&[i32]>) -> Vec { let open: Vec<_> = (0..=255) .filter(|fd| nix::sys::stat::fstat(*fd).is_ok()) .collect(); - assert_eq!(open, vec![0, 1, 2]); + assert!(open.contains(&0)); + assert!(open.contains(&1)); + assert!(open.contains(&2)); + if let Some(fds) = expected { + assert_eq!(open, fds); + } + open.to_vec() } -- cgit v1.2.3-54-g00ecf