1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

tests ~ fix tests for new execution_phrase!() and usage phrasing

This commit is contained in:
Roy Ivy III 2021-07-27 00:21:12 -05:00 committed by Michael Debertol
parent c0854000d1
commit 4da46d93c7
11 changed files with 96 additions and 48 deletions

View file

@ -85,11 +85,15 @@ fn test_wrap() {
#[test] #[test]
fn test_wrap_no_arg() { fn test_wrap_no_arg() {
for wrap_param in &["-w", "--wrap"] { for wrap_param in &["-w", "--wrap"] {
let expected_stderr = "error: The argument '--wrap <wrap>\' requires a value but none was \ let ts = TestScenario::new(util_name!());
supplied\n\nUSAGE:\n base32 [OPTION]... [FILE]\n\nFor more \ let expected_stderr = &format!(
information try --help" "error: The argument '--wrap <wrap>\' requires a value but none was \
.to_string(); supplied\n\nUSAGE:\n {1} {0} [OPTION]... [FILE]\n\nFor more \
new_ucmd!() information try --help",
ts.util_name,
ts.bin_path.to_string_lossy()
);
ts.ucmd()
.arg(wrap_param) .arg(wrap_param)
.fails() .fails()
.stderr_only(expected_stderr); .stderr_only(expected_stderr);

View file

@ -114,9 +114,12 @@ fn test_no_args() {
#[test] #[test]
fn test_no_args_output() { fn test_no_args_output() {
new_ucmd!() let ts = TestScenario::new(util_name!());
.fails() ts.ucmd().fails().stderr_is(&format!(
.stderr_is("basename: missing operand\nTry 'basename --help' for more information."); "{0}: missing operand\nTry `{1} {0} --help` for more information.",
ts.util_name,
ts.bin_path.to_string_lossy()
));
} }
#[test] #[test]
@ -126,10 +129,12 @@ fn test_too_many_args() {
#[test] #[test]
fn test_too_many_args_output() { fn test_too_many_args_output() {
new_ucmd!() let ts = TestScenario::new(util_name!());
.args(&["a", "b", "c"]) ts.ucmd().args(&["a", "b", "c"]).fails().stderr_is(format!(
.fails() "{0}: extra operand 'c'\nTry `{1} {0} --help` for more information.",
.stderr_is("basename: extra operand 'c'\nTry 'basename --help' for more information."); ts.util_name,
ts.bin_path.to_string_lossy()
));
} }
#[cfg(any(unix, target_os = "redox"))] #[cfg(any(unix, target_os = "redox"))]

View file

@ -561,14 +561,17 @@ fn test_cp_backup_off() {
#[test] #[test]
fn test_cp_backup_no_clobber_conflicting_options() { fn test_cp_backup_no_clobber_conflicting_options() {
let (_, mut ucmd) = at_and_ucmd!(); let ts = TestScenario::new(util_name!());
ts.ucmd()
ucmd.arg("--backup") .arg("--backup")
.arg("--no-clobber") .arg("--no-clobber")
.arg(TEST_HELLO_WORLD_SOURCE) .arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HOW_ARE_YOU_SOURCE) .arg(TEST_HOW_ARE_YOU_SOURCE)
.fails() .fails().stderr_is(&format!(
.stderr_is("cp: options --backup and --no-clobber are mutually exclusive\nTry 'cp --help' for more information."); "{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] #[test]

View file

@ -15,11 +15,15 @@ fn test_more_dir_arg() {
// Maybe we could capture the error, i.e. "Device not found" in that case // Maybe we could capture the error, i.e. "Device not found" in that case
// but I am leaving this for later // but I am leaving this for later
if atty::is(atty::Stream::Stdout) { 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(); result.failure();
const EXPECTED_ERROR_MESSAGE: &str = let expected_error_message = &format!(
"more: '.' is a directory.\nTry 'more --help' for more information."; "{0}: '.' is a directory.\nTry `{1} {0} --help` for more information.",
assert_eq!(result.stderr_str().trim(), EXPECTED_ERROR_MESSAGE); ts.util_name,
ts.bin_path.to_string_lossy()
);
assert_eq!(result.stderr_str().trim(), expected_error_message);
} else { } else {
} }
} }

View file

@ -522,14 +522,17 @@ fn test_mv_backup_off() {
#[test] #[test]
fn test_mv_backup_no_clobber_conflicting_options() { 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("--no-clobber")
.arg("file1") .arg("file1")
.arg("file2") .arg("file2")
.fails() .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] #[test]

View file

@ -22,10 +22,15 @@ fn test_negative_adjustment() {
#[test] #[test]
fn test_adjustment_with_no_command_should_error() { fn test_adjustment_with_no_command_should_error() {
new_ucmd!() let ts = TestScenario::new(util_name!());
ts.ucmd()
.args(&["-n", "19"]) .args(&["-n", "19"])
.run() .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] #[test]

View file

@ -255,10 +255,12 @@ fn test_rm_force_no_operand() {
#[test] #[test]
fn test_rm_no_operand() { fn test_rm_no_operand() {
let mut ucmd = new_ucmd!(); let ts = TestScenario::new(util_name!());
ts.ucmd().fails().stderr_is(&format!(
ucmd.fails() "{0}: missing an argument\n{0}: for help, try '{1} {0} --help'\n",
.stderr_is("rm: missing an argument\nrm: for help, try 'rm --help'\n"); ts.util_name,
ts.bin_path.to_string_lossy()
));
} }
#[test] #[test]

View file

@ -2,16 +2,24 @@ use crate::common::util::*;
#[test] #[test]
fn test_rejects_nan() { fn test_rejects_nan() {
new_ucmd!().args(&["NaN"]).fails().stderr_only( let ts = TestScenario::new(util_name!());
"seq: invalid 'not-a-number' argument: 'NaN'\nTry 'seq --help' for more information.",
); 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] #[test]
fn test_rejects_non_floats() { fn test_rejects_non_floats() {
new_ucmd!().args(&["foo"]).fails().stderr_only( let ts = TestScenario::new(util_name!());
"seq: invalid floating point argument: 'foo'\nTry 'seq --help' for more information.",
); 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 ---- // ---- Tests for the big integer based path ----

View file

@ -25,15 +25,19 @@ fn test_stdbuf_line_buffered_stdout() {
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
#[test] #[test]
fn test_stdbuf_no_buffer_option_fails() { 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: The following required arguments were not provided:\n \
--error <MODE>\n \ --error <MODE>\n \
--input <MODE>\n \ --input <MODE>\n \
--output <MODE>\n\n\ --output <MODE>\n\n\
USAGE:\n \ USAGE:\n \
stdbuf OPTION... COMMAND\n\n\ {1} {0} OPTION... COMMAND\n\n\
For more information try --help", For more information try --help",
); ts.util_name,
ts.bin_path.to_string_lossy()
));
} }
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
@ -49,9 +53,16 @@ fn test_stdbuf_trailing_var_arg() {
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
#[test] #[test]
fn test_stdbuf_line_buffering_stdin_fails() { fn test_stdbuf_line_buffering_stdin_fails() {
new_ucmd!().args(&["-i", "L", "head"]).fails().stderr_is( let ts = TestScenario::new(util_name!());
"stdbuf: line buffering stdin is meaningless\nTry 'stdbuf --help' for more information.",
); 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"))] #[cfg(not(target_os = "windows"))]

View file

@ -14,17 +14,20 @@ fn test_unlink_file() {
#[test] #[test]
fn test_unlink_multiple_files() { 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_a = "test_unlink_multiple_file_a";
let file_b = "test_unlink_multiple_file_b"; let file_b = "test_unlink_multiple_file_b";
at.touch(file_a); at.touch(file_a);
at.touch(file_b); at.touch(file_b);
ucmd.arg(file_a).arg(file_b).fails().stderr_is( ucmd.arg(file_a).arg(file_b).fails().stderr_is(&format!(
"unlink: extra operand: 'test_unlink_multiple_file_b'\nTry 'unlink --help' \ "{0}: extra operand: 'test_unlink_multiple_file_b'\nTry `{1} {0} --help` for more information.",
for more information.\n", ts.util_name,
); ts.bin_path.to_string_lossy()
));
} }
#[test] #[test]

View file

@ -713,7 +713,7 @@ impl AtPath {
/// ///
/// Fixtures can be found under `tests/fixtures/$util_name/` /// Fixtures can be found under `tests/fixtures/$util_name/`
pub struct TestScenario { pub struct TestScenario {
bin_path: PathBuf, pub bin_path: PathBuf,
pub util_name: String, pub util_name: String,
pub fixtures: AtPath, pub fixtures: AtPath,
tmpd: Rc<TempDir>, tmpd: Rc<TempDir>,