coreutils/tests/test_unlink.rs
Joseph Crail 7ef4bb37a8 tests: consolidate into one crate
The main motivation is to move toward running those tests for a specific
target, that is, if a test won't run on Windows, then we shouldn't build
it. This was previously the default behavior and prevented a successful
run on AppVeyor.

I borrowed this pattern from the tests in the Cargo project.
2016-05-22 03:46:54 -04:00

59 lines
1.5 KiB
Rust

use common::util::*;
static UTIL_NAME: &'static str = "unlink";
#[test]
fn test_unlink_file() {
let (at, mut ucmd) = testing(UTIL_NAME);
let file = "test_unlink_file";
at.touch(file);
let result = ucmd.arg(file).run();
assert_empty_stderr!(result);
assert!(result.success);
assert!(!at.file_exists(file));
}
#[test]
fn test_unlink_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME);
let file_a = "test_unlink_multiple_file_a";
let file_b = "test_unlink_multiple_file_b";
at.touch(file_a);
at.touch(file_b);
let result = ucmd.arg(file_a).arg(file_b).run();
assert_eq!(result.stderr,
"unlink: error: extra operand: 'test_unlink_multiple_file_b'\nTry 'unlink --help' \
for more information.\n");
assert!(!result.success);
}
#[test]
fn test_unlink_directory() {
let (at, mut ucmd) = testing(UTIL_NAME);
let dir = "test_unlink_empty_directory";
at.mkdir(dir);
let result = ucmd.arg(dir).run();
assert_eq!(result.stderr,
"unlink: error: cannot unlink 'test_unlink_empty_directory': Not a regular file \
or symlink\n");
assert!(!result.success);
}
#[test]
fn test_unlink_nonexistent() {
let (_, mut ucmd) = testing(UTIL_NAME);
let file = "test_unlink_nonexistent";
let result = ucmd.arg(file).run();
assert_eq!(result.stderr,
"unlink: error: Cannot stat 'test_unlink_nonexistent': No such file or directory \
(os error 2)\n");
assert!(!result.success);
}