2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
|
|
|
|
|
|
|
static UTIL_NAME: &'static str = "basename";
|
2016-07-29 21:26:32 +00:00
|
|
|
fn new_ucmd() -> UCommand {
|
|
|
|
TestScenario::new(UTIL_NAME).ucmd()
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2016-02-16 07:15:13 +00:00
|
|
|
fn expect_successful_stdout(input: Vec<&str>, expected: &str) {
|
2016-07-29 21:26:32 +00:00
|
|
|
let results = new_ucmd()
|
|
|
|
.args(&input).run();
|
2016-02-16 07:15:13 +00:00
|
|
|
assert_empty_stderr!(results);
|
|
|
|
assert!(results.success);
|
|
|
|
assert_eq!(expected, results.stdout.trim_right());
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_directory() {
|
|
|
|
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega/";
|
2016-02-16 07:15:13 +00:00
|
|
|
expect_successful_stdout(vec![dir], "omega");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_file() {
|
|
|
|
let file = "/etc/passwd";
|
2016-02-16 07:15:13 +00:00
|
|
|
expect_successful_stdout(vec![file], "passwd");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_suffix() {
|
|
|
|
let path = "/usr/local/bin/reallylongexecutable.exe";
|
2016-02-16 07:15:13 +00:00
|
|
|
expect_successful_stdout(vec![path, ".exe"], "reallylongexecutable");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_dont_remove_suffix() {
|
|
|
|
let path = "/foo/bar/baz";
|
2016-02-16 07:15:13 +00:00
|
|
|
expect_successful_stdout(vec![path, "baz"], "baz");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2016-02-16 07:16:19 +00:00
|
|
|
|
|
|
|
fn expect_error(input: Vec<&str>, expected_stdout: &str) {
|
2016-07-29 21:26:32 +00:00
|
|
|
let results = new_ucmd()
|
|
|
|
.args(&input).run();
|
2016-02-16 07:16:19 +00:00
|
|
|
assert!(!results.success);
|
|
|
|
assert!(results.stderr.len() > 0);
|
|
|
|
assert_eq!(expected_stdout, results.stdout.trim_right());
|
|
|
|
}
|
2016-05-22 07:46:54 +00:00
|
|
|
|
2016-02-16 07:16:19 +00:00
|
|
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_param() {
|
|
|
|
for multiple_param in vec!["-a", "--multiple"] {
|
|
|
|
let path = "/foo/bar/baz";
|
|
|
|
expect_successful_stdout(vec![multiple_param, path, path], "baz\nbaz");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
|
|
|
#[test]
|
|
|
|
fn test_suffix_param() {
|
|
|
|
for suffix_param in vec!["-s", "--suffix"] {
|
|
|
|
let path = "/foo/bar/baz.exe";
|
|
|
|
let suffix = ".exe";
|
|
|
|
expect_successful_stdout(
|
|
|
|
vec![suffix_param, suffix, path, path],
|
|
|
|
"baz\nbaz"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
|
|
|
#[test]
|
|
|
|
fn test_zero_param() {
|
|
|
|
for zero_param in vec!["-z", "--zero"] {
|
|
|
|
let path = "/foo/bar/baz";
|
|
|
|
expect_successful_stdout(vec![zero_param, "-a", path, path], "baz\0baz\0");
|
|
|
|
}
|
|
|
|
}
|
2016-02-16 07:17:04 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_option() {
|
|
|
|
let path = "/foo/bar/baz";
|
|
|
|
expect_error(vec!["-q", path], "");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_no_args() {
|
|
|
|
expect_error(vec![], "");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_too_many_args() {
|
|
|
|
expect_error(vec!["a", "b", "c"], "");
|
|
|
|
}
|