-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add unistd::getcwd and unistd::mkdir #416
Changes from 3 commits
ac64273
b03d4e5
8b1828a
8fbd8e9
c0a5785
50693c1
37e4f97
5f1e144
7dd12c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
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}; | ||
use tempfile::tempfile; | ||
use tempdir::TempDir; | ||
use libc::off_t; | ||
use std::os::unix::prelude::*; | ||
|
||
|
||
|
||
#[test] | ||
fn test_fork_and_waitpid() { | ||
let pid = fork(); | ||
|
@@ -119,6 +122,31 @@ macro_rules! execve_test_factory( | |
) | ||
); | ||
|
||
#[test] | ||
fn test_getcwd() { | ||
// workaround for the fact that on os x TmpDir::new returns /var/folders/... but upon | ||
// chdir into that directory getcwd returns /private/var/folders/... | ||
let base = if cfg!(target_os = "macos") { | ||
"/private/tmp/" | ||
} else { | ||
"/tmp/" | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a little fragile. I think it would be OK to just verify that the nix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea, I'll change this and add documentation for |
||
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); | ||
} | ||
|
||
#[test] | ||
fn test_lseek() { | ||
const CONTENTS: &'static [u8] = b"abcdef123456"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint. I've corrected those now. Any idea why
cargo clippy
did not warn about those?