Files

75 lines
2.0 KiB
Rust
Raw Permalink Normal View History

2023-08-21 10:49:27 +02:00
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
2025-03-28 09:51:51 +01:00
use uutests::at_and_ucmd;
use uutests::new_ucmd;
2022-09-10 18:38:14 +02:00
#[test]
fn test_invalid_arg() {
2025-03-01 15:29:11 +01:00
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
2022-09-10 18:38:14 +02:00
}
#[cfg(not(target_os = "android"))]
#[test]
fn test_link_existing_file() {
let (at, mut ucmd) = at_and_ucmd!();
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 17:59:21 -04:00
ucmd.args(&[file, link]).succeeds().no_stderr();
assert!(at.file_exists(file));
assert!(at.file_exists(link));
assert_eq!(at.read(file), at.read(link));
}
#[test]
fn test_link_no_circular() {
let (at, mut ucmd) = at_and_ucmd!();
let link = "test_link_no_circular";
2020-04-13 20:36:03 +02:00
ucmd.args(&[link, link])
.fails()
.stderr_is("link: cannot create link 'test_link_no_circular' to 'test_link_no_circular': No such file or directory\n");
assert!(!at.file_exists(link));
}
#[test]
fn test_link_nonexistent_file() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_link_nonexistent_file";
let link = "test_link_nonexistent_file_link";
2020-04-13 20:36:03 +02:00
ucmd.args(&[file, link])
.fails()
.stderr_only("link: cannot create link 'test_link_nonexistent_file_link' to 'test_link_nonexistent_file': No such file or directory\n");
assert!(!at.file_exists(file));
assert!(!at.file_exists(link));
}
#[test]
fn test_link_one_argument() {
let (_, mut ucmd) = at_and_ucmd!();
let file = "test_link_argument";
2022-09-29 19:03:03 +02:00
ucmd.args(&[file])
.fails()
.stderr_contains("2 values required");
}
#[test]
fn test_link_three_arguments() {
let (_, mut ucmd) = at_and_ucmd!();
2023-08-21 08:11:38 +02:00
let arguments = [
"test_link_argument1",
"test_link_argument2",
"test_link_argument3",
];
2022-09-29 19:03:03 +02:00
ucmd.args(&arguments[..])
.fails()
.stderr_contains("2 values required");
}