summaryrefslogtreecommitdiff
path: root/test/test_unistd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_unistd.rs')
-rw-r--r--test/test_unistd.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index d281f9b2..76ab442a 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -6,6 +6,7 @@ use nix::sys::wait::*;
use nix::sys::stat;
use std::iter;
use std::ffi::CString;
+use std::fs::File;
use std::io::{Write, Read};
use std::os::unix::prelude::*;
use std::env::current_dir;
@@ -142,6 +143,24 @@ macro_rules! execve_test_factory(
);
#[test]
+fn test_fchdir() {
+ let tmpdir = TempDir::new("test_fchdir").unwrap();
+ let tmpdir_path = tmpdir.path().canonicalize().unwrap();
+ let tmpdir_fd = File::open(&tmpdir_path).unwrap().into_raw_fd();
+ let olddir_path = getcwd().unwrap();
+ let olddir_fd = File::open(&olddir_path).unwrap().into_raw_fd();
+
+ assert!(fchdir(tmpdir_fd).is_ok());
+ assert_eq!(getcwd().unwrap(), tmpdir_path);
+
+ assert!(fchdir(olddir_fd).is_ok());
+ assert_eq!(getcwd().unwrap(), olddir_path);
+
+ assert!(close(olddir_fd).is_ok());
+ assert!(close(tmpdir_fd).is_ok());
+}
+
+#[test]
fn test_getcwd() {
let tmp_dir = TempDir::new("test_getcwd").unwrap();
assert!(chdir(tmp_dir.path()).is_ok());