| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
use uutests::at_and_ucmd; |
| 7 |
use uutests::new_ucmd; |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn test_invalid_arg() { |
| 11 |
new_ucmd!().arg("--definitely-invalid").fails_with_code(1); |
| 12 |
} |
| 13 |
|
| 14 |
#[cfg(not(target_os = "android"))] |
| 15 |
#[test] |
| 16 |
fn test_link_existing_file() { |
| 17 |
let (at, mut ucmd) = at_and_ucmd!(); |
| 18 |
let file = "test_link_existing_file"; |
| 19 |
let link = "test_link_existing_file_link"; |
| 20 |
|
| 21 |
at.touch(file); |
| 22 |
at.write(file, "foobar"); |
| 23 |
assert!(at.file_exists(file)); |
| 24 |
|
| 25 |
ucmd.args(&[file, link]).succeeds().no_stderr(); |
| 26 |
assert!(at.file_exists(file)); |
| 27 |
assert!(at.file_exists(link)); |
| 28 |
assert_eq!(at.read(file), at.read(link)); |
| 29 |
} |
| 30 |
|
| 31 |
#[test] |
| 32 |
fn test_link_no_circular() { |
| 33 |
let (at, mut ucmd) = at_and_ucmd!(); |
| 34 |
let link = "test_link_no_circular"; |
| 35 |
|
| 36 |
ucmd.args(&[link, link]) |
| 37 |
.fails() |
| 38 |
.stderr_is("link: cannot create link 'test_link_no_circular' to 'test_link_no_circular': No such file or directory\n"); |
| 39 |
assert!(!at.file_exists(link)); |
| 40 |
} |
| 41 |
|
| 42 |
#[test] |
| 43 |
fn test_link_nonexistent_file() { |
| 44 |
let (at, mut ucmd) = at_and_ucmd!(); |
| 45 |
let file = "test_link_nonexistent_file"; |
| 46 |
let link = "test_link_nonexistent_file_link"; |
| 47 |
|
| 48 |
ucmd.args(&[file, link]) |
| 49 |
.fails() |
| 50 |
.stderr_only("link: cannot create link 'test_link_nonexistent_file_link' to 'test_link_nonexistent_file': No such file or directory\n"); |
| 51 |
assert!(!at.file_exists(file)); |
| 52 |
assert!(!at.file_exists(link)); |
| 53 |
} |
| 54 |
|
| 55 |
#[test] |
| 56 |
fn test_link_one_argument() { |
| 57 |
let (_, mut ucmd) = at_and_ucmd!(); |
| 58 |
let file = "test_link_argument"; |
| 59 |
ucmd.args(&[file]) |
| 60 |
.fails() |
| 61 |
.stderr_contains("2 values required"); |
| 62 |
} |
| 63 |
|
| 64 |
#[test] |
| 65 |
fn test_link_three_arguments() { |
| 66 |
let (_, mut ucmd) = at_and_ucmd!(); |
| 67 |
let arguments = [ |
| 68 |
"test_link_argument1", |
| 69 |
"test_link_argument2", |
| 70 |
"test_link_argument3", |
| 71 |
]; |
| 72 |
ucmd.args(&arguments[..]) |
| 73 |
.fails() |
| 74 |
.stderr_contains("2 values required"); |
| 75 |
} |
| 76 |
|
| 77 |
#[test] |
| 78 |
fn test_link_no_arguments() { |
| 79 |
new_ucmd!().fails(); |
| 80 |
} |
| 81 |
|
| 82 |
#[cfg(not(target_os = "android"))] |
| 83 |
#[test] |
| 84 |
fn test_link_dest_exists() { |
| 85 |
let (at, mut ucmd) = at_and_ucmd!(); |
| 86 |
let file = "test_link_dest_exists_src"; |
| 87 |
let dest = "test_link_dest_exists_dst"; |
| 88 |
|
| 89 |
at.touch(file); |
| 90 |
at.touch(dest); |
| 91 |
|
| 92 |
ucmd.args(&[file, dest]).fails().stderr_contains("exists"); |
| 93 |
} |