1 use rustix::io; 2 use rustix::termios::{isatty, ttyname}; 3 use std::fs::File; 4 5 #[test] test_ttyname_ok()6fn test_ttyname_ok() { 7 let file = match File::open("/dev/stdin") { 8 Ok(file) => file, 9 Err(err) if err.kind() == std::io::ErrorKind::PermissionDenied => return, 10 Err(err) => Err(err).unwrap(), 11 }; 12 if isatty(&file) { 13 assert!(ttyname(&file, Vec::new()) 14 .unwrap() 15 .into_string() 16 .unwrap() 17 .starts_with("/dev/")); 18 } 19 } 20 21 #[test] test_ttyname_not_tty()22fn test_ttyname_not_tty() { 23 let file = File::open("Cargo.toml").unwrap(); 24 assert_eq!(ttyname(&file, Vec::new()).unwrap_err(), io::Errno::NOTTY); 25 26 let file = File::open("/dev/null").unwrap(); 27 assert_eq!(ttyname(&file, Vec::new()).unwrap_err(), io::Errno::NOTTY); 28 } 29