]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/rename-directory.rs
Auto merge of #54919 - alexcrichton:update-cargo, r=Mark-Simulacrum
[rust.git] / src / test / run-pass-fulldeps / rename-directory.rs
1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(unused_must_use)]
12 #![allow(unused_imports)]
13 // This test can't be a unit test in std,
14 // because it needs TempDir, which is in extra
15
16 // ignore-cross-compile
17
18 use std::env;
19 use std::ffi::CString;
20 use std::fs::{self, File};
21 use std::path::PathBuf;
22
23 fn rename_directory() {
24     let tmpdir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
25     let old_path = tmpdir.join("foo/bar/baz");
26     fs::create_dir_all(&old_path).unwrap();
27     let test_file = &old_path.join("temp.txt");
28
29     File::create(test_file).unwrap();
30
31     let new_path = tmpdir.join("quux/blat");
32     fs::create_dir_all(&new_path).unwrap();
33     fs::rename(&old_path, &new_path.join("newdir"));
34     assert!(new_path.join("newdir").is_dir());
35     assert!(new_path.join("newdir/temp.txt").exists());
36 }
37
38 pub fn main() { rename_directory() }