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]
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);

View file

@ -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"))]

View file

@ -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]

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
// 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 {
}
}

View file

@ -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]

View file

@ -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]

View file

@ -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]

View file

@ -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 ----

View file

@ -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"))]

View file

@ -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]

View file

@ -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>,