2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unlink_file() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let file = "test_unlink_file";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(file).succeeds().no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(!at.file_exists(file));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unlink_multiple_files() {
|
2021-07-27 05:21:12 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
let (at, mut ucmd) = (ts.fixtures.clone(), ts.ucmd());
|
2015-11-16 05:25:01 +00:00
|
|
|
let file_a = "test_unlink_multiple_file_a";
|
|
|
|
let file_b = "test_unlink_multiple_file_b";
|
|
|
|
|
|
|
|
at.touch(file_a);
|
|
|
|
at.touch(file_b);
|
|
|
|
|
2021-08-27 22:38:00 +00:00
|
|
|
ucmd.arg(file_a)
|
|
|
|
.arg(file_b)
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("USAGE");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unlink_directory() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-08-27 22:38:00 +00:00
|
|
|
let dir = "dir";
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
at.mkdir(dir);
|
|
|
|
|
2021-08-27 22:38:00 +00:00
|
|
|
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"
|
2020-04-13 18:36:03 +00:00
|
|
|
);
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unlink_nonexistent() {
|
|
|
|
let file = "test_unlink_nonexistent";
|
|
|
|
|
2021-08-27 22:38:00 +00:00
|
|
|
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"));
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|