mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Fix tr
argument handling for missing arguments (#1601)
* tests/tr ~ confirm failure for missing argument(s) * fix/tr ~ mimic GNU error reponse for missing argument(s)
This commit is contained in:
parent
9a1c560aba
commit
0fa249a944
2 changed files with 37 additions and 5 deletions
|
@ -218,17 +218,29 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.free.is_empty() {
|
|
||||||
usage(&opts);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let dflag = matches.opt_present("d");
|
let dflag = matches.opt_present("d");
|
||||||
let cflag = matches.opts_present(&["c".to_owned(), "C".to_owned()]);
|
let cflag = matches.opts_present(&["c".to_owned(), "C".to_owned()]);
|
||||||
let sflag = matches.opt_present("s");
|
let sflag = matches.opt_present("s");
|
||||||
let tflag = matches.opt_present("t");
|
let tflag = matches.opt_present("t");
|
||||||
let sets = matches.free;
|
let sets = matches.free;
|
||||||
|
|
||||||
|
if sets.is_empty() {
|
||||||
|
show_error!(
|
||||||
|
"missing operand\nTry `{} --help` for more information.",
|
||||||
|
NAME
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(dflag || sflag) && sets.len() < 2 {
|
||||||
|
show_error!(
|
||||||
|
"missing operand after ‘{}’\nTry `{} --help` for more information.",
|
||||||
|
sets[0],
|
||||||
|
NAME
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if cflag && !dflag && !sflag {
|
if cflag && !dflag && !sflag {
|
||||||
show_error!("-c is only supported with -d or -s");
|
show_error!("-c is only supported with -d or -s");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -116,3 +116,23 @@ fn test_truncate_with_set1_shorter_than_set2() {
|
||||||
.run()
|
.run()
|
||||||
.stdout_is("xycde");
|
.stdout_is("xycde");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn missing_args_fails() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
let result = ucmd.run();
|
||||||
|
|
||||||
|
assert!(!result.success);
|
||||||
|
assert!(result.stderr.contains("missing operand"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn missing_required_second_arg_fails() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
let result = ucmd
|
||||||
|
.args(&["foo"])
|
||||||
|
.run();
|
||||||
|
|
||||||
|
assert!(!result.success);
|
||||||
|
assert!(result.stderr.contains("missing operand after"));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue