Migrate rm

This commit is contained in:
Yehuda Katz 2019-08-28 10:48:52 -07:00
parent 2c65b2fc2f
commit abac7cf746

View file

@ -4,169 +4,162 @@ use h::{in_directory as cwd, Playground, Stub::*};
use helpers as h; use helpers as h;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
// #[test] #[test]
// fn rm_removes_a_file() { fn rm_removes_a_file() {
// let sandbox = Playground::setup_for("rm_regular_file_test") Playground::setup("rm_regular_file_test", |dirs, playground| {
// .with_files(vec![EmptyFile("i_will_be_deleted.txt")]) playground
// .test_dir_name(); .with_files(vec![EmptyFile("i_will_be_deleted.txt")])
.test_dir_name();
// nu!( nu!(dirs.root(), "rm rm_regular_file_test/i_will_be_deleted.txt");
// _output,
// cwd(&Playground::root()),
// "rm rm_regular_file_test/i_will_be_deleted.txt"
// );
// let path = &format!( let path = dirs.test().join("i_will_be_deleted.txt");
// "{}/{}/{}",
// Playground::root(),
// sandbox,
// "i_will_be_deleted.txt"
// );
// assert!(!h::file_exists_at(PathBuf::from(path))); assert!(!h::file_exists_at(path));
// } })
}
// #[test] #[test]
// fn rm_removes_files_with_wildcard() { fn rm_removes_files_with_wildcard() {
// let sandbox = Playground::setup_for("rm_wildcard_test_1") Playground::setup("rm_wildcard_test_1", |dirs, playground| {
// .within("src") playground
// .with_files(vec![ .within("src")
// EmptyFile("cli.rs"), .with_files(vec![
// EmptyFile("lib.rs"), EmptyFile("cli.rs"),
// EmptyFile("prelude.rs"), EmptyFile("lib.rs"),
// ]) EmptyFile("prelude.rs"),
// .within("src/parser") ])
// .with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")]) .within("src/parser")
// .within("src/parser/parse") .with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
// .with_files(vec![EmptyFile("token_tree.rs")]) .within("src/parser/parse")
// .within("src/parser/hir") .with_files(vec![EmptyFile("token_tree.rs")])
// .with_files(vec![ .within("src/parser/hir")
// EmptyFile("baseline_parse.rs"), .with_files(vec![
// EmptyFile("baseline_parse_tokens.rs"), EmptyFile("baseline_parse.rs"),
// ]) EmptyFile("baseline_parse_tokens.rs"),
// .test_dir_name(); ])
.test_dir_name();
// let full_path = format!("{}/{}", Playground::root(), sandbox); nu!(dirs.test(), r#"rm "src/*/*/*.rs""#);
// nu!( assert!(!h::files_exist_at(
// _output, vec![
// cwd("tests/fixtures/nuplayground/rm_wildcard_test_1"), "src/parser/parse/token_tree.rs",
// r#"rm "src/*/*/*.rs""# "src/parser/hir/baseline_parse.rs",
// ); "src/parser/hir/baseline_parse_tokens.rs"
],
dirs.test()
));
// assert!(!h::files_exist_at( assert_eq!(
// vec![ Playground::glob_vec(&format!("{}/src/*/*/*.rs", dirs.test().display())),
// Path::new("src/parser/parse/token_tree.rs"), Vec::<PathBuf>::new()
// Path::new("src/parser/hir/baseline_parse.rs"), );
// Path::new("src/parser/hir/baseline_parse_tokens.rs") })
// ], }
// PathBuf::from(&full_path)
// ));
// assert_eq!( #[test]
// Playground::glob_vec(&format!("{}/src/*/*/*.rs", &full_path)), fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
// Vec::<PathBuf>::new() Playground::setup("rm_wildcard_test_2", |dirs, playground| {
// ); playground
// } .within("src")
.with_files(vec![
EmptyFile("cli.rs"),
EmptyFile("lib.rs"),
EmptyFile("prelude.rs"),
])
.within("src/parser")
.with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
.within("src/parser/parse")
.with_files(vec![EmptyFile("token_tree.rs")])
.within("src/parser/hir")
.with_files(vec![
EmptyFile("baseline_parse.rs"),
EmptyFile("baseline_parse_tokens.rs"),
])
.test_dir_name();
// #[test] nu!(dirs.test(), "rm src/* --recursive");
// fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
// let sandbox = Playground::setup_for("rm_wildcard_test_2")
// .within("src")
// .with_files(vec![
// EmptyFile("cli.rs"),
// EmptyFile("lib.rs"),
// EmptyFile("prelude.rs"),
// ])
// .within("src/parser")
// .with_files(vec![EmptyFile("parse.rs"), EmptyFile("parser.rs")])
// .within("src/parser/parse")
// .with_files(vec![EmptyFile("token_tree.rs")])
// .within("src/parser/hir")
// .with_files(vec![
// EmptyFile("baseline_parse.rs"),
// EmptyFile("baseline_parse_tokens.rs"),
// ])
// .test_dir_name();
// let full_path = format!("{}/{}", Playground::root(), sandbox); assert!(!h::files_exist_at(
vec!["src/parser/parse", "src/parser/hir"],
dirs.test()
));
})
}
// nu!( #[test]
// _output, fn rm_removes_directory_contents_without_recursive_flag_if_empty() {
// cwd("tests/fixtures/nuplayground/rm_wildcard_test_2"), Playground::setup("rm_directory_removal_recursively_test_1", |dirs, _| {
// "rm src/* --recursive" nu!(dirs.root(), "rm rm_directory_removal_recursively_test_1");
// );
// assert!(!h::files_exist_at( assert!(!h::file_exists_at(dirs.test()));
// vec![Path::new("src/parser/parse"), Path::new("src/parser/hir"),], })
// PathBuf::from(&full_path) }
// ));
// }
// #[test] #[test]
// fn rm_removes_directory_contents_without_recursive_flag_if_empty() { fn rm_removes_directory_contents_with_recursive_flag() {
// let sandbox = Playground::setup_for("rm_directory_removal_recursively_test_1").test_dir_name(); Playground::setup(
"rm_directory_removal_recursively_test_2",
|dirs, playground| {
playground
.with_files(vec![
EmptyFile("yehuda.txt"),
EmptyFile("jonathan.txt"),
EmptyFile("andres.txt"),
])
.test_dir_name();
// nu!( nu!(
// _output, dirs.root(),
// cwd("tests/fixtures/nuplayground"), "rm rm_directory_removal_recursively_test_2 --recursive"
// "rm rm_directory_removal_recursively_test_1" );
// );
// let expected = format!("{}/{}", Playground::root(), sandbox); assert!(!h::file_exists_at(dirs.test()));
},
)
}
// assert!(!h::file_exists_at(PathBuf::from(expected))); #[test]
// } fn rm_errors_if_attempting_to_delete_a_directory_with_content_without_recursive_flag() {
Playground::setup(
"rm_prevent_directory_removal_without_flag_test",
|dirs, playground| {
playground
.with_files(vec![EmptyFile("some_empty_file.txt")])
.test_dir_name();
// #[test] let output = nu_error!(
// fn rm_removes_directory_contents_with_recursive_flag() { dirs.root(),
// let sandbox = Playground::setup_for("rm_directory_removal_recursively_test_2") "rm rm_prevent_directory_removal_without_flag_test"
// .with_files(vec![ );
// EmptyFile("yehuda.txt"),
// EmptyFile("jonathan.txt"),
// EmptyFile("andres.txt"),
// ])
// .test_dir_name();
// nu!( assert!(h::file_exists_at(dirs.test()));
// _output, assert!(output.contains("is a directory"));
// cwd("tests/fixtures/nuplayground"), },
// "rm rm_directory_removal_recursively_test_2 --recursive" )
// ); }
// let expected = format!("{}/{}", Playground::root(), sandbox); #[test]
fn rm_errors_if_attempting_to_delete_single_dot_as_argument() {
Playground::setup(
"rm_errors_if_attempting_to_delete_single_dot_as_argument",
|dirs, _| {
let output = nu_error!(dirs.root(), "rm .");
// assert!(!h::file_exists_at(PathBuf::from(expected))); assert!(output.contains("may not be removed"));
// } },
)
}
// #[test] #[test]
// fn rm_errors_if_attempting_to_delete_a_directory_with_content_without_recursive_flag() { fn rm_errors_if_attempting_to_delete_two_dot_as_argument() {
// let sandbox = Playground::setup_for("rm_prevent_directory_removal_without_flag_test") Playground::setup(
// .with_files(vec![EmptyFile("some_empty_file.txt")]) "rm_errors_if_attempting_to_delete_single_dot_as_argument",
// .test_dir_name(); |dirs, _| {
let output = nu_error!(dirs.root(), "rm ..");
// let full_path = format!("{}/{}", Playground::root(), sandbox); assert!(output.contains("may not be removed"));
},
// nu_error!( )
// output, }
// cwd(&Playground::root()),
// "rm rm_prevent_directory_removal_without_flag_test"
// );
// assert!(h::file_exists_at(PathBuf::from(full_path)));
// assert!(output.contains("is a directory"));
// }
// #[test]
// fn rm_errors_if_attempting_to_delete_single_dot_as_argument() {
// nu_error!(output, cwd(&Playground::root()), "rm .");
// assert!(output.contains("may not be removed"));
// }
// #[test]
// fn rm_errors_if_attempting_to_delete_two_dot_as_argument() {
// nu_error!(output, cwd(&Playground::root()), "rm ..");
// assert!(output.contains("may not be removed"));
// }