rust/tests/run-pass/current_dir.rs

18 lines
725 B
Rust
Raw Normal View History

2019-09-24 14:42:38 -05:00
// ignore-windows: TODO the windows hook is not done yet
// compile-flags: -Zmiri-disable-isolation
use std::env;
use std::path::Path;
fn main() {
2019-10-11 04:17:43 -05:00
// Test that `getcwd` is available
2019-09-24 14:42:38 -05:00
let cwd = env::current_dir().unwrap();
2019-10-11 04:17:43 -05:00
// Test that changing dir to `..` actually sets the current directory to the parent of `cwd`.
// The only exception here is if `cwd` is the root directory, then changing directory must
2019-10-11 02:35:50 -05:00
// keep the current directory equal to `cwd`.
2019-09-24 14:42:38 -05:00
let parent = cwd.parent().unwrap_or(&cwd);
2019-10-11 04:17:43 -05:00
// Test that `chdir` is available
2019-09-24 14:42:38 -05:00
assert!(env::set_current_dir(&Path::new("..")).is_ok());
2019-10-11 04:17:43 -05:00
// Test that `..` goes to the parent directory
2019-09-24 14:42:38 -05:00
assert_eq!(env::current_dir().unwrap(), parent);
}