diff options
Diffstat (limited to 'test/test_pty.rs')
-rw-r--r-- | test/test_pty.rs | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/test/test_pty.rs b/test/test_pty.rs index 1a7cab81..3b52289e 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -1,15 +1,15 @@ use std::fs::File; use std::io::{Read, Write}; -use std::path::Path; use std::os::unix::prelude::*; +use std::path::Path; use tempfile::tempfile; use libc::{_exit, STDOUT_FILENO}; -use nix::fcntl::{OFlag, open}; +use nix::fcntl::{open, OFlag}; use nix::pty::*; use nix::sys::stat; use nix::sys::termios::*; -use nix::unistd::{write, close, pause}; +use nix::unistd::{close, pause, write}; /// Regression test for Issue #659 /// This is the correct way to explicitly close a `PtyMaster` @@ -36,7 +36,7 @@ fn test_ptsname_equivalence() { assert!(master_fd.as_raw_fd() > 0); // Get the name of the slave - let slave_name = unsafe { ptsname(&master_fd) }.unwrap() ; + let slave_name = unsafe { ptsname(&master_fd) }.unwrap(); let slave_name_r = ptsname_r(&master_fd).unwrap(); assert_eq!(slave_name, slave_name_r); } @@ -111,7 +111,9 @@ fn open_ptty_pair() -> (PtyMaster, File) { let slave_name = unsafe { ptsname(&master) }.expect("ptsname failed"); // Open the slave device - let slave_fd = open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty()).unwrap(); + let slave_fd = + open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty()) + .unwrap(); #[cfg(target_os = "illumos")] // TODO: rewrite using ioctl! @@ -279,9 +281,9 @@ fn test_openpty_with_termios() { #[test] fn test_forkpty() { - use nix::unistd::ForkResult::*; use nix::sys::signal::*; use nix::sys::wait::wait; + use nix::unistd::ForkResult::*; // forkpty calls openpty which uses ptname(3) internally. let _m0 = crate::PTSNAME_MTX.lock(); // forkpty spawns a child process @@ -289,15 +291,15 @@ fn test_forkpty() { let string = "naninani\n"; let echoed_string = "naninani\r\n"; - let pty = unsafe { - forkpty(None, None).unwrap() - }; + let pty = unsafe { forkpty(None, None).unwrap() }; match pty.fork_result { Child => { write(STDOUT_FILENO, string.as_bytes()).unwrap(); - pause(); // we need the child to stay alive until the parent calls read - unsafe { _exit(0); } - }, + pause(); // we need the child to stay alive until the parent calls read + unsafe { + _exit(0); + } + } Parent { child } => { let mut buf = [0u8; 10]; assert!(child.as_raw() > 0); @@ -306,6 +308,6 @@ fn test_forkpty() { wait().unwrap(); // keep other tests using generic wait from getting our child assert_eq!(&buf, echoed_string.as_bytes()); close(pty.master).unwrap(); - }, + } } } |