1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

env: ignore flags after the command or -- argument

This commit is contained in:
Dan Hipschman 2025-04-18 12:29:50 -07:00
parent d68e288602
commit 814e82ea4e
2 changed files with 120 additions and 22 deletions

View file

@ -66,6 +66,61 @@ fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(125);
}
#[test]
#[cfg(not(target_os = "windows"))]
fn test_flags_after_command() {
new_ucmd!()
// This would cause an error if -u=v were processed because it's malformed
.args(&["echo", "-u=v"])
.succeeds()
.no_stderr()
.stdout_is("-u=v\n");
new_ucmd!()
// Ensure the string isn't split
// cSpell:disable
.args(&["printf", "%s-%s", "-Sfoo bar"])
.succeeds()
.no_stderr()
.stdout_is("-Sfoo bar-");
// cSpell:enable
new_ucmd!()
// Ensure -- is recognized
.args(&["-i", "--", "-u=v"])
.succeeds()
.no_stderr()
.stdout_is("-u=v\n");
new_ucmd!()
// Recognize echo as the command after a flag that takes a value
.args(&["-C", "..", "echo", "-u=v"])
.succeeds()
.no_stderr()
.stdout_is("-u=v\n");
new_ucmd!()
// Recognize echo as the command after a flag that takes an inline value
.args(&["-C..", "echo", "-u=v"])
.succeeds()
.no_stderr()
.stdout_is("-u=v\n");
new_ucmd!()
// Recognize echo as the command after a flag that takes a value after another flag
.args(&["-iC", "..", "echo", "-u=v"])
.succeeds()
.no_stderr()
.stdout_is("-u=v\n");
new_ucmd!()
// Similar to the last two combined
.args(&["-iC..", "echo", "-u=v"])
.succeeds()
.no_stderr()
.stdout_is("-u=v\n");
}
#[test]
fn test_env_help() {
new_ucmd!()