mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
fix tr with delete flag if more than 1 operand given (#5945)
* fix tr * fix * adding a test * tr: rename test function --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
parent
4c187e29d4
commit
5c2ae5be4f
2 changed files with 19 additions and 0 deletions
|
@ -61,6 +61,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
));
|
||||
}
|
||||
|
||||
if delete_flag && !squeeze_flag && sets_len > 1 {
|
||||
return Err(UUsageError::new(
|
||||
1,
|
||||
format!("extra operand {}\nOnly one string may be given when deleting without squeezing repeats.", sets[1].quote()),
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(first) = sets.first() {
|
||||
if first.ends_with('\\') {
|
||||
show!(USimpleError::new(
|
||||
|
|
|
@ -1147,3 +1147,15 @@ fn check_against_gnu_tr_tests_no_abort_1() {
|
|||
.succeeds()
|
||||
.stdout_is("abb");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_flag_takes_only_one_operand() {
|
||||
// gnu tr -d fails with more than 1 argument
|
||||
new_ucmd!()
|
||||
.args(&["-d", "a", "p"])
|
||||
.pipe_in("abc")
|
||||
.fails()
|
||||
.stderr_contains(
|
||||
"extra operand 'p'\nOnly one string may be given when deleting without squeezing repeats.",
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue