mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
tests: use CmdResult::usage_error
This commit is contained in:
parent
f43dfa9a61
commit
c9624725ab
9 changed files with 34 additions and 87 deletions
|
@ -113,18 +113,12 @@ fn test_wrap_bad_arg() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_base32_extra_operand() {
|
fn test_base32_extra_operand() {
|
||||||
let ts = TestScenario::new(util_name!());
|
|
||||||
|
|
||||||
// Expect a failure when multiple files are specified.
|
// Expect a failure when multiple files are specified.
|
||||||
ts.ucmd()
|
new_ucmd!()
|
||||||
.arg("a.txt")
|
.arg("a.txt")
|
||||||
.arg("b.txt")
|
.arg("b.txt")
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only(format!(
|
.usage_error("extra operand 'b.txt'");
|
||||||
"{0}: extra operand 'b.txt'\nTry '{1} {0} --help' for more information.",
|
|
||||||
ts.util_name,
|
|
||||||
ts.bin_path.to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -95,18 +95,12 @@ fn test_wrap_bad_arg() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_base64_extra_operand() {
|
fn test_base64_extra_operand() {
|
||||||
let ts = TestScenario::new(util_name!());
|
|
||||||
|
|
||||||
// Expect a failure when multiple files are specified.
|
// Expect a failure when multiple files are specified.
|
||||||
ts.ucmd()
|
new_ucmd!()
|
||||||
.arg("a.txt")
|
.arg("a.txt")
|
||||||
.arg("b.txt")
|
.arg("b.txt")
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only(format!(
|
.usage_error("extra operand 'b.txt'");
|
||||||
"{0}: extra operand 'b.txt'\nTry '{1} {0} --help' for more information.",
|
|
||||||
ts.util_name,
|
|
||||||
ts.bin_path.to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -114,12 +114,7 @@ fn test_no_args() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_args_output() {
|
fn test_no_args_output() {
|
||||||
let ts = TestScenario::new(util_name!());
|
new_ucmd!().fails().usage_error("missing operand");
|
||||||
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]
|
#[test]
|
||||||
|
@ -129,12 +124,10 @@ fn test_too_many_args() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_too_many_args_output() {
|
fn test_too_many_args_output() {
|
||||||
let ts = TestScenario::new(util_name!());
|
new_ucmd!()
|
||||||
ts.ucmd().args(&["a", "b", "c"]).fails().stderr_is(format!(
|
.args(&["a", "b", "c"])
|
||||||
"{0}: extra operand 'c'\nTry '{1} {0} --help' for more information.",
|
.fails()
|
||||||
ts.util_name,
|
.usage_error("extra operand 'c'");
|
||||||
ts.bin_path.to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(unix, target_os = "redox"))]
|
#[cfg(any(unix, target_os = "redox"))]
|
||||||
|
|
|
@ -563,17 +563,13 @@ fn test_cp_backup_off() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_backup_no_clobber_conflicting_options() {
|
fn test_cp_backup_no_clobber_conflicting_options() {
|
||||||
let ts = TestScenario::new(util_name!());
|
new_ucmd!()
|
||||||
ts.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().stderr_is(&format!(
|
.fails()
|
||||||
"{0}: options --backup and --no-clobber are mutually exclusive\nTry '{1} {0} --help' for more information.",
|
.usage_error("options --backup and --no-clobber are mutually exclusive");
|
||||||
ts.util_name,
|
|
||||||
ts.bin_path.to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -15,15 +15,10 @@ 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 ts = TestScenario::new(util_name!());
|
new_ucmd!()
|
||||||
let result = ts.ucmd().arg(".").run();
|
.arg(".")
|
||||||
result.failure();
|
.fails()
|
||||||
let expected_error_message = &format!(
|
.usage_error("'.' is a directory.");
|
||||||
"{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 {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -522,17 +522,13 @@ fn test_mv_backup_off() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mv_backup_no_clobber_conflicting_options() {
|
fn test_mv_backup_no_clobber_conflicting_options() {
|
||||||
let ts = TestScenario::new(util_name!());
|
new_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(&format!("{0}: options --backup and --no-clobber are mutually exclusive\nTry '{1} {0} --help' for more information.",
|
.usage_error("options --backup and --no-clobber are mutually exclusive");
|
||||||
ts.util_name,
|
|
||||||
ts.bin_path.to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -22,15 +22,10 @@ fn test_negative_adjustment() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_adjustment_with_no_command_should_error() {
|
fn test_adjustment_with_no_command_should_error() {
|
||||||
let ts = TestScenario::new(util_name!());
|
new_ucmd!()
|
||||||
|
.args(&["-n", "19"])
|
||||||
ts.ucmd()
|
.fails()
|
||||||
.args(&["-n", "19"])
|
.usage_error("A command must be given with an adjustment.");
|
||||||
.run()
|
|
||||||
.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]
|
||||||
|
|
|
@ -66,24 +66,18 @@ fn test_hex_identifier_in_wrong_place() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rejects_nan() {
|
fn test_rejects_nan() {
|
||||||
let ts = TestScenario::new(util_name!());
|
new_ucmd!()
|
||||||
|
.arg("NaN")
|
||||||
ts.ucmd().args(&["NaN"]).fails().stderr_only(format!(
|
.fails()
|
||||||
"{0}: invalid 'not-a-number' argument: 'NaN'\nTry '{1} {0} --help' for more information.",
|
.usage_error("invalid 'not-a-number' argument: 'NaN'");
|
||||||
ts.util_name,
|
|
||||||
ts.bin_path.to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rejects_non_floats() {
|
fn test_rejects_non_floats() {
|
||||||
let ts = TestScenario::new(util_name!());
|
new_ucmd!()
|
||||||
|
.arg("foo")
|
||||||
ts.ucmd().args(&["foo"]).fails().stderr_only(&format!(
|
.fails()
|
||||||
"{0}: invalid floating point argument: 'foo'\nTry '{1} {0} --help' for more information.",
|
.usage_error("invalid floating point argument: 'foo'");
|
||||||
ts.util_name,
|
|
||||||
ts.bin_path.to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -547,11 +541,7 @@ fn test_trailing_whitespace_error() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg("1 ")
|
.arg("1 ")
|
||||||
.fails()
|
.fails()
|
||||||
.no_stdout()
|
.usage_error("invalid floating point argument: '1 '");
|
||||||
.stderr_contains("seq: invalid floating point argument: '1 '")
|
|
||||||
// FIXME The second line of the error message is "Try 'seq
|
|
||||||
// --help' for more information."
|
|
||||||
.stderr_contains("for more information.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -53,16 +53,10 @@ 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() {
|
||||||
let ts = TestScenario::new(util_name!());
|
new_ucmd!()
|
||||||
|
|
||||||
ts.ucmd()
|
|
||||||
.args(&["-i", "L", "head"])
|
.args(&["-i", "L", "head"])
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_is(&format!(
|
.usage_error("line buffering stdin is meaningless");
|
||||||
"{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"))]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue