xref: /third_party/rust/crates/rustix/tests/termios/ttyname.rs
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/rust/crates/rustix/tests/termios/
1b8a62b91Sopenharmony_ciuse rustix::io;
2b8a62b91Sopenharmony_ciuse rustix::termios::{isatty, ttyname};
3b8a62b91Sopenharmony_ciuse std::fs::File;
4b8a62b91Sopenharmony_ci
5b8a62b91Sopenharmony_ci#[test]
6b8a62b91Sopenharmony_cifn test_ttyname_ok() {
7b8a62b91Sopenharmony_ci    let file = File::open("/dev/stdin").unwrap();
8b8a62b91Sopenharmony_ci    if isatty(&file) {
9b8a62b91Sopenharmony_ci        assert!(ttyname(&file, Vec::new())
10b8a62b91Sopenharmony_ci            .unwrap()
11b8a62b91Sopenharmony_ci            .into_string()
12b8a62b91Sopenharmony_ci            .unwrap()
13b8a62b91Sopenharmony_ci            .starts_with("/dev/"));
14b8a62b91Sopenharmony_ci    }
15b8a62b91Sopenharmony_ci}
16b8a62b91Sopenharmony_ci
17b8a62b91Sopenharmony_ci#[test]
18b8a62b91Sopenharmony_cifn test_ttyname_not_tty() {
19b8a62b91Sopenharmony_ci    let file = File::open("Cargo.toml").unwrap();
20b8a62b91Sopenharmony_ci    assert_eq!(ttyname(&file, Vec::new()).unwrap_err(), io::Errno::NOTTY);
21b8a62b91Sopenharmony_ci
22b8a62b91Sopenharmony_ci    let file = File::open("/dev/null").unwrap();
23b8a62b91Sopenharmony_ci    assert_eq!(ttyname(&file, Vec::new()).unwrap_err(), io::Errno::NOTTY);
24b8a62b91Sopenharmony_ci}
25

Indexes created Thu Nov 07 10:32:03 CST 2024