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

tests: revise/standardize usage error testing (for dd, install, mktemp, rm, seq, and touch)

This commit is contained in:
Roy Ivy III 2023-01-08 12:39:49 -06:00
parent 6a9660f9f6
commit d78e1e7399
6 changed files with 45 additions and 62 deletions

View file

@ -1303,12 +1303,12 @@ fn test_invalid_flag_arg_gnu_compatibility() {
new_ucmd!() new_ucmd!()
.args(&[format!("{}=", command)]) .args(&[format!("{}=", command)])
.fails() .fails()
.stderr_is("dd: invalid input flag: \nTry 'dd --help' for more information."); .usage_error("invalid input flag: ");
new_ucmd!() new_ucmd!()
.args(&[format!("{}=29d", command)]) .args(&[format!("{}=29d", command)])
.fails() .fails()
.stderr_is("dd: invalid input flag: 29d\nTry 'dd --help' for more information."); .usage_error("invalid input flag: 29d");
} }
} }

View file

@ -1257,16 +1257,14 @@ fn test_install_missing_arguments() {
.ucmd() .ucmd()
.fails() .fails()
.code_is(1) .code_is(1)
.stderr_contains("install: missing file operand") .usage_error("missing file operand");
.stderr_contains("install --help' for more information.");
scene scene
.ucmd() .ucmd()
.arg("-D") .arg("-D")
.arg(format!("-t {}", no_target_dir)) .arg(format!("-t {}", no_target_dir))
.fails() .fails()
.stderr_contains("install: missing file operand") .usage_error("missing file operand");
.stderr_contains("install --help' for more information.");
assert!(!at.dir_exists(no_target_dir)); assert!(!at.dir_exists(no_target_dir));
} }
@ -1282,27 +1280,17 @@ fn test_install_missing_destination() {
at.mkdir(dir_1); at.mkdir(dir_1);
// will fail and also print some info on correct usage // will fail and also print some info on correct usage
scene scene.ucmd().arg(file_1).fails().usage_error(format!(
.ucmd() "missing destination file operand after '{}'",
.arg(file_1) file_1
.fails() ));
.stderr_contains(format!(
"install: missing destination file operand after '{}'",
file_1
))
.stderr_contains("install --help' for more information.");
// GNU's install will check for correct num of arguments and then fail // GNU's install will check for correct num of arguments and then fail
// and it does not recognize, that the source is not a file but a directory. // and it does not recognize, that the source is not a file but a directory.
scene scene.ucmd().arg(dir_1).fails().usage_error(format!(
.ucmd() "missing destination file operand after '{}'",
.arg(dir_1) dir_1
.fails() ));
.stderr_contains(format!(
"install: missing destination file operand after '{}'",
dir_1
))
.stderr_contains("install --help' for more information.");
} }
#[test] #[test]

View file

