mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
rm fully operational and error surveyd.
This commit is contained in:
@ -2,7 +2,6 @@ mod helpers;
|
||||
|
||||
use h::{in_directory as cwd, Playground, Stub::*};
|
||||
use helpers as h;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[test]
|
||||
fn lines() {
|
||||
@ -139,138 +138,3 @@ fn save_can_write_out_csv() {
|
||||
let actual = h::file_contents(&expected_file);
|
||||
assert!(actual.contains("[list list],A shell for the GitHub era,2018,ISC,nu,0.2.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rm_removes_a_file() {
|
||||
let sandbox = Playground::setup_for("rm_regular_file_test")
|
||||
.with_files(vec![EmptyFile("i_will_be_deleted.txt")])
|
||||
.test_dir_name();
|
||||
|
||||
nu!(
|
||||
_output,
|
||||
cwd(&Playground::root()),
|
||||
"rm rm_regular_file_test/i_will_be_deleted.txt"
|
||||
);
|
||||
|
||||
let path = &format!(
|
||||
"{}/{}/{}",
|
||||
Playground::root(),
|
||||
sandbox,
|
||||
"i_will_be_deleted.txt"
|
||||
);
|
||||
|
||||
assert!(!h::file_exists_at(PathBuf::from(path)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rm_removes_files_with_wildcard() {
|
||||
r#"
|
||||
Given these files and directories
|
||||
src
|
||||
src/cli.rs
|
||||
src/lib.rs
|
||||
src/prelude.rs
|
||||
src/parser
|
||||
src/parser/parse.rs
|
||||
src/parser/parser.rs
|
||||
src/parser/parse
|
||||
src/parser/hir
|
||||
src/parser/parse/token_tree.rs
|
||||
src/parser/hir/baseline_parse.rs
|
||||
src/parser/hir/baseline_parse_tokens.rs
|
||||
"#;
|
||||
|
||||
let sandbox = Playground::setup_for("rm_wildcard_test")
|
||||
.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);
|
||||
|
||||
r#" The pattern
|
||||
src/*/*/*.rs
|
||||
matches
|
||||
src/parser/parse/token_tree.rs
|
||||
src/parser/hir/baseline_parse.rs
|
||||
src/parser/hir/baseline_parse_tokens.rs
|
||||
"#;
|
||||
|
||||
nu!(
|
||||
_output,
|
||||
cwd("tests/fixtures/nuplayground/rm_wildcard_test"),
|
||||
"rm \"src/*/*/*.rs\""
|
||||
);
|
||||
|
||||
assert!(!h::files_exist_at(
|
||||
vec![
|
||||
Path::new("src/parser/parse/token_tree.rs"),
|
||||
Path::new("src/parser/hir/baseline_parse.rs"),
|
||||
Path::new("src/parser/hir/baseline_parse_tokens.rs")
|
||||
],
|
||||
PathBuf::from(&full_path)
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Playground::glob_vec(&format!("{}/src/*/*/*.rs", &full_path)),
|
||||
Vec::<PathBuf>::new()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rm_removes_directory_contents_with_recursive_flag() {
|
||||
let sandbox = Playground::setup_for("rm_directory_removal_recursively_test")
|
||||
.with_files(vec![
|
||||
EmptyFile("yehuda.txt"),
|
||||
EmptyFile("jonathan.txt"),
|
||||
EmptyFile("andres.txt"),
|
||||
])
|
||||
.test_dir_name();
|
||||
|
||||
nu!(
|
||||
_output,
|
||||
cwd("tests/fixtures/nuplayground"),
|
||||
"rm rm_directory_removal_recursively_test --recursive"
|
||||
);
|
||||
|
||||
let expected = format!("{}/{}", Playground::root(), sandbox);
|
||||
|
||||
assert!(!h::file_exists_at(PathBuf::from(expected)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rm_errors_if_attempting_to_delete_a_directory_without_recursive_flag() {
|
||||
let sandbox = Playground::setup_for("rm_prevent_directory_removal_without_flag_test").test_dir_name();
|
||||
let full_path = format!("{}/{}", Playground::root(), sandbox);
|
||||
|
||||
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"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user