mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Add tests for rmdir.
I also adjusted error message to conform to GNU implementation.
This commit is contained in:
@@ -187,6 +187,7 @@ TEST_PROGS := \
|
||||
readlink \
|
||||
realpath \
|
||||
rm \
|
||||
rmdir \
|
||||
seq \
|
||||
sort \
|
||||
split \
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ fn remove_dir(path: &Path, ignore: bool, verbose: bool) -> Result<(), i32> {
|
||||
_ => (),
|
||||
}
|
||||
} else if !ignore {
|
||||
show_error!("failed to remove '{}' Directory not empty", path.display());
|
||||
show_error!("failed to remove '{}': Directory not empty", path.display());
|
||||
r = Err(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,10 @@ pub fn mkdir(dir: &str) {
|
||||
fs::create_dir(Path::new(dir)).unwrap();
|
||||
}
|
||||
|
||||
pub fn mkdir_all(dir: &str) {
|
||||
fs::create_dir_all(Path::new(dir)).unwrap();
|
||||
}
|
||||
|
||||
pub fn make_file(name: &str) -> File {
|
||||
match File::create(Path::new(name)) {
|
||||
Ok(f) => f,
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
extern crate libc;
|
||||
|
||||
use std::process::Command;
|
||||
use util::*;
|
||||
|
||||
static PROGNAME: &'static str = "./rmdir";
|
||||
|
||||
#[path = "common/util.rs"]
|
||||
#[macro_use]
|
||||
mod util;
|
||||
|
||||
#[test]
|
||||
fn test_rmdir_empty_directory_no_parents() {
|
||||
let dir = "test_rmdir_empty_no_parents";
|
||||
|
||||
mkdir(dir);
|
||||
assert!(dir_exists(dir));
|
||||
|
||||
let result = run(Command::new(PROGNAME).arg(dir));
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
|
||||
assert!(!dir_exists(dir));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rmdir_empty_directory_with_parents() {
|
||||
let dir = "test_rmdir_empty/with/parents";
|
||||
|
||||
mkdir_all(dir);
|
||||
assert!(dir_exists(dir));
|
||||
|
||||
let result = run(Command::new(PROGNAME).arg("-p").arg(dir));
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
|
||||
assert!(!dir_exists(dir));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rmdir_nonempty_directory_no_parents() {
|
||||
let dir = "test_rmdir_nonempty_no_parents";
|
||||
let file = "test_rmdir_nonempty_no_parents/foo";
|
||||
|
||||
mkdir(dir);
|
||||
assert!(dir_exists(dir));
|
||||
|
||||
touch(file);
|
||||
assert!(file_exists(file));
|
||||
|
||||
let result = run(Command::new(PROGNAME).arg(dir));
|
||||
assert_eq!(result.stderr,
|
||||
"rmdir: error: failed to remove 'test_rmdir_nonempty_no_parents': Directory not empty\n");
|
||||
assert!(!result.success);
|
||||
|
||||
assert!(dir_exists(dir));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rmdir_nonempty_directory_with_parents() {
|
||||
let dir = "test_rmdir_nonempty/with/parents";
|
||||
let file = "test_rmdir_nonempty/with/parents/foo";
|
||||
|
||||
mkdir_all(dir);
|
||||
assert!(dir_exists(dir));
|
||||
|
||||
touch(file);
|
||||
assert!(file_exists(file));
|
||||
|
||||
let result = run(Command::new(PROGNAME).arg("-p").arg(dir));
|
||||
assert_eq!(result.stderr,
|
||||
"rmdir: error: failed to remove 'test_rmdir_nonempty/with/parents': Directory not empty\n\
|
||||
rmdir: error: failed to remove 'test_rmdir_nonempty/with': Directory not empty\n\
|
||||
rmdir: error: failed to remove 'test_rmdir_nonempty': Directory not empty\n");
|
||||
assert!(!result.success);
|
||||
|
||||
assert!(dir_exists(dir));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rmdir_ignore_nonempty_directory_no_parents() {
|
||||
let dir = "test_rmdir_ignore_nonempty_no_parents";
|
||||
let file = "test_rmdir_ignore_nonempty_no_parents/foo";
|
||||
|
||||
mkdir(dir);
|
||||
assert!(dir_exists(dir));
|
||||
|
||||
touch(file);
|
||||
assert!(file_exists(file));
|
||||
|
||||
let result = run(Command::new(PROGNAME).arg("--ignore-fail-on-non-empty").arg(dir));
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
|
||||
assert!(dir_exists(dir));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rmdir_ignore_nonempty_directory_with_parents() {
|
||||
let dir = "test_rmdir_ignore_nonempty/with/parents";
|
||||
let file = "test_rmdir_ignore_nonempty/with/parents/foo";
|
||||
|
||||
mkdir_all(dir);
|
||||
assert!(dir_exists(dir));
|
||||
|
||||
touch(file);
|
||||
assert!(file_exists(file));
|
||||
|
||||
let result = run(Command::new(PROGNAME).arg("--ignore-fail-on-non-empty").arg("-p").arg(dir));
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
|
||||
assert!(dir_exists(dir));
|
||||
}
|
||||
Reference in New Issue
Block a user