2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_link_existing_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_link_existing_file";
|
|
|
|
let link = "test_link_existing_file_link";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.write(file, "foobar");
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.args(&[file, link]).succeeds().no_stderr();
|
2015-11-16 05:25:01 +00:00
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(link));
|
|
|
|
assert_eq!(at.read(file), at.read(link));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_link_no_circular() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
let link = "test_link_no_circular";
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.args(&[link, link])
|
|
|
|
.fails()
|
2021-05-25 23:45:53 +00:00
|
|
|
.stderr_is("link: No such file or directory (os error 2)\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
assert!(!at.file_exists(link));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_link_nonexistent_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_link_nonexistent_file";
|
|
|
|
let link = "test_link_nonexistent_file_link";
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.args(&[file, link])
|
|
|
|
.fails()
|
2021-05-25 23:45:53 +00:00
|
|
|
.stderr_is("link: No such file or directory (os error 2)\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
assert!(!at.file_exists(file));
|
|
|
|
assert!(!at.file_exists(link));
|
|
|
|
}
|
2021-05-02 10:32:34 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_link_one_argument() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file = "test_link_argument";
|
|
|
|
ucmd.args(&[file]).fails().stderr_contains(
|
|
|
|
"error: The argument '<FILES>...' requires at least 2 values, but only 1 was provide",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_link_three_arguments() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
|
|
|
let arguments = vec![
|
|
|
|
"test_link_argument1",
|
|
|
|
"test_link_argument2",
|
|
|
|
"test_link_argument3",
|
|
|
|
];
|
|
|
|
ucmd.args(&arguments[..]).fails().stderr_contains(
|
|
|
|
format!("error: The value '{}' was provided to '<FILES>...', but it wasn't expecting any more values", arguments[2]),
|
|
|
|
);
|
|
|
|
}
|