mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
unlink: Simplify, remove unsafe, move to core
This makes it no longer possible to pass multiple filenames, but every other implementation I tried (GNU, busybox, FreeBSD, sbase) also forbids that so I think it's for the best.
This commit is contained in:
parent
92a1f1422e
commit
b7d697753c
5 changed files with 42 additions and 100 deletions
|
@ -23,23 +23,24 @@ fn test_unlink_multiple_files() {
|
|||
at.touch(file_a);
|
||||
at.touch(file_b);
|
||||
|
||||
ucmd.arg(file_a).arg(file_b).fails().stderr_is(&format!(
|
||||
"{0}: extra operand: 'test_unlink_multiple_file_b'\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
ucmd.arg(file_a)
|
||||
.arg(file_b)
|
||||
.fails()
|
||||
.stderr_contains("USAGE");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unlink_directory() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let dir = "test_unlink_empty_directory";
|
||||
let dir = "dir";
|
||||
|
||||
at.mkdir(dir);
|
||||
|
||||
ucmd.arg(dir).fails().stderr_is(
|
||||
"unlink: cannot unlink 'test_unlink_empty_directory': Not a regular file \
|
||||
or symlink\n",
|
||||
let res = ucmd.arg(dir).fails();
|
||||
let stderr = res.stderr_str();
|
||||
assert!(
|
||||
stderr == "unlink: cannot unlink 'dir': Is a directory\n"
|
||||
|| stderr == "unlink: cannot unlink 'dir': Permission denied\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -47,8 +48,21 @@ fn test_unlink_directory() {
|
|||
fn test_unlink_nonexistent() {
|
||||
let file = "test_unlink_nonexistent";
|
||||
|
||||
new_ucmd!().arg(file).fails().stderr_is(
|
||||
"unlink: Cannot stat 'test_unlink_nonexistent': No such file or directory \
|
||||
(os error 2)\n",
|
||||
);
|
||||
new_ucmd!()
|
||||
.arg(file)
|
||||
.fails()
|
||||
.stderr_is("unlink: cannot unlink 'test_unlink_nonexistent': No such file or directory\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unlink_symlink() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
at.touch("foo");
|
||||
at.symlink_file("foo", "bar");
|
||||
|
||||
ucmd.arg("bar").succeeds().no_stderr();
|
||||
|
||||
assert!(at.file_exists("foo"));
|
||||
assert!(!at.file_exists("bar"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue