2021-05-30 05:10:54 +00:00
|
|
|
|
// spell-checker:ignore (words) reallylongexecutable
|
|
|
|
|
|
2020-05-25 17:05:26 +00:00
|
|
|
|
use crate::common::util::*;
|
2021-05-18 23:04:24 +00:00
|
|
|
|
#[cfg(any(unix, target_os = "redox"))]
|
2021-04-25 21:28:42 +00:00
|
|
|
|
use std::ffi::OsStr;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
2021-05-02 04:47:36 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_help() {
|
2021-05-29 12:32:35 +00:00
|
|
|
|
for help_flg in &["-h", "--help"] {
|
2021-05-02 04:47:36 +00:00
|
|
|
|
new_ucmd!()
|
|
|
|
|
.arg(&help_flg)
|
|
|
|
|
.succeeds()
|
|
|
|
|
.no_stderr()
|
|
|
|
|
.stdout_contains("USAGE:");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_version() {
|
2021-05-29 12:32:35 +00:00
|
|
|
|
for version_flg in &["-V", "--version"] {
|
2021-05-02 04:47:36 +00:00
|
|
|
|
assert!(new_ucmd!()
|
|
|
|
|
.arg(&version_flg)
|
|
|
|
|
.succeeds()
|
|
|
|
|
.no_stderr()
|
|
|
|
|
.stdout_str()
|
|
|
|
|
.starts_with("basename"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_directory() {
|
2020-04-13 18:36:03 +00:00
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.stdout_only("omega\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_file() {
|
2020-04-13 18:36:03 +00:00
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["/etc/passwd"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.stdout_only("passwd\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_remove_suffix() {
|
2020-04-13 18:36:03 +00:00
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.stdout_only("reallylongexecutable\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-05-30 05:10:54 +00:00
|
|
|
|
fn test_do_not_remove_suffix() {
|
2020-04-13 18:36:03 +00:00
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["/foo/bar/baz", "baz"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.stdout_only("baz\n");
|
2016-02-16 07:16:19 +00:00
|
|
|
|
}
|
2016-05-22 07:46:54 +00:00
|
|
|
|
|
2016-02-16 07:16:19 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_multiple_param() {
|
2022-01-29 00:03:28 +00:00
|
|
|
|
for &multiple_param in &["-a", "--multiple", "--mul"] {
|
2016-02-16 07:16:19 +00:00
|
|
|
|
let path = "/foo/bar/baz";
|
2020-04-13 18:36:03 +00:00
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&[multiple_param, path, path])
|
|
|
|
|
.succeeds()
|
2021-05-30 05:10:54 +00:00
|
|
|
|
.stdout_only("baz\nbaz\n"); // spell-checker:disable-line
|
2016-02-16 07:16:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_suffix_param() {
|
2022-01-29 00:03:28 +00:00
|
|
|
|
for &suffix_param in &["-s", "--suffix", "--suf"] {
|
2016-02-16 07:16:19 +00:00
|
|
|
|
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])
|
2020-04-13 18:36:03 +00:00
|
|
|
|
.succeeds()
|
2021-05-30 05:10:54 +00:00
|
|
|
|
.stdout_only("baz\nbaz\n"); // spell-checker:disable-line
|
2016-02-16 07:16:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_zero_param() {
|
2022-01-29 00:03:28 +00:00
|
|
|
|
for &zero_param in &["-z", "--zero", "--ze"] {
|
2016-02-16 07:16:19 +00:00
|
|
|
|
let path = "/foo/bar/baz";
|
2020-04-13 18:36:03 +00:00
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&[zero_param, "-a", path, path])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.stdout_only("baz\0baz\0");
|
2016-02-16 07:16:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-16 07:17:04 +00:00
|
|
|
|
|
2022-01-30 12:07:20 +00:00
|
|
|
|
fn expect_error(input: &[&str]) {
|
2021-05-29 12:32:35 +00:00
|
|
|
|
assert!(!new_ucmd!()
|
2022-01-30 12:07:20 +00:00
|
|
|
|
.args(input)
|
2021-05-29 12:32:35 +00:00
|
|
|
|
.fails()
|
|
|
|
|
.no_stdout()
|
|
|
|
|
.stderr_str()
|
|
|
|
|
.is_empty());
|
2016-08-09 01:12:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-16 07:17:04 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_invalid_option() {
|
|
|
|
|
let path = "/foo/bar/baz";
|
2022-01-30 12:07:20 +00:00
|
|
|
|
expect_error(&["-q", path]);
|
2016-02-16 07:17:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_no_args() {
|
2022-01-30 12:07:20 +00:00
|
|
|
|
expect_error(&[]);
|
2016-02-16 07:17:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-03 14:22:00 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_no_args_output() {
|
2021-11-09 20:23:41 +00:00
|
|
|
|
new_ucmd!().fails().usage_error("missing operand");
|
2021-05-03 14:22:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-16 07:17:04 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_too_many_args() {
|
2022-01-30 12:07:20 +00:00
|
|
|
|
expect_error(&["a", "b", "c"]);
|
2016-02-16 07:17:04 +00:00
|
|
|
|
}
|
2021-04-25 21:28:42 +00:00
|
|
|
|
|
2021-05-03 14:22:00 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_too_many_args_output() {
|
2021-11-09 20:23:41 +00:00
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["a", "b", "c"])
|
|
|
|
|
.fails()
|
|
|
|
|
.usage_error("extra operand 'c'");
|
2021-05-03 14:22:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-18 23:04:24 +00:00
|
|
|
|
#[cfg(any(unix, target_os = "redox"))]
|
2021-04-25 21:28:42 +00:00
|
|
|
|
fn test_invalid_utf8_args(os_str: &OsStr) {
|
|
|
|
|
let test_vec = vec![os_str.to_os_string()];
|
|
|
|
|
new_ucmd!().args(&test_vec).succeeds().stdout_is("fo<EFBFBD>o\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(any(unix, target_os = "redox"))]
|
|
|
|
|
#[test]
|
|
|
|
|
fn invalid_utf8_args_unix() {
|
|
|
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
|
|
|
|
|
|
let source = [0x66, 0x6f, 0x80, 0x6f];
|
|
|
|
|
let os_str = OsStr::from_bytes(&source[..]);
|
|
|
|
|
test_invalid_utf8_args(os_str);
|
|
|
|
|
}
|
2021-07-30 15:06:55 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_root() {
|
2021-08-01 14:05:01 +00:00
|
|
|
|
let expected = if cfg!(windows) { "\\\n" } else { "/\n" };
|
|
|
|
|
new_ucmd!().arg("/").succeeds().stdout_is(expected);
|
2021-07-30 15:06:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_double_slash() {
|
|
|
|
|
// TODO The GNU tests seem to suggest that some systems treat "//"
|
|
|
|
|
// as the same directory as "/" directory but not all systems. We
|
|
|
|
|
// should extend this test to account for that possibility.
|
2021-08-01 14:05:01 +00:00
|
|
|
|
let expected = if cfg!(windows) { "\\\n" } else { "/\n" };
|
2021-07-30 15:06:55 +00:00
|
|
|
|
new_ucmd!().arg("//").succeeds().stdout_is(expected);
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["//", "/"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.stdout_is(expected);
|
|
|
|
|
new_ucmd!()
|
|
|
|
|
.args(&["//", "//"])
|
|
|
|
|
.succeeds()
|
|
|
|
|
.stdout_is(expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_triple_slash() {
|
2021-08-01 14:05:01 +00:00
|
|
|
|
let expected = if cfg!(windows) { "\\\n" } else { "/\n" };
|
|
|
|
|
new_ucmd!().arg("///").succeeds().stdout_is(expected);
|
2021-07-30 15:06:55 +00:00
|
|
|
|
}
|