mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
b7d697753c
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.
68 lines
1.4 KiB
Rust
68 lines
1.4 KiB
Rust
use crate::common::util::*;
|
|
|
|
#[test]
|
|
fn test_unlink_file() {
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
let file = "test_unlink_file";
|
|
|
|
at.touch(file);
|
|
|
|
ucmd.arg(file).succeeds().no_stderr();
|
|
|
|
assert!(!at.file_exists(file));
|
|
}
|
|
|
|
#[test]
|
|
fn test_unlink_multiple_files() {
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let (at, mut ucmd) = (ts.fixtures.clone(), ts.ucmd());
|
|
let file_a = "test_unlink_multiple_file_a";
|
|
let file_b = "test_unlink_multiple_file_b";
|
|
|
|
at.touch(file_a);
|
|
at.touch(file_b);
|
|
|
|
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 = "dir";
|
|
|
|
at.mkdir(dir);
|
|
|
|
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"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_unlink_nonexistent() {
|
|
let file = "test_unlink_nonexistent";
|
|
|
|
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"));
|
|
}
|