Skip to content

Commit

Permalink
Add a few more tests for ttyname and getcwd. (#833)
Browse files Browse the repository at this point in the history
Add some tests that would catch the bug fixed in #832.
  • Loading branch information
sunfishcode authored Sep 19, 2023
1 parent 83bc861 commit 8180e99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions tests/process/working_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ fn test_changing_working_directory() {
let tmpdir = tmpdir();

let orig_cwd = rustix::process::getcwd(Vec::new()).expect("get the cwd");
assert!(orig_cwd.to_str().unwrap().starts_with("/"));

assert_eq!(
orig_cwd.to_str().unwrap(),
std::env::current_dir().unwrap().display().to_string(),
"rustix's cwd doesn't match std's"
);

#[cfg(not(target_os = "fuchsia"))]
let orig_fd_cwd = rustix::fs::openat(rustix::fs::CWD, ".", OFlags::RDONLY, Mode::empty())
Expand Down
11 changes: 7 additions & 4 deletions tests/termios/ttyname.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustix::fs::FileTypeExt;
use rustix::io;
use rustix::termios::{isatty, ttyname};
use std::fs::File;
Expand All @@ -10,11 +11,13 @@ fn test_ttyname_ok() {
Err(err) => Err(err).unwrap(),
};
if isatty(&file) {
assert!(ttyname(&file, Vec::new())
let name = ttyname(&file, Vec::new()).unwrap().into_string().unwrap();
assert!(name.starts_with("/dev/"));
assert!(!name.ends_with("/"));
assert!(std::fs::metadata(&name)
.unwrap()
.into_string()
.unwrap()
.starts_with("/dev/"));
.file_type()
.is_char_device());
}
}

Expand Down

0 comments on commit 8180e99

Please sign in to comment.