From f7a132f4280cb8b01ba78126acc0cbea91951634 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 19 Feb 2023 09:44:14 +0000 Subject: [PATCH] Move `rename_directory` from ui-fulldeps to std std has had a `TempDir` implementation for a long time now. --- library/std/src/fs/tests.rs | 16 ++++++++++++ tests/ui-fulldeps/std/rename-directory.rs | 30 ----------------------- 2 files changed, 16 insertions(+), 30 deletions(-) delete mode 100644 tests/ui-fulldeps/std/rename-directory.rs diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 839fdc96632..909d9bf4093 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1595,3 +1595,19 @@ fn test_read_dir_infinite_loop() { // Check for duplicate errors assert!(dir.filter(|e| e.is_err()).take(2).count() < 2); } + +#[test] +fn rename_directory() { + let tmpdir = tmpdir(); + let old_path = tmpdir.join("foo/bar/baz"); + fs::create_dir_all(&old_path).unwrap(); + let test_file = &old_path.join("temp.txt"); + + File::create(test_file).unwrap(); + + let new_path = tmpdir.join("quux/blat"); + fs::create_dir_all(&new_path).unwrap(); + fs::rename(&old_path, &new_path.join("newdir")).unwrap(); + assert!(new_path.join("newdir").is_dir()); + assert!(new_path.join("newdir/temp.txt").exists()); +} diff --git a/tests/ui-fulldeps/std/rename-directory.rs b/tests/ui-fulldeps/std/rename-directory.rs deleted file mode 100644 index 8fc340cb918..00000000000 --- a/tests/ui-fulldeps/std/rename-directory.rs +++ /dev/null @@ -1,30 +0,0 @@ -// run-pass - -#![allow(unused_must_use)] -#![allow(unused_imports)] -// This test can't be a unit test in std, -// because it needs TempDir, which is in extra - -// ignore-cross-compile - -use std::env; -use std::ffi::CString; -use std::fs::{self, File}; -use std::path::PathBuf; - -fn rename_directory() { - let tmpdir = PathBuf::from(env::var_os("RUST_TEST_TMPDIR").unwrap()); - let old_path = tmpdir.join("foo/bar/baz"); - fs::create_dir_all(&old_path).unwrap(); - let test_file = &old_path.join("temp.txt"); - - File::create(test_file).unwrap(); - - let new_path = tmpdir.join("quux/blat"); - fs::create_dir_all(&new_path).unwrap(); - fs::rename(&old_path, &new_path.join("newdir")); - assert!(new_path.join("newdir").is_dir()); - assert!(new_path.join("newdir/temp.txt").exists()); -} - -pub fn main() { rename_directory() }