From 45c1938eefa3176609ade8871f94e5f9afcfd491 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 2 Apr 2024 21:00:53 +0200 Subject: [PATCH] xargs: add more tests and priority --- src/xargs/mod.rs | 2 +- tests/xargs_tests.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/xargs/mod.rs b/src/xargs/mod.rs index 6a269bd..74144b7 100644 --- a/src/xargs/mod.rs +++ b/src/xargs/mod.rs @@ -888,7 +888,7 @@ fn do_xargs(args: &[&str]) -> Result { max_lines: matches.get_one::(options::MAX_LINES).copied(), no_run_if_empty: matches.get_flag(options::NO_RUN_IF_EMPTY), null: matches.get_flag(options::NULL), - replace: [options::REPLACE, options::REPLACE_I] + replace: [options::REPLACE_I, options::REPLACE] .iter() .find_map(|&option| { matches.contains_id(option).then(|| { diff --git a/tests/xargs_tests.rs b/tests/xargs_tests.rs index 28e7b47..fb6aa9a 100644 --- a/tests/xargs_tests.rs +++ b/tests/xargs_tests.rs @@ -478,6 +478,21 @@ fn xargs_replace() { .assert() .stdout(predicate::str::contains("foo bar foo")); + // other order + Command::cargo_bin("xargs") + .expect("found binary") + .args(["-i", "-I=_", "echo", "{} bar {}"]) + .write_stdin("foo") + .assert() + .stdout(predicate::str::contains("{} bar {}")); + + Command::cargo_bin("xargs") + .expect("found binary") + .args(["-i", "-I", "_", "echo", "{} bar _"]) + .write_stdin("foo") + .assert() + .stdout(predicate::str::contains("{} bar foo")); + // Expected to fail Command::cargo_bin("xargs") .expect("found binary")