summaryrefslogtreecommitdiff
path: root/test/test_unistd.rs
diff options
context:
space:
mode:
authorPhilipp Keller <philipp.keller@gmail.com>2016-09-05 21:50:06 +0200
committerPhilipp Keller <philipp.keller@gmail.com>2016-09-05 21:50:06 +0200
commit8b1828a5cd7c133156fc2bac703136e6d5abd31d (patch)
treefa26f5a9b1420f6af35ebb55ac6b2614127bdf7a /test/test_unistd.rs
parentb03d4e5ff22e0f8988dc8655c1e7dfcc3fe29f66 (diff)
downloadnix-8b1828a5cd7c133156fc2bac703136e6d5abd31d.zip
implemented mkdir, extended getcwd test to include long path names
Diffstat (limited to 'test/test_unistd.rs')
-rw-r--r--test/test_unistd.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 2b6182b6..26746426 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -3,6 +3,8 @@ extern crate tempdir;
use nix::unistd::*;
use nix::unistd::ForkResult::*;
use nix::sys::wait::*;
+use nix::sys::stat;
+use std::iter;
use std::ffi::CString;
use std::io::{Write, Read};
@@ -129,7 +131,18 @@ fn test_getcwd() {
} else {
"/tmp/"
};
- let tmp_dir = TempDir::new_in(base, "test_getcwd").expect("create temp dir").into_path();
+ let mut tmp_dir = TempDir::new_in(base, "test_getcwd").expect("create temp dir").into_path();
+ assert!(chdir(tmp_dir.as_path()).is_ok());
+ assert_eq!(getcwd().unwrap(), tmp_dir);
+
+ // make path 500 chars longer so that buffer doubling in getcwd kicks in.
+ // Note: One path cannot be longer than 255 bytes (NAME_MAX)
+ // whole path cannot be longer than PATH_MAX (usually 4096 on linux, 1024 on macos)
+ for _ in 0..5 {
+ let newdir = iter::repeat("a").take(100).collect::<String>();
+ tmp_dir.push(newdir);
+ assert!(mkdir(tmp_dir.as_path(), stat::S_IRWXU).is_ok());
+ }
assert!(chdir(tmp_dir.as_path()).is_ok());
assert_eq!(getcwd().unwrap(), tmp_dir);
}