fix: Command rm remove file with flag -r

This commit is contained in:
Ynit 2021-01-20 17:34:26 +08:00
parent 3877712774
commit 1d6cf15bf2
2 changed files with 17 additions and 1 deletions

View file

@ -49,7 +49,7 @@ impl Command for CommandImpl {
let result = if !path.exists() {
Ok(())
} else if path.is_file() {
fs::remove_file(&arguments[0])
fs::remove_file(&path)
} else if recursive {
fs::remove_dir_all(&path)
} else {

View file

@ -56,6 +56,22 @@ fn run_path_is_file() {
assert!(!path.exists());
}
#[test]
fn run_path_is_file_and_with_flag() {
let path = Path::new("./target/_duckscript/rm/file_with_flag.txt");
let result = ensure_exists("./target/_duckscript/rm/file_with_flag.txt");
assert!(result.is_ok());
assert!(path.exists());
test::run_script_and_validate(
vec![create("")],
"out = rm -r ./target/_duckscript/rm/file_with_flag.txt",
CommandValidation::Match("out".to_string(), "true".to_string()),
);
assert!(!path.exists());
}
#[test]
fn run_path_recursive() {
let path = Path::new("./target/_duckscript/rm/recursive/file.txt");