2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_one_file() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let file = "test_rm_one_file";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(file).succeeds().no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.file_exists(file));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_multiple_files() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let file_a = "test_rm_multiple_file_a";
|
|
|
|
let file_b = "test_rm_multiple_file_b";
|
|
|
|
|
|
|
|
at.touch(file_a);
|
|
|
|
at.touch(file_b);
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(file_a).arg(file_b).succeeds().no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
|
|
assert!(!at.file_exists(file_b));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_interactive() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2016-07-29 21:26:32 +00:00
|
|
|
let at = &scene.fixtures;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
let file_a = "test_rm_interactive_file_a";
|
|
|
|
let file_b = "test_rm_interactive_file_b";
|
|
|
|
|
|
|
|
at.touch(file_a);
|
|
|
|
at.touch(file_b);
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
2016-08-13 21:59:21 +00:00
|
|
|
.arg("-i")
|
|
|
|
.arg(file_a)
|
|
|
|
.arg(file_b)
|
|
|
|
.pipe_in("n")
|
|
|
|
.succeeds();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(at.file_exists(file_a));
|
|
|
|
assert!(at.file_exists(file_b));
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
2016-08-13 21:59:21 +00:00
|
|
|
.arg("-i")
|
|
|
|
.arg(file_a)
|
|
|
|
.arg(file_b)
|
|
|
|
.pipe_in("Yesh")
|
|
|
|
.succeeds();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
|
|
assert!(at.file_exists(file_b));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_force() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let file_a = "test_rm_force_a";
|
|
|
|
let file_b = "test_rm_force_b";
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg("-f")
|
|
|
|
.arg(file_a)
|
|
|
|
.arg(file_b)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
|
|
assert!(!at.file_exists(file_b));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_empty_directory() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let dir = "test_rm_empty_directory";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg("-d").arg(dir).succeeds().no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_recursive() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let dir = "test_rm_recursive_directory";
|
|
|
|
let file_a = "test_rm_recursive_directory/test_rm_recursive_file_a";
|
|
|
|
let file_b = "test_rm_recursive_directory/test_rm_recursive_file_b";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
at.touch(file_a);
|
|
|
|
at.touch(file_b);
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg("-r").arg(dir).succeeds().no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
|
|
assert!(!at.file_exists(file_b));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_errors() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let dir = "test_rm_errors_directory";
|
|
|
|
let file_a = "test_rm_errors_directory/test_rm_errors_file_a";
|
|
|
|
let file_b = "test_rm_errors_directory/test_rm_errors_file_b";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
at.touch(file_a);
|
|
|
|
at.touch(file_b);
|
|
|
|
|
|
|
|
// $ rm test_rm_errors_directory
|
|
|
|
// rm: error: could not remove directory 'test_rm_errors_directory' (did you mean to pass '-r'?)
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.arg(dir).fails().stderr_is(
|
|
|
|
"rm: error: could not remove directory 'test_rm_errors_directory' (did you mean \
|
|
|
|
to pass '-r'?)\n",
|
|
|
|
);
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_verbose() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let file_a = "test_rm_verbose_file_a";
|
|
|
|
let file_b = "test_rm_verbose_file_b";
|
|
|
|
|
|
|
|
at.touch(file_a);
|
|
|
|
at.touch(file_b);
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.arg("-v")
|
|
|
|
.arg(file_a)
|
|
|
|
.arg(file_b)
|
|
|
|
.succeeds()
|
2016-08-13 21:59:21 +00:00
|
|
|
.stdout_only(format!("removed '{}'\nremoved '{}'\n", file_a, file_b));
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2017-04-01 14:38:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_dir_symlink() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let dir = "test_rm_dir_symlink_dir";
|
|
|
|
let link = "test_rm_dir_symlink_link";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
2018-11-13 04:55:25 +00:00
|
|
|
at.symlink_dir(dir, link);
|
2017-04-01 14:38:38 +00:00
|
|
|
|
|
|
|
ucmd.arg(link).succeeds();
|
|
|
|
}
|
2017-04-08 16:03:16 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_invalid_symlink() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let link = "test_rm_invalid_symlink";
|
|
|
|
|
2018-11-13 04:55:25 +00:00
|
|
|
at.symlink_file(link, link);
|
2017-04-08 16:03:16 +00:00
|
|
|
|
|
|
|
ucmd.arg(link).succeeds();
|
|
|
|
}
|
2017-12-26 23:25:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_force_no_operand() {
|
|
|
|
let mut ucmd = new_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("-f").succeeds().no_stderr();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_no_operand() {
|
|
|
|
let mut ucmd = new_ucmd!();
|
|
|
|
|
|
|
|
ucmd.fails()
|
|
|
|
.stderr_is("rm: error: missing an argument\nrm: error: for help, try 'rm --help'\n");
|
|
|
|
}
|