Migrate mv

This commit is contained in:
Yehuda Katz 2019-08-28 10:28:58 -07:00
parent 21ad06b1e1
commit 2c65b2fc2f
2 changed files with 113 additions and 120 deletions

View File

@ -40,146 +40,139 @@ fn overwrites_if_moving_to_existing_file() {
})
}
// #[test]
// fn moves_a_directory() {
// let sandbox = Playground::setup_for("mv_test_3")
// .mkdir("empty_dir")
// .test_dir_name();
#[test]
fn moves_a_directory() {
Playground::setup("mv_test_3", |dirs, playground| {
playground.mkdir("empty_dir");
// let full_path = format!("{}/{}", Playground::root(), sandbox);
// let original_dir = format!("{}/{}", full_path, "empty_dir");
// let expected = format!("{}/{}", full_path, "renamed_dir");
let original_dir = dirs.test().join("empty_dir");
let expected = dirs.test().join("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(PathBuf::from(expected)));
// }
assert!(!h::dir_exists_at(original_dir));
assert!(h::dir_exists_at(expected));
})
}
// #[test]
// fn moves_the_file_inside_directory_if_path_to_move_is_existing_directory() {
// let sandbox = Playground::setup_for("mv_test_4")
// .with_files(vec![EmptyFile("jonathan.txt")])
// .mkdir("expected")
// .test_dir_name();
#[test]
fn moves_the_file_inside_directory_if_path_to_move_is_existing_directory() {
Playground::setup("mv_test_4", |dirs, playground| {
playground
.with_files(vec![EmptyFile("jonathan.txt")])
.mkdir("expected")
.test_dir_name();
// let full_path = format!("{}/{}", Playground::root(), sandbox);
// let original_dir = format!("{}/{}", full_path, "jonathan.txt");
// let expected = format!("{}/{}", full_path, "expected/jonathan.txt");
let original_dir = dirs.test().join("jonathan.txt");
let expected = dirs.test().join("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(PathBuf::from(expected)));
// }
assert!(!h::file_exists_at(original_dir));
assert!(h::file_exists_at(expected));
})
}
// #[test]
// fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory() {
// let sandbox = Playground::setup_for("mv_test_5")
// .within("contributors")
// .with_files(vec![EmptyFile("jonathan.txt")])
// .mkdir("expected")
// .test_dir_name();
#[test]
fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory() {
Playground::setup("mv_test_5", |dirs, playground| {
playground
.within("contributors")
.with_files(vec![EmptyFile("jonathan.txt")])
.mkdir("expected")
.test_dir_name();
// let full_path = format!("{}/{}", Playground::root(), sandbox);
// let original_dir = format!("{}/{}", full_path, "contributors");
// let expected = format!("{}/{}", full_path, "expected/contributors");
let original_dir = dirs.test().join("contributors");
let expected = dirs.test().join("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::file_exists_at(PathBuf::from(expected)));
// }
assert!(!h::dir_exists_at(original_dir));
assert!(h::file_exists_at(expected));
})
}
// #[test]
// fn moves_the_directory_inside_directory_if_path_to_move_is_nonexistent_directory() {
// let sandbox = Playground::setup_for("mv_test_6")
// .within("contributors")
// .with_files(vec![EmptyFile("jonathan.txt")])
// .mkdir("expected")
// .test_dir_name();
#[test]
fn moves_the_directory_inside_directory_if_path_to_move_is_nonexistent_directory() {
Playground::setup("mv_test_6", |dirs, playground| {
playground
.within("contributors")
.with_files(vec![EmptyFile("jonathan.txt")])
.mkdir("expected")
.test_dir_name();
// let full_path = format!("{}/{}", Playground::root(), sandbox);
// let original_dir = format!("{}/{}", full_path, "contributors");
let original_dir = dirs.test().join("contributors");
// nu!(
// _output,
// cwd(&full_path),
// "mv contributors expected/this_dir_exists_now/los_tres_amigos"
// );
nu!(
dirs.test(),
"mv contributors expected/this_dir_exists_now/los_tres_amigos"
);
// let expected = format!(
// "{}/{}",
// full_path, "expected/this_dir_exists_now/los_tres_amigos"
// );
let expected = dirs
.test()
.join("expected/this_dir_exists_now/los_tres_amigos");
// assert!(!h::dir_exists_at(PathBuf::from(original_dir)));
// assert!(h::file_exists_at(PathBuf::from(expected)));
// }
assert!(!h::dir_exists_at(original_dir));
assert!(h::file_exists_at(expected));
})
}
// #[test]
// fn moves_using_path_with_wildcard() {
// let sandbox = Playground::setup_for("mv_test_7")
// .within("originals")
// .with_files(vec![
// EmptyFile("andres.ini"),
// EmptyFile("caco3_plastics.csv"),
// EmptyFile("cargo_sample.toml"),
// EmptyFile("jonathan.ini"),
// EmptyFile("jonathan.xml"),
// EmptyFile("sgml_description.json"),
// EmptyFile("sample.ini"),
// EmptyFile("utf16.ini"),
// EmptyFile("yehuda.ini"),
// ])
// .mkdir("work_dir")
// .mkdir("expected")
// .test_dir_name();
#[test]
fn moves_using_path_with_wildcard() {
Playground::setup("mv_test_7", |dirs, playground| {
playground
.within("originals")
.with_files(vec![
EmptyFile("andres.ini"),
EmptyFile("caco3_plastics.csv"),
EmptyFile("cargo_sample.toml"),
EmptyFile("jonathan.ini"),
EmptyFile("jonathan.xml"),
EmptyFile("sgml_description.json"),
EmptyFile("sample.ini"),
EmptyFile("utf16.ini"),
EmptyFile("yehuda.ini"),
])
.mkdir("work_dir")
.mkdir("expected")
.test_dir_name();
// let full_path = format!("{}/{}", Playground::root(), sandbox);
// let work_dir = format!("{}/{}", full_path, "work_dir");
// let expected_copies_path = format!("{}/{}", full_path, "expected");
let work_dir = dirs.test().join("work_dir");
let expected = dirs.test().join("expected");
// nu!(_output, cwd(&work_dir), "mv ../originals/*.ini ../expected");
nu!(work_dir, "mv ../originals/*.ini ../expected");
// assert!(h::files_exist_at(
// vec![
// Path::new("yehuda.ini"),
// Path::new("jonathan.ini"),
// Path::new("sample.ini"),
// Path::new("andres.ini"),
// ],
// PathBuf::from(&expected_copies_path)
// ));
// }
assert!(h::files_exist_at(
vec!["yehuda.ini", "jonathan.ini", "sample.ini", "andres.ini",],
expected
));
})
}
// #[test]
// fn moves_using_a_glob() {
// let sandbox = Playground::setup_for("mv_test_8")
// .within("meals")
// .with_files(vec![
// EmptyFile("arepa.txt"),
// EmptyFile("empanada.txt"),
// EmptyFile("taquiza.txt"),
// ])
// .mkdir("work_dir")
// .mkdir("expected")
// .test_dir_name();
#[test]
fn moves_using_a_glob() {
Playground::setup("mv_test_8", |dirs, playground| {
playground
.within("meals")
.with_files(vec![
EmptyFile("arepa.txt"),
EmptyFile("empanada.txt"),
EmptyFile("taquiza.txt"),
])
.mkdir("work_dir")
.mkdir("expected")
.test_dir_name();
// let full_path = format!("{}/{}", Playground::root(), sandbox);
// let meal_dir = format!("{}/{}", full_path, "meals");
// let work_dir = format!("{}/{}", full_path, "work_dir");
// let expected_copies_path = format!("{}/{}", full_path, "expected");
let meal_dir = dirs.test().join("meals");
let work_dir = dirs.test().join("work_dir");
let expected = dirs.test().join("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::files_exist_at(
// vec![
// Path::new("arepa.txt"),
// Path::new("empanada.txt"),
// Path::new("taquiza.txt"),
// ],
// PathBuf::from(&expected_copies_path)
// ));
// }
assert!(h::dir_exists_at(meal_dir));
assert!(h::files_exist_at(
vec!["arepa.txt", "empanada.txt", "taquiza.txt",],
expected
));
})
}

View File

@ -345,7 +345,7 @@ pub fn copy_file_to(source: &str, destination: &str) {
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| {
let mut loc = PathBuf::from(path.as_ref());
loc.push(f);