2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rmdir_empty_directory_no_parents() {
|
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_rmdir_empty_no_parents";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(dir).succeeds().no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rmdir_empty_directory_with_parents() {
|
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_rmdir_empty/with/parents";
|
|
|
|
|
|
|
|
at.mkdir_all(dir);
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg("-p").arg(dir).succeeds().no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rmdir_nonempty_directory_no_parents() {
|
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_rmdir_nonempty_no_parents";
|
|
|
|
let file = "test_rmdir_nonempty_no_parents/foo";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.arg(dir).fails().stderr_is(
|
2021-05-25 23:45:53 +00:00
|
|
|
"rmdir: failed to remove 'test_rmdir_nonempty_no_parents': Directory not \
|
2021-03-18 09:24:30 +00:00
|
|
|
empty\n",
|
2020-04-13 18:36:03 +00:00
|
|
|
);
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rmdir_nonempty_directory_with_parents() {
|
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_rmdir_nonempty/with/parents";
|
|
|
|
let file = "test_rmdir_nonempty/with/parents/foo";
|
|
|
|
|
|
|
|
at.mkdir_all(dir);
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.arg("-p").arg(dir).fails().stderr_is(
|
2021-05-25 23:45:53 +00:00
|
|
|
"rmdir: failed to remove 'test_rmdir_nonempty/with/parents': Directory not \
|
|
|
|
empty\nrmdir: failed to remove 'test_rmdir_nonempty/with': Directory not \
|
|
|
|
empty\nrmdir: failed to remove 'test_rmdir_nonempty': Directory not \
|
2021-03-18 09:24:30 +00:00
|
|
|
empty\n",
|
2020-04-13 18:36:03 +00:00
|
|
|
);
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rmdir_ignore_nonempty_directory_no_parents() {
|
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_rmdir_ignore_nonempty_no_parents";
|
|
|
|
let file = "test_rmdir_ignore_nonempty_no_parents/foo";
|
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.arg("--ignore-fail-on-non-empty")
|
|
|
|
.arg(dir)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rmdir_ignore_nonempty_directory_with_parents() {
|
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_rmdir_ignore_nonempty/with/parents";
|
|
|
|
let file = "test_rmdir_ignore_nonempty/with/parents/foo";
|
|
|
|
|
|
|
|
at.mkdir_all(dir);
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.arg("--ignore-fail-on-non-empty")
|
|
|
|
.arg("-p")
|
|
|
|
.arg(dir)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
}
|
2021-05-30 02:45:54 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rmdir_remove_symlink_match_gnu_error() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
let file = "file";
|
|
|
|
let fl = "fl";
|
|
|
|
at.touch(file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
at.symlink_file(file, fl);
|
|
|
|
assert!(at.file_exists(fl));
|
|
|
|
|
|
|
|
ucmd.arg("fl/")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("rmdir: failed to remove 'fl/': Not a directory");
|
|
|
|
}
|