2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_directory() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"])
|
2016-08-09 01:12:58 +00:00
|
|
|
.succeeds().stdout_only("omega");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_file() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["/etc/passwd"]).succeeds().stdout_only("passwd");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_remove_suffix() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"])
|
2016-08-09 01:12:58 +00:00
|
|
|
.succeeds().stdout_only("reallylongexecutable");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_dont_remove_suffix() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["/foo/bar/baz", "baz"]).succeeds().stdout_only( "baz");
|
2016-02-16 07:16:19 +00:00
|
|
|
}
|
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";
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&[multiple_param, path, path])
|
2016-08-09 01:12:58 +00:00
|
|
|
.succeeds().stdout_only("baz\nbaz");
|
2016-02-16 07:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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";
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-08-09 01:12:58 +00:00
|
|
|
.args(&[suffix_param, ".exe", path, path])
|
|
|
|
.succeeds().stdout_only("baz\nbaz");
|
2016-02-16 07:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
|
|
|
#[test]
|
|
|
|
fn test_zero_param() {
|
|
|
|
for zero_param in vec!["-z", "--zero"] {
|
|
|
|
let path = "/foo/bar/baz";
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&[zero_param, "-a", path, path])
|
2016-08-09 01:12:58 +00:00
|
|
|
.succeeds().stdout_only("baz\0baz\0");
|
2016-02-16 07:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-16 07:17:04 +00:00
|
|
|
|
2016-08-09 01:12:58 +00:00
|
|
|
|
|
|
|
fn expect_error(input: Vec<&str>) {
|
2016-08-23 11:52:43 +00:00
|
|
|
assert!(new_ucmd!().args(&input)
|
2016-08-09 01:12:58 +00:00
|
|
|
.fails().no_stdout().stderr.len() > 0);
|
|
|
|
}
|
|
|
|
|
2016-02-16 07:17:04 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_option() {
|
|
|
|
let path = "/foo/bar/baz";
|
2016-08-09 01:12:58 +00:00
|
|
|
expect_error(vec!["-q", path]);
|
2016-02-16 07:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_no_args() {
|
2016-08-09 01:12:58 +00:00
|
|
|
expect_error(vec![]);
|
2016-02-16 07:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_too_many_args() {
|
2016-08-09 01:12:58 +00:00
|
|
|
expect_error(vec!["a", "b", "c"]);
|
2016-02-16 07:17:04 +00:00
|
|
|
}
|