mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Add tests for rmdir.
I also adjusted error message to conform to GNU implementation.
This commit is contained in:
parent
510b024d0f
commit
3b5c776675
4 changed files with 120 additions and 1 deletions
1
Makefile
1
Makefile
|
@ -187,6 +187,7 @@ TEST_PROGS := \
|
||||||
readlink \
|
readlink \
|
||||||
realpath \
|
realpath \
|
||||||
rm \
|
rm \
|
||||||
|
rmdir \
|
||||||
seq \
|
seq \
|
||||||
sort \
|
sort \
|
||||||
split \
|
split \
|
||||||
|
|
|
@ -118,7 +118,7 @@ fn remove_dir(path: &Path, ignore: bool, verbose: bool) -> Result<(), i32> {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else if !ignore {
|
} 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);
|
r = Err(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,10 @@ pub fn mkdir(dir: &str) {
|
||||||
fs::create_dir(Path::new(dir)).unwrap();
|
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 {
|
pub fn make_file(name: &str) -> File {
|
||||||
match File::create(Path::new(name)) {
|
match File::create(Path::new(name)) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
|
|
114
test/rmdir.rs
Normal file
114
test/rmdir.rs
Normal file
|
@ -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));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue