| 5 | |
| 6 | #[test] |
| 7 | fn test_ttyname_ok() { |
| 8 | let file = match File::open("/dev/stdin") { |
| 9 | Ok(file) => file, |
| 10 | Err(err) if err.kind() == std::io::ErrorKind::PermissionDenied => return, |
| 11 | Err(err) => panic!("{:?}", err), |
| 12 | }; |
| 13 | if isatty(&file) { |
| 14 | let name = ttyname(&file, Vec::new()).unwrap().into_string().unwrap(); |
| 15 | assert!(name.starts_with("/dev/")); |
| 16 | assert!(!name.ends_with('/')); |
| 17 | assert!(std::fs::metadata(&name) |
| 18 | .unwrap() |
| 19 | .file_type() |
| 20 | .is_char_device()); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | #[test] |
| 25 | fn test_ttyname_not_tty() { |