2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(not(target_os = "android"))]
|
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()
|
2023-01-05 20:09:15 +00:00
|
|
|
.stderr_is("link: cannot create link 'test_link_no_circular' to 'test_link_no_circular': No such file or directory\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()
|
2023-01-05 20:09:15 +00:00
|
|
|
.stderr_only("link: cannot create link 'test_link_nonexistent_file_link' to 'test_link_nonexistent_file': No such file or directory\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";
|
2022-09-29 17:03:03 +00:00
|
|
|
ucmd.args(&[file])
|
|
|
|
.fails()
|
2023-03-08 14:06:07 +00:00
|
|
|
.stderr_contains("2 values required");
|
2021-05-02 10:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_link_three_arguments() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
|
|
|
let arguments = vec![
|
|
|
|
"test_link_argument1",
|
|
|
|
"test_link_argument2",
|
|
|
|
"test_link_argument3",
|
|
|
|
];
|
2022-09-29 17:03:03 +00:00
|
|
|
ucmd.args(&arguments[..])
|
|
|
|
.fails()
|
2023-03-08 14:06:07 +00:00
|
|
|
.stderr_contains("2 values required");
|
2021-05-02 10:32:34 +00:00
|
|
|
}
|