@ -673,11 +673,7 @@ fn test_mktemp_with_posixly_correct() {
.env("POSIXLY_CORRECT", "1") .env("POSIXLY_CORRECT", "1")
.args(&["aXXXX", "--suffix=b"]) .args(&["aXXXX", "--suffix=b"])
.fails() .fails()
.stderr_is(&format!( .usage_error("too many templates");
"mktemp: too many templates\nTry '{} {} --help' for more information.\n",
scene.bin_path.to_string_lossy(),
scene.util_name
));
scene scene
.ucmd() .ucmd()

View file

@ -286,11 +286,7 @@ fn test_rm_force_no_operand() {
#[test] #[test]
fn test_rm_no_operand() { fn test_rm_no_operand() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
ts.ucmd().fails().stderr_is(&format!( ts.ucmd().fails().usage_error("missing operand");
"{0}: missing operand\nTry '{1} {0} --help' for more information.\n",
ts.util_name,
ts.bin_path.to_string_lossy()
));
} }
#[test] #[test]

View file

@ -13,25 +13,40 @@ fn test_hex_rejects_sign_after_identifier() {
.args(&["0x-123ABC"]) .args(&["0x-123ABC"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '0x-123ABC'") .usage_error("invalid floating point argument: '0x-123ABC'");
.stderr_contains("for more information.");
new_ucmd!() new_ucmd!()
.args(&["0x+123ABC"]) .args(&["0x+123ABC"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '0x+123ABC'") .usage_error("invalid floating point argument: '0x+123ABC'");
.stderr_contains("for more information.");
new_ucmd!()
.args(&["--", "-0x-123ABC"])
.fails()
.no_stdout()
.usage_error("invalid floating point argument: '-0x-123ABC'");
new_ucmd!()
.args(&["--", "-0x+123ABC"])
.fails()
.no_stdout()
.usage_error("invalid floating point argument: '-0x+123ABC'");
// test without "--" => argument parsed as (invalid) flag
new_ucmd!() new_ucmd!()
.args(&["-0x-123ABC"]) .args(&["-0x-123ABC"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("which wasn't expected, or isn't valid in this context") .stderr_contains(
"Found argument '-0' which wasn't expected, or isn't valid in this context",
)
.stderr_contains("For more information try '--help'"); .stderr_contains("For more information try '--help'");
new_ucmd!() new_ucmd!()
.args(&["-0x+123ABC"]) .args(&["-0x+123ABC"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("which wasn't expected, or isn't valid in this context") .stderr_contains(
"Found argument '-0' which wasn't expected, or isn't valid in this context",
)
.stderr_contains("For more information try '--help'"); .stderr_contains("For more information try '--help'");
} }
@ -66,8 +81,7 @@ fn test_hex_identifier_in_wrong_place() {
.args(&["1234ABCD0x"]) .args(&["1234ABCD0x"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '1234ABCD0x'") .usage_error("invalid floating point argument: '1234ABCD0x'");
.stderr_contains("for more information.");
} }
#[test] #[test]
@ -119,38 +133,32 @@ fn test_invalid_float() {
.args(&["1e2.3"]) .args(&["1e2.3"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '1e2.3'") .usage_error("invalid floating point argument: '1e2.3'");
.stderr_contains("for more information.");
new_ucmd!() new_ucmd!()
.args(&["1e2.3", "2"]) .args(&["1e2.3", "2"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '1e2.3'") .usage_error("invalid floating point argument: '1e2.3'");
.stderr_contains("for more information.");
new_ucmd!() new_ucmd!()
.args(&["1", "1e2.3"]) .args(&["1", "1e2.3"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '1e2.3'") .usage_error("invalid floating point argument: '1e2.3'");
.stderr_contains("for more information.");
new_ucmd!() new_ucmd!()
.args(&["1e2.3", "2", "3"]) .args(&["1e2.3", "2", "3"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '1e2.3'") .usage_error("invalid floating point argument: '1e2.3'");
.stderr_contains("for more information.");
new_ucmd!() new_ucmd!()
.args(&["1", "1e2.3", "3"]) .args(&["1", "1e2.3", "3"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '1e2.3'") .usage_error("invalid floating point argument: '1e2.3'");
.stderr_contains("for more information.");
new_ucmd!() new_ucmd!()
.args(&["1", "2", "1e2.3"]) .args(&["1", "2", "1e2.3"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '1e2.3'") .usage_error("invalid floating point argument: '1e2.3'");
.stderr_contains("for more information.");
} }
#[test] #[test]
@ -159,8 +167,7 @@ fn test_width_invalid_float() {
.args(&["-w", "1e2.3"]) .args(&["-w", "1e2.3"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid floating point argument: '1e2.3'") .usage_error("invalid floating point argument: '1e2.3'");
.stderr_contains("for more information.");
} }
// ---- Tests for the big integer based path ---- // ---- Tests for the big integer based path ----
@ -738,6 +745,5 @@ fn test_invalid_zero_increment_value() {
.args(&["0", "0", "1"]) .args(&["0", "0", "1"])
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains("invalid Zero increment value: '0'") .usage_error("invalid Zero increment value: '0'");
.stderr_contains("for more information.");
} }

View file

@ -763,10 +763,7 @@ fn test_touch_permission_denied_error_msg() {
#[test] #[test]
fn test_touch_no_args() { fn test_touch_no_args() {
let mut ucmd = new_ucmd!(); let mut ucmd = new_ucmd!();
ucmd.fails().stderr_only( ucmd.fails().no_stdout().usage_error("missing file operand");
r##"touch: missing file operand
Try 'touch --help' for more information."##,
);
} }
#[test] #[test]