2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
|
|
|
|
|
|
|
static UTIL_NAME: &'static str = "link";
|
2016-07-29 21:26:32 +00:00
|
|
|
fn at_and_ucmd() -> (AtPath, UCommand) {
|
|
|
|
let ts = TestScenario::new(UTIL_NAME);
|
|
|
|
let ucmd = ts.ucmd();
|
|
|
|
(ts.fixtures, ucmd)
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_link_existing_file() {
|
2016-07-29 21:26:32 +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-07-29 21:26:32 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd();
|
2015-11-16 05:25:01 +00:00
|
|
|
let link = "test_link_no_circular";
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.args(&[link, link]).fails()
|
|
|
|
.stderr_is("link: error: 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-07-29 21:26:32 +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";
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.args(&[file, link]).fails()
|
|
|
|
.stderr_is("link: error: 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));
|
|
|
|
}
|