rust/tests/pass/shims/env/current_dir.rs

19 lines
834 B
Rust
Raw Normal View History

2022-07-08 11:08:32 -05:00
//@compile-flags: -Zmiri-disable-isolation
2019-09-24 14:42:38 -05:00
use std::env;
use std::io::ErrorKind;
2019-09-24 14:42:38 -05:00
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
assert!(env::set_current_dir("..").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);
// Test that `chdir` to a non-existing directory returns a proper error
assert_eq!(env::set_current_dir("thisdoesnotexist").unwrap_err().kind(), ErrorKind::NotFound);
2019-09-24 14:42:38 -05:00
}