mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
99b39e4237
Although for some tests this adds characters we still use them there because the brevity cost is now worth the benefit in terms of instant, natural-language readability and recognizability for people not familiar with this tests of this module or even the project
144 lines
3.3 KiB
Rust
144 lines
3.3 KiB
Rust
use common::util::*;
|
|
|
|
static UTIL_NAME: &'static str = "rm";
|
|
fn at_and_ucmd() -> (AtPath, UCommand) {
|
|
let ts = TestScenario::new(UTIL_NAME);
|
|
let ucmd = ts.ucmd();
|
|
(ts.fixtures, ucmd)
|
|
}
|
|
|
|
#[test]
|
|
fn test_rm_one_file() {
|
|
let (at, mut ucmd) = at_and_ucmd();
|
|
let file = "test_rm_one_file";
|
|
|
|
at.touch(file);
|
|
|
|
ucmd.arg(file).succeeds().no_stderr();
|
|
|
|
assert!(!at.file_exists(file));
|
|
}
|
|
|
|
#[test]
|
|
fn test_rm_multiple_files() {
|
|
let (at, mut ucmd) = at_and_ucmd();
|
|
let file_a = "test_rm_multiple_file_a";
|
|
let file_b = "test_rm_multiple_file_b";
|
|
|
|
at.touch(file_a);
|
|
at.touch(file_b);
|
|
|
|
ucmd.arg(file_a).arg(file_b).succeeds().no_stderr();
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
assert!(!at.file_exists(file_b));
|
|
}
|
|
|
|
#[test]
|
|
fn test_rm_interactive() {
|
|
let scene = TestScenario::new(UTIL_NAME);
|
|
let at = &scene.fixtures;
|
|
|
|
let file_a = "test_rm_interactive_file_a";
|
|
let file_b = "test_rm_interactive_file_b";
|
|
|
|
at.touch(file_a);
|
|
at.touch(file_b);
|
|
|
|
scene.ucmd()
|
|
.arg("-i")
|
|
.arg(file_a)
|
|
.arg(file_b)
|
|
.pipe_in("n")
|
|
.succeeds();
|
|
|
|
assert!(at.file_exists(file_a));
|
|
assert!(at.file_exists(file_b));
|
|
|
|
scene.ucmd()
|
|
.arg("-i")
|
|
.arg(file_a)
|
|
.arg(file_b)
|
|
.pipe_in("Yesh")
|
|
.succeeds();
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
assert!(at.file_exists(file_b));
|
|
}
|
|
|
|
#[test]
|
|
fn test_rm_force() {
|
|
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(file_a)
|
|
.arg(file_b)
|
|
.succeeds()
|
|
.no_stderr();
|
|
|
|
assert!(!at.file_exists(file_a));
|
|
assert!(!at.file_exists(file_b));
|
|
}
|
|
|
|
#[test]
|
|
fn test_rm_empty_directory() {
|
|
let (at, mut ucmd) = at_and_ucmd();
|
|
let dir = "test_rm_empty_directory";
|
|
|
|
at.mkdir(dir);
|
|
|
|
ucmd.arg("-d").arg(dir).succeeds().no_stderr();
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
}
|
|
|
|
#[test]
|
|
fn test_rm_recursive() {
|
|
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(dir).succeeds().no_stderr();
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
assert!(!at.file_exists(file_a));
|
|
assert!(!at.file_exists(file_b));
|
|
}
|
|
|
|
#[test]
|
|
fn test_rm_errors() {
|
|
let (at, mut ucmd) = at_and_ucmd();
|
|
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'?)
|
|
ucmd.arg(dir).fails()
|
|
.stderr_is("rm: error: could not remove directory 'test_rm_errors_directory' (did you mean \
|
|
to pass '-r'?)\n");
|
|
}
|
|
|
|
#[test]
|
|
fn test_rm_verbose() {
|
|
let (at, mut ucmd) = at_and_ucmd();
|
|
let file_a = "test_rm_verbose_file_a";
|
|
let file_b = "test_rm_verbose_file_b";
|
|
|
|
at.touch(file_a);
|
|
at.touch(file_b);
|
|
|
|
ucmd.arg("-v").arg(file_a).arg(file_b).succeeds()
|
|
.stdout_only(format!("removed '{}'\nremoved '{}'\n", file_a, file_b));
|
|
}
|