Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensures the handling of OPTARG is consistent with Bash’s getopts #30

Merged
merged 8 commits into from
Dec 14, 2024
Prev Previous commit
Next Next commit
Updated "option supplied" test to work with declare
  • Loading branch information
UrsaDK committed Dec 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit b963f7dd219f626ebc60f366f53f657aff34c6c6
4 changes: 2 additions & 2 deletions test/bats/github_15a.bats
Original file line number Diff line number Diff line change
@@ -82,14 +82,14 @@ load ../test_helper
compare '-o-- -t user_arg' \
'--option-- --toggle user_arg' \
'1{/(option supplied|INVALID OPTION)/d}'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="--"'
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="option--"'
}
@test "${FEATURE}: long option, verbose" {
compare '-o-- -t user_arg' \
'--option-- --toggle user_arg' \
'1{/(option supplied|illegal option)/d}' \
'2{/^INVALID OPTION or MISSING ARGUMENT/d}'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="--"'
expect "${getopts_long[1]}" =~ "getopts_long-verbose: illegal option -- option--$"
}
4 changes: 2 additions & 2 deletions test/bats/github_15b.bats
Original file line number Diff line number Diff line change
@@ -85,14 +85,14 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-shortspec_with_dash'
compare '-o-- -t user_arg' \
'--option-- --toggle user_arg' \
'1{/(option supplied|INVALID OPTION)/d}'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="--"'
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="option--"'
}
@test "${FEATURE}: long option, verbose" {
compare '-o-- -t user_arg' \
'--option-- --toggle user_arg' \
'1{/(option supplied|illegal option)/d}' \
'2{/^INVALID OPTION or MISSING ARGUMENT/d}'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="--"'
expect "${getopts_long[1]}" =~ "getopts_long-\w+-verbose: illegal option -- option--$"
}
20 changes: 10 additions & 10 deletions test/bats/option_supplied.bats
Original file line number Diff line number Diff line change
@@ -69,27 +69,27 @@ load ../test_helper
@test "${FEATURE}: short option, multiple same arguments, silent" {
compare '-o user_val1 -o user_val2' \
'-o user_val1 -o user_val2'
expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1'
expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2'
expect "${getopts_long[1]}" == 'option supplied -- OPTARG="user_val"1'
expect "${getopts_long[2]}" == 'option supplied -- OPTARG="user_val"2'
}
@test "${FEATURE}: short option, multiple same arguments, verbose" {
compare '-o user_val1 -o user_val2' \
'-o user_val1 -o user_val2'
expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1'
expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2'
expect "${getopts_long[1]}" == 'option supplied -- OPTARG="user_val"1'
expect "${getopts_long[2]}" == 'option supplied -- OPTARG="user_val"2'
}

@test "${FEATURE}: long option, multiple same arguments, silent" {
compare '-o user_val1 -o user_val2' \
'--option user_val1 --option user_val2'
expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1'
expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2'
expect "${getopts_long[1]}" == 'option supplied -- OPTARG="user_val"1'
expect "${getopts_long[2]}" == 'option supplied -- OPTARG="user_val"2'
}
@test "${FEATURE}: long option, multiple same arguments, verbose" {
compare '-o user_val1 -o user_val2' \
'--option user_val1 --option user_val2'
expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1'
expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2'
expect "${getopts_long[1]}" == 'option supplied -- OPTARG="user_val"1'
expect "${getopts_long[2]}" == 'option supplied -- OPTARG="user_val"2'
}

# terminator followed by options
@@ -198,7 +198,7 @@ load ../test_helper
compare '-ouser_val' \
'--optionuser_val' \
'1d'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=user_val'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="user_val"'
expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG="optionuser_val"'

}
@@ -208,6 +208,6 @@ load ../test_helper
'--optionuser_val' \
'1d' \
'2{/^INVALID OPTION or MISSING ARGUMENT/d}'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=user_val'
expect "${bash_getopts[1]}" == 'option supplied -- OPTARG="user_val"'
expect "${getopts_long[1]}" =~ 'getopts_long-verbose: illegal option -- optionuser_val'
}