Skip to content

Commit 8180e99

Browse files
authored
Add a few more tests for ttyname and getcwd. (#833)
Add some tests that would catch the bug fixed in #832.
1 parent 83bc861 commit 8180e99

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

tests/process/working_directory.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ fn test_changing_working_directory() {
1515
let tmpdir = tmpdir();
1616

1717
let orig_cwd = rustix::process::getcwd(Vec::new()).expect("get the cwd");
18+
assert!(orig_cwd.to_str().unwrap().starts_with("/"));
19+
20+
assert_eq!(
21+
orig_cwd.to_str().unwrap(),
22+
std::env::current_dir().unwrap().display().to_string(),
23+
"rustix's cwd doesn't match std's"
24+
);
1825

1926
#[cfg(not(target_os = "fuchsia"))]
2027
let orig_fd_cwd = rustix::fs::openat(rustix::fs::CWD, ".", OFlags::RDONLY, Mode::empty())

tests/termios/ttyname.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustix::fs::FileTypeExt;
12
use rustix::io;
23
use rustix::termios::{isatty, ttyname};
34
use std::fs::File;
@@ -10,11 +11,13 @@ fn test_ttyname_ok() {
1011
Err(err) => Err(err).unwrap(),
1112
};
1213
if isatty(&file) {
13-
assert!(ttyname(&file, Vec::new())
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)
1418
.unwrap()
15-
.into_string()
16-
.unwrap()
17-
.starts_with("/dev/"));
19+
.file_type()
20+
.is_char_device());
1821
}
1922
}
2023

0 commit comments

Comments
 (0)