mirror of
https://github.com/uutils/coreutils
synced 2024-11-15 09:27:21 +00:00
Add tests for link.
This commit is contained in:
parent
1f7f3ad535
commit
10a2c5c224
3 changed files with 55 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -177,6 +177,7 @@ TEST_PROGS := \
|
|||
fold \
|
||||
hashsum \
|
||||
head \
|
||||
link \
|
||||
ln \
|
||||
mkdir \
|
||||
mv \
|
||||
|
|
|
@ -64,6 +64,11 @@ pub fn get_file_contents(name: &str) -> String {
|
|||
contents
|
||||
}
|
||||
|
||||
pub fn set_file_contents(name: &str, contents: &str) {
|
||||
let mut f = File::open(Path::new(name)).unwrap();
|
||||
let _ = f.write(contents.as_bytes());
|
||||
}
|
||||
|
||||
pub fn mkdir(dir: &str) {
|
||||
fs::create_dir(Path::new(dir)).unwrap();
|
||||
}
|
||||
|
|
49
test/link.rs
Normal file
49
test/link.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
extern crate libc;
|
||||
|
||||
use std::process::Command;
|
||||
use util::*;
|
||||
|
||||
static PROGNAME: &'static str = "./link";
|
||||
|
||||
#[path = "common/util.rs"]
|
||||
#[macro_use]
|
||||
mod util;
|
||||
|
||||
#[test]
|
||||
fn test_link_existing_file() {
|
||||
let file = "test_link_existing_file";
|
||||
let link = "test_link_existing_file_link";
|
||||
|
||||
touch(file);
|
||||
set_file_contents(file, "foobar");
|
||||
assert!(file_exists(file));
|
||||
|
||||
let result = run(Command::new(PROGNAME).args(&[file, link]));
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(file_exists(file));
|
||||
assert!(file_exists(link));
|
||||
assert_eq!(get_file_contents(file), get_file_contents(link));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_link_no_circular() {
|
||||
let link = "test_link_no_circular";
|
||||
|
||||
let result = run(Command::new(PROGNAME).args(&[link, link]));
|
||||
assert_eq!(result.stderr, "link: error: No such file or directory (os error 2)\n");
|
||||
assert!(!result.success);
|
||||
assert!(!file_exists(link));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_link_nonexistent_file() {
|
||||
let file = "test_link_nonexistent_file";
|
||||
let link = "test_link_nonexistent_file_link";
|
||||
|
||||
let result = run(Command::new(PROGNAME).args(&[file, link]));
|
||||
assert_eq!(result.stderr, "link: error: No such file or directory (os error 2)\n");
|
||||
assert!(!result.success);
|
||||
assert!(!file_exists(file));
|
||||
assert!(!file_exists(link));
|
||||
}
|
Loading…
Reference in a new issue