1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 13:07:46 +00:00

Merge pull request #6018 from BenWiederhake/dev-basename-multi-arg

basename: Fix handling of repeated flags/arguments
This commit is contained in:
Daniel Hofstetter 2024-02-27 10:03:14 +01:00 committed by GitHub
commit 8b2a2921c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 98 additions and 68 deletions

View file

@ -201,3 +201,67 @@ fn test_simple_format() {
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}
#[test]
fn test_repeated_multiple() {
new_ucmd!()
.args(&["-aa", "-a", "foo"])
.succeeds()
.stdout_is("foo\n");
}
#[test]
fn test_repeated_multiple_many() {
new_ucmd!()
.args(&["-aa", "-a", "1/foo", "q/bar", "x/y/baz"])
.succeeds()
.stdout_is("foo\nbar\nbaz\n");
}
#[test]
fn test_repeated_suffix_last() {
new_ucmd!()
.args(&["-s", ".h", "-s", ".c", "foo.c"])
.succeeds()
.stdout_is("foo\n");
}
#[test]
fn test_repeated_suffix_not_first() {
new_ucmd!()
.args(&["-s", ".h", "-s", ".c", "foo.h"])
.succeeds()
.stdout_is("foo.h\n");
}
#[test]
fn test_repeated_suffix_multiple() {
new_ucmd!()
.args(&["-as", ".h", "-a", "-s", ".c", "foo.c", "bar.c", "bar.h"])
.succeeds()
.stdout_is("foo\nbar\nbar.h\n");
}
#[test]
fn test_repeated_zero() {
new_ucmd!()
.args(&["-zz", "-z", "foo/bar"])
.succeeds()
.stdout_is("bar\0");
}
#[test]
fn test_zero_does_not_imply_multiple() {
new_ucmd!()
.args(&["-z", "foo.c", "c"])
.succeeds()
.stdout_is("foo.\0");
}
#[test]
fn test_suffix_implies_multiple() {
new_ucmd!()
.args(&["-s", ".c", "foo.c", "o.c"])
.succeeds()
.stdout_is("foo\no\n");
}