2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[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));
|
|
|
|
}
|
|
|
|
|
2020-11-08 22:26:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_rm_failed() {
|
|
|
|
let (_at, mut ucmd) = at_and_ucmd!();
|
2021-04-05 22:04:49 +00:00
|
|
|
let file = "test_rm_one_file"; // Doesn't exist
|
2021-03-25 22:04:02 +00:00
|
|
|
|
2021-04-05 22:04:49 +00:00
|
|
|
ucmd.arg(file).fails().stderr_contains(&format!(
|
2021-03-25 22:04:02 +00:00
|
|
|
"cannot remove '{}': No such file or directory",
|
|
|
|
file
|
2021-04-05 22:04:49 +00:00
|
|
|
));
|
2020-11-08 22:26:42 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[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)
|
2021-05-31 03:55:28 +00:00
|
|
|
.pipe_in("Yesh") // spell-checker:disable-line
|
2016-08-13 21:59:21 +00:00
|
|
|
.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));
|
|
|
|
}
|
|
|
|
|
2020-12-25 13:21:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_rm_force_multiple() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file_a = "test_rm_force_a";
|
|
|
|
let file_b = "test_rm_force_b";
|
|
|
|
|
|
|
|
ucmd.arg("-f")
|
|
|
|
.arg("-f")
|
|
|
|
.arg("-f")
|
|
|
|
.arg(file_a)
|
|
|
|
.arg(file_b)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
|
|
assert!(!at.file_exists(file_b));
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[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));
|
|
|
|
}
|
|
|
|
|
2021-03-25 22:04:02 +00:00
|
|
|
#[test]
|
|
|
|
fn test_rm_empty_directory_verbose() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let dir = "test_rm_empty_directory_verbose";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
|
|
|
|
ucmd.arg("-d")
|
|
|
|
.arg("-v")
|
|
|
|
.arg(dir)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only(format!("removed directory '{}'\n", dir));
|
|
|
|
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
2021-03-18 13:46:56 +00:00
|
|
|
#[test]
|
|
|
|
fn test_rm_non_empty_directory() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let dir = "test_rm_non_empty_dir";
|
|
|
|
let file_a = &format!("{}/test_rm_non_empty_file_a", dir);
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
at.touch(file_a);
|
|
|
|
|
2021-04-05 22:04:49 +00:00
|
|
|
ucmd.arg("-d")
|
|
|
|
.arg(dir)
|
|
|
|
.fails()
|
|
|
|
.stderr_contains(&format!("cannot remove '{}': Directory not empty", dir));
|
2021-03-18 13:46:56 +00:00
|
|
|
assert!(at.file_exists(file_a));
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[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));
|
|
|
|
}
|
|
|
|
|
2021-10-29 04:50:58 +00:00
|
|
|
#[test]
|
|
|
|
fn test_rm_recursive_multiple() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
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);
|
|
|
|
|
|
|
|
ucmd.arg("-r")
|
|
|
|
.arg("-r")
|
|
|
|
.arg("-r")
|
|
|
|
.arg(dir)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
|
|
assert!(!at.file_exists(file_b));
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[test]
|
2021-03-25 22:04:02 +00:00
|
|
|
fn test_rm_directory_without_flag() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-25 22:04:02 +00:00
|
|
|
let dir = "test_rm_directory_without_flag_dir";
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
at.mkdir(dir);
|
2021-03-30 19:24:01 +00:00
|
|
|
|
2021-04-05 22:04:49 +00:00
|
|
|
ucmd.arg(dir)
|
|
|
|
.fails()
|
|
|
|
.stderr_contains(&format!("cannot remove '{}': Is a directory", dir));
|
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]
|
2021-03-25 22:04:02 +00:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
// on unix symlink_dir is a file
|
|
|
|
fn test_rm_symlink_dir() {
|
2017-04-01 14:38:38 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-25 22:04:02 +00:00
|
|
|
|
|
|
|
let dir = "test_rm_symlink_dir_directory";
|
|
|
|
let link = "test_rm_symlink_dir_link";
|
2017-04-01 14:38:38 +00:00
|
|
|
|
|
|
|
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();
|
2021-03-25 22:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(windows)]
|
|
|
|
// on windows removing symlink_dir requires "-r" or "-d"
|
|
|
|
fn test_rm_symlink_dir() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
let dir = "test_rm_symlink_dir_directory";
|
|
|
|
let link = "test_rm_symlink_dir_link";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
at.symlink_dir(dir, link);
|
|
|
|
|
2021-04-05 22:04:49 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg(link)
|
|
|
|
.fails()
|
|
|
|
.stderr_contains(&format!("cannot remove '{}': Is a directory", link));
|
2021-03-25 22:04:02 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(link));
|
|
|
|
|
|
|
|
scene.ucmd().arg("-r").arg(link).succeeds();
|
2017-04-01 14:38:38 +00:00
|
|
|
}
|
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() {
|
2021-07-27 05:21:12 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
ts.ucmd().fails().stderr_is(&format!(
|
2021-12-29 20:57:55 +00:00
|
|
|
"{0}: missing operand\nTry '{1} {0} --help' for more information.\n",
|
2021-07-27 05:21:12 +00:00
|
|
|
ts.util_name,
|
|
|
|
ts.bin_path.to_string_lossy()
|
|
|
|
));
|
2017-12-26 23:25:03 +00:00
|
|
|
}
|
2021-04-05 20:18:47 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_verbose_slash() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let dir = "test_rm_verbose_slash_directory";
|
|
|
|
let file_a = &format!("{}/test_rm_verbose_slash_file_a", dir);
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
at.touch(file_a);
|
|
|
|
|
|
|
|
let file_a_normalized = &format!(
|
|
|
|
"{}{}test_rm_verbose_slash_file_a",
|
|
|
|
dir,
|
|
|
|
std::path::MAIN_SEPARATOR
|
|
|
|
);
|
|
|
|
|
|
|
|
ucmd.arg("-r")
|
|
|
|
.arg("-f")
|
|
|
|
.arg("-v")
|
|
|
|
.arg(&format!("{}///", dir))
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only(format!(
|
|
|
|
"removed '{}'\nremoved directory '{}'\n",
|
|
|
|
file_a_normalized, dir
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
|
|
}
|
2021-11-04 09:04:26 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_silently_accepts_presume_input_tty2() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file_2 = "test_rm_silently_accepts_presume_input_tty2";
|
|
|
|
|
|
|
|
at.touch(file_2);
|
|
|
|
|
|
|
|
ucmd.arg("---presume-input-tty").arg(file_2).succeeds();
|
|
|
|
|
|
|
|
assert!(!at.file_exists(file_2));
|
|
|
|
}
|
2022-04-02 22:35:35 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rm_interactive_never() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
let file_2 = "test_rm_interactive";
|
|
|
|
|
|
|
|
at.touch(file_2);
|
|
|
|
#[cfg(feature = "chmod")]
|
|
|
|
scene.ccmd("chmod").arg("0").arg(file_2).succeeds();
|
|
|
|
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("--interactive=never")
|
|
|
|
.arg(file_2)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
|
|
|
|
|
|
|
assert!(!at.file_exists(file_2));
|
|
|
|
}
|
2022-07-17 20:34:04 +00:00
|
|
|
|
2022-10-05 11:35:31 +00:00
|
|
|
#[test]
|
|
|
|
fn test_rm_descend_directory() {
|
|
|
|
// This test descends into each directory and deletes the files and folders inside of them
|
|
|
|
// This test will have the rm process asks 6 question and us answering Y to them will delete all the files and folders
|
|
|
|
use std::io::Write;
|
|
|
|
use std::process::Child;
|
|
|
|
|
|
|
|
// Needed for talking with stdin on platforms where CRLF or LF matters
|
|
|
|
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };
|
|
|
|
|
|
|
|
let yes = format!("y{}", END_OF_LINE);
|
|
|
|
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
let file_1 = "a/at.txt";
|
|
|
|
let file_2 = "a/b/bt.txt";
|
|
|
|
|
|
|
|
at.mkdir_all("a/b/");
|
|
|
|
at.touch(file_1);
|
|
|
|
at.touch(file_2);
|
|
|
|
|
|
|
|
let mut child: Child = scene.ucmd().arg("-ri").arg("a").run_no_wait();
|
|
|
|
|
|
|
|
// Needed so that we can talk to the rm program
|
|
|
|
let mut child_stdin = child.stdin.take().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
|
|
|
|
child.wait_with_output().unwrap();
|
|
|
|
|
|
|
|
assert!(!at.dir_exists("a/b"));
|
|
|
|
assert!(!at.dir_exists("a"));
|
|
|
|
assert!(!at.file_exists(file_1));
|
|
|
|
assert!(!at.file_exists(file_2));
|
|
|
|
}
|
|
|
|
|
2022-10-08 20:02:56 +00:00
|
|
|
#[cfg(feature = "chmod")]
|
|
|
|
#[test]
|
|
|
|
fn test_rm_prompts() {
|
|
|
|
use std::io::Write;
|
|
|
|
use std::process::Child;
|
|
|
|
|
|
|
|
// Needed for talking with stdin on platforms where CRLF or LF matters
|
|
|
|
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };
|
|
|
|
|
|
|
|
let mut answers = vec![
|
|
|
|
"rm: descend into directory 'a'?",
|
|
|
|
"rm: remove write-protected regular empty file 'a/empty-no-write'?",
|
|
|
|
"rm: remove symbolic link 'a/slink'?",
|
|
|
|
"rm: remove symbolic link 'a/slink-dot'?",
|
|
|
|
"rm: remove write-protected regular file 'a/f-no-write'?",
|
|
|
|
"rm: remove regular empty file 'a/empty'?",
|
|
|
|
"rm: remove directory 'a/b'?",
|
|
|
|
"rm: remove write-protected directory 'a/b-no-write'?",
|
|
|
|
"rm: remove directory 'a'?",
|
|
|
|
];
|
|
|
|
|
|
|
|
answers.sort();
|
|
|
|
|
|
|
|
let yes = format!("y{}", END_OF_LINE);
|
|
|
|
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
at.mkdir("a/");
|
|
|
|
|
|
|
|
let file_1 = "a/empty";
|
|
|
|
let file_2 = "a/empty-no-write";
|
|
|
|
let file_3 = "a/f-no-write";
|
|
|
|
|
|
|
|
at.touch(file_1);
|
|
|
|
at.touch(file_2);
|
|
|
|
at.make_file(file_3)
|
|
|
|
.write_all(b"not-empty")
|
|
|
|
.expect("Couldn't write to a/f-no-write");
|
|
|
|
|
|
|
|
at.symlink_dir("a/empty-f", "a/slink");
|
|
|
|
at.symlink_dir(".", "a/slink-dot");
|
|
|
|
|
|
|
|
let dir_1 = "a/b/";
|
|
|
|
let dir_2 = "a/b-no-write/";
|
|
|
|
|
|
|
|
at.mkdir(dir_1);
|
|
|
|
at.mkdir(dir_2);
|
|
|
|
|
|
|
|
scene
|
|
|
|
.ccmd("chmod")
|
|
|
|
.arg("u-w")
|
|
|
|
.arg(file_3)
|
|
|
|
.arg(dir_2)
|
|
|
|
.arg(file_2)
|
|
|
|
.succeeds();
|
|
|
|
|
|
|
|
let mut child: Child = scene.ucmd().arg("-ri").arg("a").run_no_wait();
|
|
|
|
|
|
|
|
let mut child_stdin = child.stdin.take().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
|
|
|
|
let output = child.wait_with_output().unwrap();
|
|
|
|
|
|
|
|
let mut trimmed_output = Vec::new();
|
|
|
|
for string in String::from_utf8(output.stderr)
|
|
|
|
.expect("Couldn't convert output.stderr to string")
|
|
|
|
.split("rm: ")
|
|
|
|
{
|
|
|
|
if !string.is_empty() {
|
|
|
|
let trimmed_string = format!("rm: {}", string).trim().to_string();
|
|
|
|
trimmed_output.push(trimmed_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trimmed_output.sort();
|
|
|
|
|
|
|
|
assert!(trimmed_output.len() == answers.len());
|
|
|
|
|
|
|
|
for (i, checking_string) in trimmed_output.iter().enumerate() {
|
|
|
|
assert!(checking_string == answers[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(!at.dir_exists("a"));
|
|
|
|
}
|
|
|
|
|
2022-10-10 18:48:34 +00:00
|
|
|
#[test]
|
|
|
|
fn test_rm_force_prompts_order() {
|
|
|
|
use std::io::Write;
|
|
|
|
use std::process::Child;
|
|
|
|
|
|
|
|
// Needed for talking with stdin on platforms where CRLF or LF matters
|
|
|
|
const END_OF_LINE: &str = if cfg!(windows) { "\r\n" } else { "\n" };
|
|
|
|
|
|
|
|
let yes = format!("y{}", END_OF_LINE);
|
|
|
|
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
let empty_file = "empty";
|
|
|
|
|
|
|
|
at.touch(empty_file);
|
|
|
|
|
|
|
|
// This should cause rm to prompt to remove regular empty file
|
|
|
|
let mut child: Child = scene.ucmd().arg("-fi").arg(empty_file).run_no_wait();
|
|
|
|
|
|
|
|
let mut child_stdin = child.stdin.take().unwrap();
|
|
|
|
child_stdin.write_all(yes.as_bytes()).unwrap();
|
|
|
|
child_stdin.flush().unwrap();
|
|
|
|
|
|
|
|
let output = child.wait_with_output().unwrap();
|
|
|
|
let string_output =
|
|
|
|
String::from_utf8(output.stderr).expect("Couldn't convert output.stderr to string");
|
2022-10-10 18:52:05 +00:00
|
|
|
assert!(string_output.trim() == "rm: remove regular empty file 'empty'?");
|
2022-10-10 18:48:34 +00:00
|
|
|
assert!(!at.file_exists(empty_file));
|
|
|
|
|
|
|
|
at.touch(empty_file);
|
|
|
|
|
|
|
|
// This should not cause rm to prompt to remove regular empty file
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("-if")
|
|
|
|
.arg(empty_file)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
assert!(!at.file_exists(empty_file));
|
|
|
|
}
|
|
|
|
|
2022-07-17 20:34:04 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore = "issue #3722"]
|
|
|
|
fn test_rm_directory_rights_rm1() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
at.mkdir_all("b/a/p");
|
|
|
|
at.mkdir_all("b/c");
|
|
|
|
at.mkdir_all("b/d");
|
|
|
|
at.set_readonly("b/a");
|
|
|
|
ucmd.args(&["-rf", "b"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("Permission denied");
|
|
|
|
assert!(at.dir_exists("b/a/p"));
|
|
|
|
assert!(!at.dir_exists("b/c"));
|
|
|
|
assert!(!at.dir_exists("b/d"));
|
|
|
|
}
|
2022-08-23 15:47:48 +00:00
|
|
|
|
2022-08-27 14:08:10 +00:00
|
|
|
#[cfg(feature = "chmod")]
|
2022-08-23 15:47:48 +00:00
|
|
|
#[test]
|
|
|
|
fn test_prompt_write_protected_yes() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
let file_1 = "test_rm_prompt_write_protected_1";
|
|
|
|
|
|
|
|
at.touch(file_1);
|
|
|
|
|
|
|
|
scene.ccmd("chmod").arg("0").arg(file_1).succeeds();
|
|
|
|
|
|
|
|
scene.ucmd().arg(file_1).pipe_in("y").succeeds();
|
|
|
|
assert!(!at.file_exists(file_1));
|
|
|
|
}
|
|
|
|
|
2022-08-27 14:08:10 +00:00
|
|
|
#[cfg(feature = "chmod")]
|
2022-08-23 15:47:48 +00:00
|
|
|
#[test]
|
|
|
|
fn test_prompt_write_protected_no() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
let file_2 = "test_rm_prompt_write_protected_2";
|
|
|
|
|
|
|
|
at.touch(file_2);
|
|
|
|
|
|
|
|
scene.ccmd("chmod").arg("0").arg(file_2).succeeds();
|
|
|
|
|
|
|
|
scene.ucmd().arg(file_2).pipe_in("n").succeeds();
|
|
|
|
assert!(at.file_exists(file_2));
|
|
|
|
}
|