]> git.lizzy.rs Git - rust.git/blob - tests/ui-fulldeps/rename-directory.rs
Rollup merge of #106644 - alexcrichton:update-wasi-toolchain, r=cuviper
[rust.git] / tests / ui-fulldeps / rename-directory.rs
1 // run-pass
2
3 #![allow(unused_must_use)]
4 #![allow(unused_imports)]
5 // This test can't be a unit test in std,
6 // because it needs TempDir, which is in extra
7
8 // ignore-cross-compile
9
10 use std::env;
11 use std::ffi::CString;
12 use std::fs::{self, File};
13 use std::path::PathBuf;
14
15 fn rename_directory() {
16     let tmpdir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
17     let old_path = tmpdir.join("foo/bar/baz");
18     fs::create_dir_all(&old_path).unwrap();
19     let test_file = &old_path.join("temp.txt");
20
21     File::create(test_file).unwrap();
22
23     let new_path = tmpdir.join("quux/blat");
24     fs::create_dir_all(&new_path).unwrap();
25     fs::rename(&old_path, &new_path.join("newdir"));
26     assert!(new_path.join("newdir").is_dir());
27     assert!(new_path.join("newdir/temp.txt").exists());
28 }
29
30 pub fn main() { rename_directory() }