]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/rename-directory.rs
417707e89322c27611f685ec7a724d73c87a7a3c
[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 // This test can't be a unit test in std,
12 // because it needs TempDir, which is in extra
13
14 // ignore-cross-compile
15
16 use std::env;
17 use std::ffi::CString;
18 use std::fs::{self, File};
19 use std::path::PathBuf;
20
21 fn rename_directory() {
22     let tmpdir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap());
23     let old_path = tmpdir.join("foo/bar/baz");
24     fs::create_dir_all(&old_path).unwrap();
25     let test_file = &old_path.join("temp.txt");
26
27     File::create(test_file).unwrap();
28
29     let new_path = tmpdir.join("quux/blat");
30     fs::create_dir_all(&new_path).unwrap();
31     fs::rename(&old_path, &new_path.join("newdir"));
32     assert!(new_path.join("newdir").is_dir());
33     assert!(new_path.join("newdir/temp.txt").exists());
34 }
35
36 pub fn main() { rename_directory() }