mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
Migrate mv
This commit is contained in:
parent
21ad06b1e1
commit
2c65b2fc2f
@ -40,146 +40,139 @@ fn overwrites_if_moving_to_existing_file() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn moves_a_directory() {
|
fn moves_a_directory() {
|
||||||
// let sandbox = Playground::setup_for("mv_test_3")
|
Playground::setup("mv_test_3", |dirs, playground| {
|
||||||
// .mkdir("empty_dir")
|
playground.mkdir("empty_dir");
|
||||||
// .test_dir_name();
|
|
||||||
|
|
||||||
// let full_path = format!("{}/{}", Playground::root(), sandbox);
|
let original_dir = dirs.test().join("empty_dir");
|
||||||
// let original_dir = format!("{}/{}", full_path, "empty_dir");
|
let expected = dirs.test().join("renamed_dir");
|
||||||
// let expected = format!("{}/{}", full_path, "renamed_dir");
|
|
||||||
|
|
||||||
// nu!(_output, cwd(&full_path), "mv empty_dir renamed_dir");
|
nu!(dirs.test(), "mv empty_dir renamed_dir");
|
||||||
|
|
||||||
// assert!(!h::dir_exists_at(PathBuf::from(original_dir)));
|
assert!(!h::dir_exists_at(original_dir));
|
||||||
// assert!(h::dir_exists_at(PathBuf::from(expected)));
|
assert!(h::dir_exists_at(expected));
|
||||||
// }
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn moves_the_file_inside_directory_if_path_to_move_is_existing_directory() {
|
fn moves_the_file_inside_directory_if_path_to_move_is_existing_directory() {
|
||||||
// let sandbox = Playground::setup_for("mv_test_4")
|
Playground::setup("mv_test_4", |dirs, playground| {
|
||||||
// .with_files(vec![EmptyFile("jonathan.txt")])
|
playground
|
||||||
// .mkdir("expected")
|
.with_files(vec![EmptyFile("jonathan.txt")])
|
||||||
// .test_dir_name();
|
.mkdir("expected")
|
||||||
|
.test_dir_name();
|
||||||
|
|
||||||
// let full_path = format!("{}/{}", Playground::root(), sandbox);
|
let original_dir = dirs.test().join("jonathan.txt");
|
||||||
// let original_dir = format!("{}/{}", full_path, "jonathan.txt");
|
let expected = dirs.test().join("expected/jonathan.txt");
|
||||||
// let expected = format!("{}/{}", full_path, "expected/jonathan.txt");
|
|
||||||
|
|
||||||
// nu!(_output, cwd(&full_path), "mv jonathan.txt expected");
|
nu!(dirs.test(), "mv jonathan.txt expected");
|
||||||
|
|
||||||
// assert!(!h::file_exists_at(PathBuf::from(original_dir)));
|
assert!(!h::file_exists_at(original_dir));
|
||||||
// assert!(h::file_exists_at(PathBuf::from(expected)));
|
assert!(h::file_exists_at(expected));
|
||||||
// }
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory() {
|
fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory() {
|
||||||
// let sandbox = Playground::setup_for("mv_test_5")
|
Playground::setup("mv_test_5", |dirs, playground| {
|
||||||
// .within("contributors")
|
playground
|
||||||
// .with_files(vec![EmptyFile("jonathan.txt")])
|
.within("contributors")
|
||||||
// .mkdir("expected")
|
.with_files(vec![EmptyFile("jonathan.txt")])
|
||||||
// .test_dir_name();
|
.mkdir("expected")
|
||||||
|
.test_dir_name();
|
||||||
|
|
||||||
// let full_path = format!("{}/{}", Playground::root(), sandbox);
|
let original_dir = dirs.test().join("contributors");
|
||||||
// let original_dir = format!("{}/{}", full_path, "contributors");
|
let expected = dirs.test().join("expected/contributors");
|
||||||
// let expected = format!("{}/{}", full_path, "expected/contributors");
|
|
||||||
|
|
||||||
// nu!(_output, cwd(&full_path), "mv contributors expected");
|
nu!(dirs.test(), "mv contributors expected");
|
||||||
|
|
||||||
// assert!(!h::dir_exists_at(PathBuf::from(original_dir)));
|
assert!(!h::dir_exists_at(original_dir));
|
||||||
// assert!(h::file_exists_at(PathBuf::from(expected)));
|
assert!(h::file_exists_at(expected));
|
||||||
// }
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn moves_the_directory_inside_directory_if_path_to_move_is_nonexistent_directory() {
|
fn moves_the_directory_inside_directory_if_path_to_move_is_nonexistent_directory() {
|
||||||
// let sandbox = Playground::setup_for("mv_test_6")
|
Playground::setup("mv_test_6", |dirs, playground| {
|
||||||
// .within("contributors")
|
playground
|
||||||
// .with_files(vec![EmptyFile("jonathan.txt")])
|
.within("contributors")
|
||||||
// .mkdir("expected")
|
.with_files(vec![EmptyFile("jonathan.txt")])
|
||||||
// .test_dir_name();
|
.mkdir("expected")
|
||||||
|
.test_dir_name();
|
||||||
|
|
||||||
// let full_path = format!("{}/{}", Playground::root(), sandbox);
|
let original_dir = dirs.test().join("contributors");
|
||||||
// let original_dir = format!("{}/{}", full_path, "contributors");
|
|
||||||
|
|
||||||
// nu!(
|
nu!(
|
||||||
// _output,
|
dirs.test(),
|
||||||
// cwd(&full_path),
|
"mv contributors expected/this_dir_exists_now/los_tres_amigos"
|
||||||
// "mv contributors expected/this_dir_exists_now/los_tres_amigos"
|
);
|
||||||
// );
|
|
||||||
|
|
||||||
// let expected = format!(
|
let expected = dirs
|
||||||
// "{}/{}",
|
.test()
|
||||||
// full_path, "expected/this_dir_exists_now/los_tres_amigos"
|
.join("expected/this_dir_exists_now/los_tres_amigos");
|
||||||
// );
|
|
||||||
|
|
||||||
// assert!(!h::dir_exists_at(PathBuf::from(original_dir)));
|
assert!(!h::dir_exists_at(original_dir));
|
||||||
// assert!(h::file_exists_at(PathBuf::from(expected)));
|
assert!(h::file_exists_at(expected));
|
||||||
// }
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn moves_using_path_with_wildcard() {
|
fn moves_using_path_with_wildcard() {
|
||||||
// let sandbox = Playground::setup_for("mv_test_7")
|
Playground::setup("mv_test_7", |dirs, playground| {
|
||||||
// .within("originals")
|
playground
|
||||||
// .with_files(vec![
|
.within("originals")
|
||||||
// EmptyFile("andres.ini"),
|
.with_files(vec![
|
||||||
// EmptyFile("caco3_plastics.csv"),
|
EmptyFile("andres.ini"),
|
||||||
// EmptyFile("cargo_sample.toml"),
|
EmptyFile("caco3_plastics.csv"),
|
||||||
// EmptyFile("jonathan.ini"),
|
EmptyFile("cargo_sample.toml"),
|
||||||
// EmptyFile("jonathan.xml"),
|
EmptyFile("jonathan.ini"),
|
||||||
// EmptyFile("sgml_description.json"),
|
EmptyFile("jonathan.xml"),
|
||||||
// EmptyFile("sample.ini"),
|
EmptyFile("sgml_description.json"),
|
||||||
// EmptyFile("utf16.ini"),
|
EmptyFile("sample.ini"),
|
||||||
// EmptyFile("yehuda.ini"),
|
EmptyFile("utf16.ini"),
|
||||||
// ])
|
EmptyFile("yehuda.ini"),
|
||||||
// .mkdir("work_dir")
|
])
|
||||||
// .mkdir("expected")
|
.mkdir("work_dir")
|
||||||
// .test_dir_name();
|
.mkdir("expected")
|
||||||
|
.test_dir_name();
|
||||||
|
|
||||||
// let full_path = format!("{}/{}", Playground::root(), sandbox);
|
let work_dir = dirs.test().join("work_dir");
|
||||||
// let work_dir = format!("{}/{}", full_path, "work_dir");
|
let expected = dirs.test().join("expected");
|
||||||
// let expected_copies_path = format!("{}/{}", full_path, "expected");
|
|
||||||
|
|
||||||
// nu!(_output, cwd(&work_dir), "mv ../originals/*.ini ../expected");
|
nu!(work_dir, "mv ../originals/*.ini ../expected");
|
||||||
|
|
||||||
// assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
// vec![
|
vec!["yehuda.ini", "jonathan.ini", "sample.ini", "andres.ini",],
|
||||||
// Path::new("yehuda.ini"),
|
expected
|
||||||
// Path::new("jonathan.ini"),
|
));
|
||||||
// Path::new("sample.ini"),
|
})
|
||||||
// Path::new("andres.ini"),
|
}
|
||||||
// ],
|
|
||||||
// PathBuf::from(&expected_copies_path)
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn moves_using_a_glob() {
|
fn moves_using_a_glob() {
|
||||||
// let sandbox = Playground::setup_for("mv_test_8")
|
Playground::setup("mv_test_8", |dirs, playground| {
|
||||||
// .within("meals")
|
playground
|
||||||
// .with_files(vec![
|
.within("meals")
|
||||||
// EmptyFile("arepa.txt"),
|
.with_files(vec![
|
||||||
// EmptyFile("empanada.txt"),
|
EmptyFile("arepa.txt"),
|
||||||
// EmptyFile("taquiza.txt"),
|
EmptyFile("empanada.txt"),
|
||||||
// ])
|
EmptyFile("taquiza.txt"),
|
||||||
// .mkdir("work_dir")
|
])
|
||||||
// .mkdir("expected")
|
.mkdir("work_dir")
|
||||||
// .test_dir_name();
|
.mkdir("expected")
|
||||||
|
.test_dir_name();
|
||||||
|
|
||||||
// let full_path = format!("{}/{}", Playground::root(), sandbox);
|
let meal_dir = dirs.test().join("meals");
|
||||||
// let meal_dir = format!("{}/{}", full_path, "meals");
|
let work_dir = dirs.test().join("work_dir");
|
||||||
// let work_dir = format!("{}/{}", full_path, "work_dir");
|
let expected = dirs.test().join("expected");
|
||||||
// let expected_copies_path = format!("{}/{}", full_path, "expected");
|
|
||||||
|
|
||||||
// nu!(_output, cwd(&work_dir), "mv ../meals/* ../expected");
|
nu!(work_dir, "mv ../meals/* ../expected");
|
||||||
|
|
||||||
// assert!(h::dir_exists_at(PathBuf::from(meal_dir)));
|
assert!(h::dir_exists_at(meal_dir));
|
||||||
// assert!(h::files_exist_at(
|
assert!(h::files_exist_at(
|
||||||
// vec![
|
vec!["arepa.txt", "empanada.txt", "taquiza.txt",],
|
||||||
// Path::new("arepa.txt"),
|
expected
|
||||||
// Path::new("empanada.txt"),
|
));
|
||||||
// Path::new("taquiza.txt"),
|
})
|
||||||
// ],
|
}
|
||||||
// PathBuf::from(&expected_copies_path)
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
|
@ -345,7 +345,7 @@ pub fn copy_file_to(source: &str, destination: &str) {
|
|||||||
std::fs::copy(source, destination).expect("can not copy file");
|
std::fs::copy(source, destination).expect("can not copy file");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn files_exist_at(files: Vec<&Path>, path: impl AsRef<Path>) -> bool {
|
pub fn files_exist_at(files: Vec<impl AsRef<Path>>, path: impl AsRef<Path>) -> bool {
|
||||||
files.iter().all(|f| {
|
files.iter().all(|f| {
|
||||||
let mut loc = PathBuf::from(path.as_ref());
|
let mut loc = PathBuf::from(path.as_ref());
|
||||||
loc.push(f);
|
loc.push(f);
|
||||||
|
Loading…
Reference in New Issue
Block a user