mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 01:38:04 +00:00
569cd162d3
Updates to individual integration tests - use proposed conventional approach to beginning tests - use new convenience functions for using fixtures - use new names for TestScenario Updates to integration test modules - add proposed conventional module-level functions Updates to test/common/util.rs - rename TestSet, and its methods, for semantic clarity - create convenience functions for use of fixtures - delete convenience functions obsoleted by new conventions
160 lines
4 KiB
Rust
160 lines
4 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);
|
|
|
|
let result = ucmd.arg(file).run();
|
|
assert_empty_stderr!(result);
|
|
assert!(result.success);
|
|
|
|
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);
|
|
|
|
let result = ucmd.arg(file_a).arg(file_b).run();
|
|
assert_empty_stderr!(result);
|
|
assert!(result.success);
|
|
|
|
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);
|
|
|
|
let result1 = scene.ucmd()
|
|
.arg("-i")
|
|
.arg(file_a)
|
|
.arg(file_b)
|
|
.run_piped_stdin("n");
|
|
|
|
assert!(result1.success);
|
|
|
|
assert!(at.file_exists(file_a));
|
|
assert!(at.file_exists(file_b));
|
|
|
|
let result2 = scene.ucmd()
|
|
.arg("-i")
|
|
.arg(file_a)
|
|
.arg(file_b)
|
|
.run_piped_stdin("Yesh");
|
|
|
|
assert!(result2.success);
|
|
|
|
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";
|
|
|
|
let result = ucmd.arg("-f")
|
|
.arg(file_a)
|
|
.arg(file_b)
|
|
.run();
|
|
assert_empty_stderr!(result);
|
|
assert!(result.success);
|
|
|
|
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);
|
|
|
|
let result = ucmd.arg("-d").arg(dir).run();
|
|
assert_empty_stderr!(result);
|
|
assert!(result.success);
|
|
|
|
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);
|
|
|
|
let result = ucmd.arg("-r").arg(dir).run();
|
|
assert_empty_stderr!(result);
|
|
assert!(result.success);
|
|
|
|
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'?)
|
|
let result = ucmd.arg(dir).run();
|
|
assert_eq!(result.stderr,
|
|
"rm: error: could not remove directory 'test_rm_errors_directory' (did you mean \
|
|
to pass '-r'?)\n");
|
|
assert!(!result.success);
|
|
}
|
|
|
|
#[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);
|
|
|
|
let result = ucmd.arg("-v").arg(file_a).arg(file_b).run();
|
|
assert_empty_stderr!(result);
|
|
assert_eq!(result.stdout,
|
|
format!("removed '{}'\nremoved '{}'\n", file_a, file_b));
|
|
assert!(result.success);
|
|
}
|