diff options
Diffstat (limited to 'test/test_pty.rs')
-rw-r--r-- | test/test_pty.rs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/test/test_pty.rs b/test/test_pty.rs index b1c2d630..8528caf7 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -5,17 +5,7 @@ use nix::fcntl::{O_RDWR, open}; use nix::pty::*; use nix::sys::stat; use nix::sys::termios::*; -use nix::unistd::{read, write, close}; - -/// Helper function analogous to std::io::Read::read_exact, but for `RawFD`s -fn read_exact(f: RawFd, buf: &mut [u8]) { - let mut len = 0; - while len < buf.len() { - // get_mut would be better than split_at_mut, but it requires nightly - let (_, remaining) = buf.split_at_mut(len); - len += read(f, remaining).unwrap(); - } -} +use nix::unistd::{write, close}; /// Test equivalence of `ptsname` and `ptsname_r` #[test] @@ -115,21 +105,21 @@ fn test_openpty() { let string = "foofoofoo\n"; let mut buf = [0u8; 10]; write(pty.master, string.as_bytes()).unwrap(); - read_exact(pty.slave, &mut buf); + ::read_exact(pty.slave, &mut buf); assert_eq!(&buf, string.as_bytes()); // Read the echo as well let echoed_string = "foofoofoo\r\n"; let mut buf = [0u8; 11]; - read_exact(pty.master, &mut buf); + ::read_exact(pty.master, &mut buf); assert_eq!(&buf, echoed_string.as_bytes()); let string2 = "barbarbarbar\n"; let echoed_string2 = "barbarbarbar\r\n"; let mut buf = [0u8; 14]; write(pty.slave, string2.as_bytes()).unwrap(); - read_exact(pty.master, &mut buf); + ::read_exact(pty.master, &mut buf); assert_eq!(&buf, echoed_string2.as_bytes()); @@ -160,20 +150,20 @@ fn test_openpty_with_termios() { let string = "foofoofoo\n"; let mut buf = [0u8; 10]; write(pty.master, string.as_bytes()).unwrap(); - read_exact(pty.slave, &mut buf); + ::read_exact(pty.slave, &mut buf); assert_eq!(&buf, string.as_bytes()); // read the echo as well let echoed_string = "foofoofoo\n"; - read_exact(pty.master, &mut buf); + ::read_exact(pty.master, &mut buf); assert_eq!(&buf, echoed_string.as_bytes()); let string2 = "barbarbarbar\n"; let echoed_string2 = "barbarbarbar\n"; let mut buf = [0u8; 13]; write(pty.slave, string2.as_bytes()).unwrap(); - read_exact(pty.master, &mut buf); + ::read_exact(pty.master, &mut buf); assert_eq!(&buf, echoed_string2.as_bytes()); |