1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37: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:
BaherSalama 2024-02-06 17:42:08 +02:00 committed by GitHub
parent 4c187e29d4
commit 5c2ae5be4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View file

@ -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 let Some(first) = sets.first() {
if first.ends_with('\\') { if first.ends_with('\\') {
show!(USimpleError::new( show!(USimpleError::new(

View file

@ -1147,3 +1147,15 @@ fn check_against_gnu_tr_tests_no_abort_1() {
.succeeds() .succeeds()
.stdout_is("abb"); .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.",
);
}