summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/tests/termios/ttyname.rs
blob: 636178c31a2457cbed7c17cd3c52ede2d8ffd80e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use rustix::io;
use rustix::termios::{isatty, ttyname};
use std::fs::File;

#[test]
fn test_ttyname_ok() {
    let file = File::open("/dev/stdin").unwrap();
    if isatty(&file) {
        assert!(ttyname(&file, Vec::new())
            .unwrap()
            .into_string()
            .unwrap()
            .starts_with("/dev/"));
    }
}

#[test]
fn test_ttyname_not_tty() {
    let file = File::open("Cargo.toml").unwrap();
    assert_eq!(ttyname(&file, Vec::new()).unwrap_err(), io::Errno::NOTTY);

    let file = File::open("/dev/null").unwrap();
    assert_eq!(ttyname(&file, Vec::new()).unwrap_err(), io::Errno::NOTTY);
}