mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 19:56:17 +00:00
Merge pull request #2471 from miDeb/real-exe-name
make executable!() return the real executable name
This commit is contained in:
commit
114c9a409c
114 changed files with 675 additions and 493 deletions
|
@ -85,11 +85,15 @@ fn test_wrap() {
|
|||
#[test]
|
||||
fn test_wrap_no_arg() {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
let expected_stderr = "error: The argument '--wrap <wrap>\' requires a value but none was \
|
||||
supplied\n\nUSAGE:\n base32 [OPTION]... [FILE]\n\nFor more \
|
||||
information try --help"
|
||||
.to_string();
|
||||
new_ucmd!()
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let expected_stderr = &format!(
|
||||
"error: The argument '--wrap <wrap>\' requires a value but none was \
|
||||
supplied\n\nUSAGE:\n {1} {0} [OPTION]... [FILE]\n\nFor more \
|
||||
information try --help",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
);
|
||||
ts.ucmd()
|
||||
.arg(wrap_param)
|
||||
.fails()
|
||||
.stderr_only(expected_stderr);
|
||||
|
|
|
@ -114,9 +114,12 @@ fn test_no_args() {
|
|||
|
||||
#[test]
|
||||
fn test_no_args_output() {
|
||||
new_ucmd!()
|
||||
.fails()
|
||||
.stderr_is("basename: missing operand\nTry 'basename --help' for more information.");
|
||||
let ts = TestScenario::new(util_name!());
|
||||
ts.ucmd().fails().stderr_is(&format!(
|
||||
"{0}: missing operand\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -126,10 +129,12 @@ fn test_too_many_args() {
|
|||
|
||||
#[test]
|
||||
fn test_too_many_args_output() {
|
||||
new_ucmd!()
|
||||
.args(&["a", "b", "c"])
|
||||
.fails()
|
||||
.stderr_is("basename: extra operand 'c'\nTry 'basename --help' for more information.");
|
||||
let ts = TestScenario::new(util_name!());
|
||||
ts.ucmd().args(&["a", "b", "c"]).fails().stderr_is(format!(
|
||||
"{0}: extra operand 'c'\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
|
|
|
@ -561,14 +561,17 @@ fn test_cp_backup_off() {
|
|||
|
||||
#[test]
|
||||
fn test_cp_backup_no_clobber_conflicting_options() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
ucmd.arg("--backup")
|
||||
let ts = TestScenario::new(util_name!());
|
||||
ts.ucmd()
|
||||
.arg("--backup")
|
||||
.arg("--no-clobber")
|
||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.fails()
|
||||
.stderr_is("cp: options --backup and --no-clobber are mutually exclusive\nTry 'cp --help' for more information.");
|
||||
.fails().stderr_is(&format!(
|
||||
"{0}: options --backup and --no-clobber are mutually exclusive\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -15,11 +15,15 @@ fn test_more_dir_arg() {
|
|||
// Maybe we could capture the error, i.e. "Device not found" in that case
|
||||
// but I am leaving this for later
|
||||
if atty::is(atty::Stream::Stdout) {
|
||||
let result = new_ucmd!().arg(".").run();
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let result = ts.ucmd().arg(".").run();
|
||||
result.failure();
|
||||
const EXPECTED_ERROR_MESSAGE: &str =
|
||||
"more: '.' is a directory.\nTry 'more --help' for more information.";
|
||||
assert_eq!(result.stderr_str().trim(), EXPECTED_ERROR_MESSAGE);
|
||||
let expected_error_message = &format!(
|
||||
"{0}: '.' is a directory.\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
);
|
||||
assert_eq!(result.stderr_str().trim(), expected_error_message);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -522,14 +522,17 @@ fn test_mv_backup_off() {
|
|||
|
||||
#[test]
|
||||
fn test_mv_backup_no_clobber_conflicting_options() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
||||
ucmd.arg("--backup")
|
||||
ts.ucmd().arg("--backup")
|
||||
.arg("--no-clobber")
|
||||
.arg("file1")
|
||||
.arg("file2")
|
||||
.fails()
|
||||
.stderr_is("mv: options --backup and --no-clobber are mutually exclusive\nTry 'mv --help' for more information.");
|
||||
.stderr_is(&format!("{0}: options --backup and --no-clobber are mutually exclusive\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -22,10 +22,15 @@ fn test_negative_adjustment() {
|
|||
|
||||
#[test]
|
||||
fn test_adjustment_with_no_command_should_error() {
|
||||
new_ucmd!()
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["-n", "19"])
|
||||
.run()
|
||||
.stderr_is("nice: A command must be given with an adjustment.\nTry \"nice --help\" for more information.\n");
|
||||
.stderr_is(&format!("{0}: A command must be given with an adjustment.\nTry '{1} {0} --help' for more information.\n",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -255,10 +255,12 @@ fn test_rm_force_no_operand() {
|
|||
|
||||
#[test]
|
||||
fn test_rm_no_operand() {
|
||||
let mut ucmd = new_ucmd!();
|
||||
|
||||
ucmd.fails()
|
||||
.stderr_is("rm: missing an argument\nrm: for help, try 'rm --help'\n");
|
||||
let ts = TestScenario::new(util_name!());
|
||||
ts.ucmd().fails().stderr_is(&format!(
|
||||
"{0}: missing an argument\n{0}: for help, try '{1} {0} --help'\n",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -2,16 +2,24 @@ use crate::common::util::*;
|
|||
|
||||
#[test]
|
||||
fn test_rejects_nan() {
|
||||
new_ucmd!().args(&["NaN"]).fails().stderr_only(
|
||||
"seq: invalid 'not-a-number' argument: 'NaN'\nTry 'seq --help' for more information.",
|
||||
);
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
||||
ts.ucmd().args(&["NaN"]).fails().stderr_only(format!(
|
||||
"{0}: invalid 'not-a-number' argument: 'NaN'\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rejects_non_floats() {
|
||||
new_ucmd!().args(&["foo"]).fails().stderr_only(
|
||||
"seq: invalid floating point argument: 'foo'\nTry 'seq --help' for more information.",
|
||||
);
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
||||
ts.ucmd().args(&["foo"]).fails().stderr_only(&format!(
|
||||
"{0}: invalid floating point argument: 'foo'\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
// ---- Tests for the big integer based path ----
|
||||
|
|
|
@ -25,15 +25,19 @@ fn test_stdbuf_line_buffered_stdout() {
|
|||
#[cfg(not(target_os = "windows"))]
|
||||
#[test]
|
||||
fn test_stdbuf_no_buffer_option_fails() {
|
||||
new_ucmd!().args(&["head"]).fails().stderr_is(
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
||||
ts.ucmd().args(&["head"]).fails().stderr_is(&format!(
|
||||
"error: The following required arguments were not provided:\n \
|
||||
--error <MODE>\n \
|
||||
--input <MODE>\n \
|
||||
--output <MODE>\n\n\
|
||||
USAGE:\n \
|
||||
stdbuf OPTION... COMMAND\n\n\
|
||||
{1} {0} OPTION... COMMAND\n\n\
|
||||
For more information try --help",
|
||||
);
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -49,9 +53,16 @@ fn test_stdbuf_trailing_var_arg() {
|
|||
#[cfg(not(target_os = "windows"))]
|
||||
#[test]
|
||||
fn test_stdbuf_line_buffering_stdin_fails() {
|
||||
new_ucmd!().args(&["-i", "L", "head"]).fails().stderr_is(
|
||||
"stdbuf: line buffering stdin is meaningless\nTry 'stdbuf --help' for more information.",
|
||||
);
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
||||
ts.ucmd()
|
||||
.args(&["-i", "L", "head"])
|
||||
.fails()
|
||||
.stderr_is(&format!(
|
||||
"{0}: line buffering stdin is meaningless\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
|
|
@ -14,17 +14,20 @@ fn test_unlink_file() {
|
|||
|
||||
#[test]
|
||||
fn test_unlink_multiple_files() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
||||
let (at, mut ucmd) = (ts.fixtures.clone(), ts.ucmd());
|
||||
let file_a = "test_unlink_multiple_file_a";
|
||||
let file_b = "test_unlink_multiple_file_b";
|
||||
|
||||
at.touch(file_a);
|
||||
at.touch(file_b);
|
||||
|
||||
ucmd.arg(file_a).arg(file_b).fails().stderr_is(
|
||||
"unlink: extra operand: 'test_unlink_multiple_file_b'\nTry 'unlink --help' \
|
||||
for more information.\n",
|
||||
);
|
||||
ucmd.arg(file_a).arg(file_b).fails().stderr_is(&format!(
|
||||
"{0}: extra operand: 'test_unlink_multiple_file_b'\nTry '{1} {0} --help' for more information.",
|
||||
ts.util_name,
|
||||
ts.bin_path.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -713,7 +713,7 @@ impl AtPath {
|
|||
///
|
||||
/// Fixtures can be found under `tests/fixtures/$util_name/`
|
||||
pub struct TestScenario {
|
||||
bin_path: PathBuf,
|
||||
pub bin_path: PathBuf,
|
||||
pub util_name: String,
|
||||
pub fixtures: AtPath,
|
||||
tmpd: Rc<TempDir>,
|
||||
|
|
86
tests/test_util_name.rs
Normal file
86
tests/test_util_name.rs
Normal file
|
@ -0,0 +1,86 @@
|
|||
mod common;
|
||||
|
||||
use common::util::TestScenario;
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::symlink as symlink_file;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::fs::symlink_file;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "ls")]
|
||||
fn execution_phrase_double() {
|
||||
use std::process::Command;
|
||||
|
||||
let scenario = TestScenario::new("ls");
|
||||
let output = Command::new(&scenario.bin_path)
|
||||
.arg("ls")
|
||||
.arg("--some-invalid-arg")
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(String::from_utf8(output.stderr)
|
||||
.unwrap()
|
||||
.contains(&format!("USAGE:\n {} ls", scenario.bin_path.display(),)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "ls")]
|
||||
fn execution_phrase_single() {
|
||||
use std::process::Command;
|
||||
|
||||
let scenario = TestScenario::new("ls");
|
||||
symlink_file(scenario.bin_path, scenario.fixtures.plus("uu-ls")).unwrap();
|
||||
let output = Command::new(scenario.fixtures.plus("uu-ls"))
|
||||
.arg("--some-invalid-arg")
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(String::from_utf8(output.stderr).unwrap().contains(&format!(
|
||||
"USAGE:\n {}",
|
||||
scenario.fixtures.plus("uu-ls").display()
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "sort")]
|
||||
fn util_name_double() {
|
||||
use std::{
|
||||
io::Write,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
let scenario = TestScenario::new("sort");
|
||||
let mut child = Command::new(&scenario.bin_path)
|
||||
.arg("sort")
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
// input invalid utf8 to cause an error
|
||||
child.stdin.take().unwrap().write_all(&[255]).unwrap();
|
||||
let output = child.wait_with_output().unwrap();
|
||||
assert!(String::from_utf8(output.stderr).unwrap().contains("sort: "));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "sort")]
|
||||
fn util_name_single() {
|
||||
use std::{
|
||||
io::Write,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
let scenario = TestScenario::new("sort");
|
||||
symlink_file(scenario.bin_path, scenario.fixtures.plus("uu-sort")).unwrap();
|
||||
let mut child = Command::new(scenario.fixtures.plus("uu-sort"))
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
// input invalid utf8 to cause an error
|
||||
child.stdin.take().unwrap().write_all(&[255]).unwrap();
|
||||
let output = child.wait_with_output().unwrap();
|
||||
assert!(String::from_utf8(output.stderr).unwrap().contains(&format!(
|
||||
"{}: ",
|
||||
scenario.fixtures.plus("uu-sort").display()
|
||||
)));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue