mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Merge pull request #712 from jbcrail/add-link-tests
Add tests for link.
This commit is contained in:
commit
fa34096bb8
3 changed files with 55 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -177,6 +177,7 @@ TEST_PROGS := \
|
||||||
fold \
|
fold \
|
||||||
hashsum \
|
hashsum \
|
||||||
head \
|
head \
|
||||||
|
link \
|
||||||
ln \
|
ln \
|
||||||
mkdir \
|
mkdir \
|
||||||
mv \
|
mv \
|
||||||
|
|
|
@ -64,6 +64,11 @@ pub fn get_file_contents(name: &str) -> String {
|
||||||
contents
|
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) {
|
pub fn mkdir(dir: &str) {
|
||||||
fs::create_dir(Path::new(dir)).unwrap();
|
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…
Add table
Add a link
Reference in a new issue