From 55a69594007cb7315c4d3e3ea994df30c932fc5f Mon Sep 17 00:00:00 2001 From: Dmytro Konstantinov Date: Sat, 14 Dec 2024 09:07:08 +0000 Subject: [PATCH] [GH-15] Fixed double hyphen handling (#28) - Fixed double hyphen handling in short options - Added more tests to cover #15 - Updated documentation - Test suit improvements --- README.md | 17 +++- lib/getopts_long.bash | 7 +- test/bats/github_13.bats | 50 +++++------ test/bats/github_15a.bats | 63 +++++++------- test/bats/github_15b.bats | 82 ++++++++++-------- test/bats/invalid_arguments.bats | 28 +++---- test/bats/no_arguments.bats | 4 +- test/bats/option_supplied.bats | 44 +++++----- test/bats/toggle_triggered.bats | 32 +++---- test/bats/value_supplied.bats | 84 +++++++++---------- ...=> getopts_long-longspec_with_dash-silent} | 0 ...> getopts_long-longspec_with_dash-verbose} | 0 ...ilent => getopts_long-no_shortspec-silent} | 0 ...bose => getopts_long-no_shortspec-verbose} | 0 ...> getopts_long-shortspec_with_dash-silent} | 12 ++- ... getopts_long-shortspec_with_dash-verbose} | 12 ++- test/test_helper.bash | 12 ++- 17 files changed, 243 insertions(+), 204 deletions(-) rename test/bin/{getopts_long-github_15b-silent => getopts_long-longspec_with_dash-silent} (100%) rename test/bin/{getopts_long-github_15b-verbose => getopts_long-longspec_with_dash-verbose} (100%) rename test/bin/{getopts_long-github_13-silent => getopts_long-no_shortspec-silent} (100%) rename test/bin/{getopts_long-github_13-verbose => getopts_long-no_shortspec-verbose} (100%) rename test/bin/{getopts-github_15b-silent => getopts_long-shortspec_with_dash-silent} (71%) rename test/bin/{getopts-github_15b-verbose => getopts_long-shortspec_with_dash-verbose} (70%) diff --git a/README.md b/README.md index 1467501..835679b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,17 @@ This is a pure BASH implementation of `getopts_long` function, which "upgrades" This function is 100% compatible with the built-in `getopts`. It is implemented with no external dependencies, and relies solely on BASH built-in tools to provide all of its functionality. +The implementation supports the following option syntax: + + - Short options are compatible with bash’s built-in getopts: + - `-o` + - `-o value` + - `-ovalue` + - Long options support GNU-like syntax: + - `--option` + - `--option value` + - `--option=value` + Table of Content ---------------- @@ -177,7 +188,11 @@ while getopts ...; do done ``` -Identical to `getopts`, `getopts_long` will parse options and their possible arguments. It will stop parsing on the first non-option argument (a string that doesn't begin with a hyphen (`-`) that isn't an argument for any option in front of it). It will also stop parsing when it sees the `--` (double-hyphen), which means end of options. +Identical to `getopts`, `getopts_long` will parse options and their possible arguments. It will stop parsing on the first non-option argument (a string that doesn't begin with a hyphen (`-`) that isn't an argument for any option in front of it). It will also stop parsing when it sees the `--` (double-hyphen) as a stand-alone argument. + +> IMPORTANT: IMPORTANT: There’s only one exception to the rule that says getopts_long behaves like getopts: when handling `-` within short options! +> +> To support long options, getopts_long provides its own implementation for `-` option, which means the user can no longer define `-` as part of the short option OPTSPEC. ### Internal variables diff --git a/lib/getopts_long.bash b/lib/getopts_long.bash index 60117d2..90a3708 100644 --- a/lib/getopts_long.bash +++ b/lib/getopts_long.bash @@ -2,7 +2,7 @@ getopts_long() { : "${1:?Missing required parameter -- long optspec}" : "${2:?Missing required parameter -- variable name}" - local optspec_short="${1%% *}-:" + local optspec_short="${1%% *}" local optspec_long="${1#* }" local optvar="${2}" @@ -17,6 +17,11 @@ getopts_long() { set -- "${args[@]}" fi + # Sanitize and normalize short optspec + optspec_short="${optspec_short//-:}" + optspec_short="${optspec_short//-}" + [[ "${!OPTIND:0:2}" == "--" ]] && optspec_short+='-:' + builtin getopts -- "${optspec_short}" "${optvar}" "${@}" || return 1 [[ "${!optvar}" == '-' ]] || return 0 diff --git a/test/bats/github_13.bats b/test/bats/github_13.bats index 16a5d3d..673ec34 100644 --- a/test/bats/github_13.bats +++ b/test/bats/github_13.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats load ../test_helper -export GETOPTS_LONG_TEST_BIN='getopts_long-github_13' +export GETOPTS_LONG_TEST_BIN='getopts_long-no_shortspec' @test "${FEATURE}: long option, silent" { compare '-o user_val' \ @@ -16,77 +16,77 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-github_13' compare '-v user_val' \ '--variable=user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } @test "${FEATURE}: long variable, verbose" { compare '-v user_val' \ '--variable=user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } @test "${FEATURE}: toggle followed by long variable, silent" { compare '-t -v user_val' \ '--toggle --variable=user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[5]}" == 'OPTIND: 4' - expect "${getopts_long_lines[5]}" == 'OPTIND: 3' + expect "${bash_getopts[6]}" == 'OPTIND: 4' + expect "${getopts_long[6]}" == 'OPTIND: 3' } @test "${FEATURE}: toggle followed by long variable, verbose" { compare '-t -v user_val' \ '--toggle --variable=user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[5]}" == 'OPTIND: 4' - expect "${getopts_long_lines[5]}" == 'OPTIND: 3' + expect "${bash_getopts[6]}" == 'OPTIND: 4' + expect "${getopts_long[6]}" == 'OPTIND: 3' } @test "${FEATURE}: long variable followed by toggle, silent" { compare '-v user_val -t' \ '--variable=user_val --toggle' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[5]}" == 'OPTIND: 4' - expect "${getopts_long_lines[5]}" == 'OPTIND: 3' + expect "${bash_getopts[6]}" == 'OPTIND: 4' + expect "${getopts_long[6]}" == 'OPTIND: 3' } @test "${FEATURE}: long variable followed by toggle, verbose" { compare '-v user_val -t' \ '--variable=user_val --toggle' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[5]}" == 'OPTIND: 4' - expect "${getopts_long_lines[5]}" == 'OPTIND: 3' + expect "${bash_getopts[6]}" == 'OPTIND: 4' + expect "${getopts_long[6]}" == 'OPTIND: 3' } @test "${FEATURE}: terminator followed by long variable, silent" { compare '-t -- -v user_val' \ '--toggle -- --variable=user_val' \ '/^\$@: /d' - expect "${bash_getopts_lines[5]}" == '$@: -v user_val' - expect "${getopts_long_lines[5]}" == '$@: --variable=user_val' + expect "${bash_getopts[6]}" == '$@: -v user_val' + expect "${getopts_long[6]}" == '$@: --variable=user_val' } @test "${FEATURE}: terminator followed by long variable, verbose" { compare '-t -- -v user_val' \ '--toggle -- --variable=user_val' \ '/^\$@: /d' - expect "${bash_getopts_lines[5]}" == '$@: -v user_val' - expect "${getopts_long_lines[5]}" == '$@: --variable=user_val' + expect "${bash_getopts[6]}" == '$@: -v user_val' + expect "${getopts_long[6]}" == '$@: --variable=user_val' } @test "${FEATURE}: long variable followed by terminator, silent" { compare '-v user_val -- -t' \ '--variable=user_val -- --toggle' \ '/^(OPTIND|\$@): /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 4' - expect "${getopts_long_lines[4]}" == 'OPTIND: 3' - expect "${bash_getopts_lines[5]}" == '$@: -t' - expect "${getopts_long_lines[5]}" == '$@: --toggle' + expect "${bash_getopts[5]}" == 'OPTIND: 4' + expect "${getopts_long[5]}" == 'OPTIND: 3' + expect "${bash_getopts[6]}" == '$@: -t' + expect "${getopts_long[6]}" == '$@: --toggle' } @test "${FEATURE}: long variable followed by terminator, verbose" { compare '-v user_val -- -t' \ '--variable=user_val -- --toggle' \ '/^(OPTIND|\$@): /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 4' - expect "${getopts_long_lines[4]}" == 'OPTIND: 3' - expect "${bash_getopts_lines[5]}" == '$@: -t' - expect "${getopts_long_lines[5]}" == '$@: --toggle' + expect "${bash_getopts[5]}" == 'OPTIND: 4' + expect "${getopts_long[5]}" == 'OPTIND: 3' + expect "${bash_getopts[6]}" == '$@: -t' + expect "${getopts_long[6]}" == '$@: --toggle' } diff --git a/test/bats/github_15a.bats b/test/bats/github_15a.bats index 3bf25b7..f422b15 100644 --- a/test/bats/github_15a.bats +++ b/test/bats/github_15a.bats @@ -2,28 +2,25 @@ load ../test_helper -# Neither bash getopts nor getopts_long OPTSPEC includes [-], but -# getopts_long always appends [-:] to the end of the short OPTSPEC. +# Neither bash getopts nor getopts_long OPTSPEC includes [-] + +@test "${FEATURE}: short toggle, single, silent" { + compare '-t- -t user_arg' \ + '-t- -t user_arg' +} +@test "${FEATURE}: short toggle, single, verbose" { + compare '-t- -t user_arg' \ + '-t- -t user_arg' \ + 's/getopts[[:alpha:]_-]*/GETOPTS-NORMALISED/' +} -# Standard getopts should see: -# -t - a toggle -# -- - an invalid option -# -- - an invalid option -# -t - a toggle -# Getopts_long should see: -# -t - a toggle -# --- - an invalid option -# -t - a toggle @test "${FEATURE}: short toggle, silent" { compare '-t-- -t user_arg' \ - '-t-- -t user_arg' \ - '3{/^INVALID OPTION/d}' + '-t-- -t user_arg' } @test "${FEATURE}: short toggle, verbose" { compare '-t-- -t user_arg' \ '-t-- -t user_arg' \ - '4{/getopts-verbose: illegal option -- -$/d}' \ - '5{/^INVALID OPTION or MISSING ARGUMENT -- OPTARG is unset$/d}' \ 's/getopts[[:alpha:]_-]*/GETOPTS-NORMALISED/' } @@ -40,12 +37,12 @@ load ../test_helper '--toggle-- --toggle user_arg' \ '1{/^toggle triggered/d}' \ '/^INVALID OPTION/d' - expect "${bash_getopts_lines[0]}" == 'toggle triggered -- OPTARG is unset' - expect "${bash_getopts_lines[1]}" == 'INVALID OPTION -- OPTARG=-' - expect "${bash_getopts_lines[2]}" == 'INVALID OPTION -- OPTARG=-' - expect "${bash_getopts_lines[3]}" == 'toggle triggered -- OPTARG is unset' - expect "${getopts_long_lines[0]}" == 'INVALID OPTION -- OPTARG=toggle--' - expect "${getopts_long_lines[1]}" == 'toggle triggered -- OPTARG is unset' + expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG is unset' + expect "${bash_getopts[2]}" == 'INVALID OPTION -- OPTARG=-' + expect "${bash_getopts[3]}" == 'INVALID OPTION -- OPTARG=-' + expect "${bash_getopts[4]}" == 'toggle triggered -- OPTARG is unset' + expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=toggle--' + expect "${getopts_long[2]}" == 'toggle triggered -- OPTARG is unset' } @test "${FEATURE}: long toggle, verbose" { compare '-t-- -t user_arg' \ @@ -55,16 +52,16 @@ load ../test_helper '5{/^INVALID OPTION or MISSING ARGUMENT/d}' \ 's/getopts[[:alpha:]_-]*/GETOPTS-NORMALISED/' \ 's/(illegal option --) (-|toggle--)/\1 TOGGLE-NORMALISED/' - expect "${bash_getopts_lines[0]}" == 'toggle triggered -- OPTARG is unset' - expect "${bash_getopts_lines[1]}" =~ 'getopts-verbose: illegal option -- -$' - expect "${bash_getopts_lines[3]}" =~ 'getopts-verbose: illegal option -- -$' - expect "${bash_getopts_lines[5]}" == 'toggle triggered -- OPTARG is unset' - expect "${getopts_long_lines[0]}" =~ 'getopts_long-verbose: illegal option -- toggle--$' - expect "${getopts_long_lines[2]}" == 'toggle triggered -- OPTARG is unset' + expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG is unset' + expect "${bash_getopts[2]}" =~ 'getopts-verbose: illegal option -- -$' + expect "${bash_getopts[4]}" =~ 'getopts-verbose: illegal option -- -$' + expect "${bash_getopts[6]}" == 'toggle triggered -- OPTARG is unset' + expect "${getopts_long[1]}" =~ 'getopts_long-verbose: illegal option -- toggle--$' + expect "${getopts_long[3]}" == 'toggle triggered -- OPTARG is unset' } # Both implementations should see: -# -o -- - an option (-o) with a value (--) +# -o -- - an option with a value # -t - a toggle @test "${FEATURE}: short option, silent" { compare '-o-- -t user_arg' \ @@ -76,7 +73,7 @@ load ../test_helper } # Standard getopts should see: -# -o -- - an option with a value (--) +# -o -- - an option with a value # -t - a toggle # Getopts_long should see: # --option-- - an invalid option @@ -85,14 +82,14 @@ load ../test_helper compare '-o-- -t user_arg' \ '--option-- --toggle user_arg' \ '1{/(option supplied|INVALID OPTION)/d}' - expect "${bash_getopts_lines[0]}" == 'option supplied -- OPTARG=--' - expect "${getopts_long_lines[0]}" == 'INVALID OPTION -- OPTARG=option--' + 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_lines[0]}" == 'option supplied -- OPTARG=--' - expect "${getopts_long_lines[0]}" =~ "getopts_long-verbose: illegal option -- option--$" + expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--' + expect "${getopts_long[1]}" =~ "getopts_long-verbose: illegal option -- option--$" } diff --git a/test/bats/github_15b.bats b/test/bats/github_15b.bats index ffa8d66..a38e799 100644 --- a/test/bats/github_15b.bats +++ b/test/bats/github_15b.bats @@ -2,53 +2,69 @@ load ../test_helper -# Both bash getopts and getopts_long OPTSPEC includes [-] -export GETOPTS_TEST_BIN='getopts-github_15b' -export GETOPTS_LONG_TEST_BIN='getopts_long-github_15b' +# Bash getopts includes [-] in OPTSPEC, while getopts_long doesn't +# This test should be identical to test/bats/github_15a.bats, since +# getopts_long filters out [-] from short optspec. +export GETOPTS_LONG_TEST_BIN='getopts_long-shortspec_with_dash' + +@test "${FEATURE}: short toggle, single, silent" { + compare '-t- -t user_arg' \ + '-t- -t user_arg' +} +@test "${FEATURE}: short toggle, single, verbose" { + compare '-t- -t user_arg' \ + '-t- -t user_arg' \ + 's/getopts[[:alpha:]_-]*/GETOPTS-NORMALISED/' +} -# Bash getopts should see four toggles: -t -- -- -t -# Getopts_long should see three toggles: -t --- -t @test "${FEATURE}: short toggle, silent" { compare '-t-- -t user_arg' \ - '-t-- -t user_arg' \ - '4{/^toggle triggered/d}' + '-t-- -t user_arg' } @test "${FEATURE}: short toggle, verbose" { compare '-t-- -t user_arg' \ '-t-- -t user_arg' \ - '4{/^toggle triggered/d}' + 's/getopts[[:alpha:]_-]*/GETOPTS-NORMALISED/' } -# Bash getopts should see four toggles: -t -- -- -t -# Getopts_long should see an invalid option (--toggle--) and a toggle +# Standard getopts should see: +# -t - a toggle +# -- - an invalid option +# -- - an invalid option +# -t - a toggle +# Getopts_long should see: +# --toggle-- - an invalid option +# --toggle - a toggle @test "${FEATURE}: long toggle, silent" { compare '-t-- -t user_arg' \ '--toggle-- --toggle user_arg' \ - '/^toggle triggered/d' \ - '/^INVALID OPTION --/d' - expect "${bash_getopts_lines[0]}" == 'toggle triggered -- OPTARG is unset' - expect "${bash_getopts_lines[1]}" == 'toggle triggered -- OPTARG is unset' - expect "${bash_getopts_lines[2]}" == 'toggle triggered -- OPTARG is unset' - expect "${bash_getopts_lines[3]}" == 'toggle triggered -- OPTARG is unset' - expect "${getopts_long_lines[0]}" == 'INVALID OPTION -- OPTARG=toggle--' - expect "${getopts_long_lines[1]}" == 'toggle triggered -- OPTARG is unset' + '1{/^toggle triggered/d}' \ + '/^INVALID OPTION/d' + expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG is unset' + expect "${bash_getopts[2]}" == 'INVALID OPTION -- OPTARG=-' + expect "${bash_getopts[3]}" == 'INVALID OPTION -- OPTARG=-' + expect "${bash_getopts[4]}" == 'toggle triggered -- OPTARG is unset' + expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=toggle--' + expect "${getopts_long[2]}" == 'toggle triggered -- OPTARG is unset' } @test "${FEATURE}: long toggle, verbose" { compare '-t-- -t user_arg' \ '--toggle-- --toggle user_arg' \ - '/^toggle triggered/d' \ - '/illegal option -- toggle--$/d' \ - '/^INVALID OPTION or MISSING ARGUMENT --/d' - expect "${bash_getopts_lines[0]}" == 'toggle triggered -- OPTARG is unset' - expect "${bash_getopts_lines[1]}" == 'toggle triggered -- OPTARG is unset' - expect "${bash_getopts_lines[2]}" == 'toggle triggered -- OPTARG is unset' - expect "${bash_getopts_lines[3]}" == 'toggle triggered -- OPTARG is unset' - expect "${getopts_long_lines[0]}" =~ 'getopts_long-\w+-verbose: illegal option -- toggle--' - expect "${getopts_long_lines[2]}" == 'toggle triggered -- OPTARG is unset' + '1{/^toggle triggered/d}' \ + '4{/getopts-verbose: illegal option -- -$/d}' \ + '5{/^INVALID OPTION or MISSING ARGUMENT/d}' \ + 's/getopts[[:alpha:]_-]*/GETOPTS-NORMALISED/' \ + 's/(illegal option --) (-|toggle--)/\1 TOGGLE-NORMALISED/' + expect "${bash_getopts[1]}" == 'toggle triggered -- OPTARG is unset' + expect "${bash_getopts[2]}" =~ 'getopts-verbose: illegal option -- -$' + expect "${bash_getopts[4]}" =~ 'getopts-verbose: illegal option -- -$' + expect "${bash_getopts[6]}" == 'toggle triggered -- OPTARG is unset' + expect "${getopts_long[1]}" =~ 'getopts_long-\w+-verbose: illegal option -- toggle--$' + expect "${getopts_long[3]}" == 'toggle triggered -- OPTARG is unset' } # Both implementations should see: -# -o -- - an option (-o) with a value (--) +# -o -- - an option with a value # -t - a toggle @test "${FEATURE}: short option, silent" { compare '-o-- -t user_arg' \ @@ -60,7 +76,7 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-github_15b' } # Standard getopts should see: -# -o -- - an option with a value (--) +# -o -- - an option with a value # -t - a toggle # Getopts_long should see: # --option-- - an invalid option @@ -69,14 +85,14 @@ export GETOPTS_LONG_TEST_BIN='getopts_long-github_15b' compare '-o-- -t user_arg' \ '--option-- --toggle user_arg' \ '1{/(option supplied|INVALID OPTION)/d}' - expect "${bash_getopts_lines[0]}" == 'option supplied -- OPTARG=--' - expect "${getopts_long_lines[0]}" == 'INVALID OPTION -- OPTARG=option--' + 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_lines[0]}" == 'option supplied -- OPTARG=--' - expect "${getopts_long_lines[0]}" =~ 'getopts_long-\w+-verbose: illegal option -- option--$' + expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=--' + expect "${getopts_long[1]}" =~ "getopts_long-\w+-verbose: illegal option -- option--$" } diff --git a/test/bats/invalid_arguments.bats b/test/bats/invalid_arguments.bats index 492ecb3..7b5f15e 100644 --- a/test/bats/invalid_arguments.bats +++ b/test/bats/invalid_arguments.bats @@ -16,8 +16,8 @@ load ../test_helper compare '-i' \ '--invalid' \ '/^INVALID OPTION -- /d' - expect "${bash_getopts_lines[0]}" == 'INVALID OPTION -- OPTARG=i' - expect "${getopts_long_lines[0]}" == 'INVALID OPTION -- OPTARG=invalid' + expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG=i' + expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=invalid' } @test "${FEATURE}: long option, verbose" { compare '-i' \ @@ -41,8 +41,8 @@ load ../test_helper compare '-i user_arg' \ '--invalid user_arg' \ '/^INVALID OPTION -- /d' - expect "${bash_getopts_lines[0]}" == 'INVALID OPTION -- OPTARG=i' - expect "${getopts_long_lines[0]}" == 'INVALID OPTION -- OPTARG=invalid' + expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG=i' + expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=invalid' } @test "${FEATURE}: long option, extra arguments, verbose" { compare '-i user_arg' \ @@ -55,28 +55,28 @@ load ../test_helper @test "${FEATURE}: short option, terminator, extra arguments, silent" { compare '-i -- user_arg' \ '-i -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: short option, terminator, extra arguments, verbose" { compare '-i -- user_arg' \ '-i -- user_arg' \ 's/getopts_long-verbose/getopts-verbose/g' - expect "${getopts_long_lines[6]}" == '$@: user_arg' + expect "${getopts_long[7]}" == '$@: user_arg' } @test "${FEATURE}: long option, terminator, extra arguments, silent" { compare '-i -- user_arg' \ '--invalid -- user_arg' \ '/^INVALID OPTION -- /d' - expect "${bash_getopts_lines[0]}" == 'INVALID OPTION -- OPTARG=i' - expect "${getopts_long_lines[0]}" == 'INVALID OPTION -- OPTARG=invalid' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${bash_getopts[1]}" == 'INVALID OPTION -- OPTARG=i' + expect "${getopts_long[1]}" == 'INVALID OPTION -- OPTARG=invalid' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: long option, terminator, extra arguments, verbose" { compare '-i -- user_arg' \ '--invalid -- user_arg' \ 's/getopts_long-verbose: (.*) invalid$/getopts-verbose: \1 i/g' - expect "${getopts_long_lines[6]}" == '$@: user_arg' + expect "${getopts_long[7]}" == '$@: user_arg' } # terminator followed by options @@ -84,24 +84,24 @@ load ../test_helper @test "${FEATURE}: terminator, short option, extra arguments, silent" { compare '-- -i user_arg' \ '-- -i user_arg' - expect "${getopts_long_lines[4]}" == '$@: -i user_arg' + expect "${getopts_long[5]}" == '$@: -i user_arg' } @test "${FEATURE}: terminator, short option, extra arguments, verbose" { compare '-- -i user_arg' \ '-- -i user_arg' \ 's/getopts_long-verbose/getopts-verbose/g' - expect "${getopts_long_lines[4]}" == '$@: -i user_arg' + expect "${getopts_long[5]}" == '$@: -i user_arg' } @test "${FEATURE}: terminator, long option, extra arguments, silent" { compare '-- -i user_arg' \ '-- --invalid user_arg' \ '/^\$@: /d' - expect "${getopts_long_lines[4]}" == '$@: --invalid user_arg' + expect "${getopts_long[5]}" == '$@: --invalid user_arg' } @test "${FEATURE}: terminator, long option, extra arguments, verbose" { compare '-- -i user_arg' \ '-- --invalid user_arg' \ '/^\$@: /d' - expect "${getopts_long_lines[4]}" == '$@: --invalid user_arg' + expect "${getopts_long[5]}" == '$@: --invalid user_arg' } diff --git a/test/bats/no_arguments.bats b/test/bats/no_arguments.bats index 95c29b4..5dcdd9f 100644 --- a/test/bats/no_arguments.bats +++ b/test/bats/no_arguments.bats @@ -21,10 +21,10 @@ load ../test_helper @test "${FEATURE}: terminator, extra arguments, silent" { compare '-- user_arg' \ '-- user_arg' - expect "${getopts_long_lines[4]}" == '$@: user_arg' + expect "${getopts_long[5]}" == '$@: user_arg' } @test "${FEATURE}: terminator, extra arguments, verbose" { compare '-- user_arg' \ '-- user_arg' - expect "${getopts_long_lines[4]}" == '$@: user_arg' + expect "${getopts_long[5]}" == '$@: user_arg' } diff --git a/test/bats/option_supplied.bats b/test/bats/option_supplied.bats index 929d169..d83c864 100644 --- a/test/bats/option_supplied.bats +++ b/test/bats/option_supplied.bats @@ -45,23 +45,23 @@ load ../test_helper @test "${FEATURE}: short option, terminator, extra arguments, silent" { compare '-o user_val -- user_arg' \ '-o user_val -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: short option, terminator, extra arguments, verbose" { compare '-o user_val -- user_arg' \ '-o user_val -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: long option, terminator, extra arguments, silent" { compare '-o user_val -- user_arg' \ '--option user_val -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: long option, terminator, extra arguments, verbose" { compare '-o user_val -- user_arg' \ '--option user_val -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } # multiple same arguments @@ -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_lines[0]}" == 'option supplied -- OPTARG=user_val1' - expect "${getopts_long_lines[1]}" == 'option supplied -- OPTARG=user_val2' + expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1' + expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2' } @test "${FEATURE}: short option, multiple same arguments, verbose" { compare '-o user_val1 -o user_val2' \ '-o user_val1 -o user_val2' - expect "${getopts_long_lines[0]}" == 'option supplied -- OPTARG=user_val1' - expect "${getopts_long_lines[1]}" == 'option supplied -- OPTARG=user_val2' + expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1' + expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2' } @test "${FEATURE}: long option, multiple same arguments, silent" { compare '-o user_val1 -o user_val2' \ '--option user_val1 --option user_val2' - expect "${getopts_long_lines[0]}" == 'option supplied -- OPTARG=user_val1' - expect "${getopts_long_lines[1]}" == 'option supplied -- OPTARG=user_val2' + expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1' + expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2' } @test "${FEATURE}: long option, multiple same arguments, verbose" { compare '-o user_val1 -o user_val2' \ '--option user_val1 --option user_val2' - expect "${getopts_long_lines[0]}" == 'option supplied -- OPTARG=user_val1' - expect "${getopts_long_lines[1]}" == 'option supplied -- OPTARG=user_val2' + expect "${getopts_long[1]}" == 'option supplied -- OPTARG=user_val1' + expect "${getopts_long[2]}" == 'option supplied -- OPTARG=user_val2' } # terminator followed by options @@ -97,25 +97,25 @@ load ../test_helper @test "${FEATURE}: terminator, short option, extra arguments, silent" { compare '-- -o user_val user_arg' \ '-- -o user_val user_arg' - expect "${getopts_long_lines[4]}" == '$@: -o user_val user_arg' + expect "${getopts_long[5]}" == '$@: -o user_val user_arg' } @test "${FEATURE}: terminator, short option, extra arguments, verbose" { compare '-- -o user_val user_arg' \ '-- -o user_val user_arg' - expect "${getopts_long_lines[4]}" == '$@: -o user_val user_arg' + expect "${getopts_long[5]}" == '$@: -o user_val user_arg' } @test "${FEATURE}: terminator, long option, extra arguments, silent" { compare '-- -o user_val user_arg' \ '-- --option user_val user_arg' \ '/^\$@: /d' - expect "${getopts_long_lines[4]}" == '$@: --option user_val user_arg' + expect "${getopts_long[5]}" == '$@: --option user_val user_arg' } @test "${FEATURE}: terminator, long option, extra arguments, verbose" { compare '-- -o user_val user_arg' \ '-- --option user_val user_arg' \ '/^\$@: /d' - expect "${getopts_long_lines[4]}" == '$@: --option user_val user_arg' + expect "${getopts_long[5]}" == '$@: --option user_val user_arg' } # option without an argument @@ -134,8 +134,8 @@ load ../test_helper compare '-o' \ '--option' \ '/^MISSING ARGUMENT -- /d' - expect "${bash_getopts_lines[0]}" == 'MISSING ARGUMENT -- OPTARG=o' - expect "${getopts_long_lines[0]}" == 'MISSING ARGUMENT -- OPTARG=option' + expect "${bash_getopts[1]}" == 'MISSING ARGUMENT -- OPTARG=o' + expect "${getopts_long[1]}" == 'MISSING ARGUMENT -- OPTARG=option' } @test "${FEATURE}: long option, missing value, verbose" { compare '-o' \ @@ -198,8 +198,8 @@ load ../test_helper compare '-ouser_val' \ '--optionuser_val' \ '1d' - expect "${bash_getopts_lines[0]}" == 'option supplied -- OPTARG=user_val' - expect "${getopts_long_lines[0]}" == 'INVALID OPTION -- OPTARG=optionuser_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_lines[0]}" == 'option supplied -- OPTARG=user_val' - expect "${getopts_long_lines[0]}" =~ 'getopts_long-verbose: illegal option -- optionuser_val' + expect "${bash_getopts[1]}" == 'option supplied -- OPTARG=user_val' + expect "${getopts_long[1]}" =~ 'getopts_long-verbose: illegal option -- optionuser_val' } diff --git a/test/bats/toggle_triggered.bats b/test/bats/toggle_triggered.bats index a98e287..a89d543 100644 --- a/test/bats/toggle_triggered.bats +++ b/test/bats/toggle_triggered.bats @@ -45,23 +45,23 @@ load ../test_helper @test "${FEATURE}: short option, terminator, extra arguments, silent" { compare '-t -- user_arg' \ '-t -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: short option, terminator, extra arguments, verbose" { compare '-t -- user_arg' \ '-t -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: long option, terminator, extra arguments, silent" { compare '-t -- user_arg' \ '--toggle -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: long option, terminator, extra arguments, verbose" { compare '-t -- user_arg' \ '--toggle -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } # multiple same arguments @@ -69,27 +69,27 @@ load ../test_helper @test "${FEATURE}: short option, multiple same arguments, silent" { compare '-t -t' \ '-t -t' - expect "${getopts_long_lines[0]}" == "${getopts_long_lines[1]}" - expect "${getopts_long_lines[0]}" == 'toggle triggered -- OPTARG is unset' + expect "${getopts_long[1]}" == "${getopts_long[2]}" + expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG is unset' } @test "${FEATURE}: short option, multiple same arguments, verbose" { compare '-t -t' \ '-t -t' - expect "${getopts_long_lines[0]}" == "${getopts_long_lines[1]}" - expect "${getopts_long_lines[0]}" == 'toggle triggered -- OPTARG is unset' + expect "${getopts_long[1]}" == "${getopts_long[2]}" + expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG is unset' } @test "${FEATURE}: long option, multiple same arguments, silent" { compare '-t -t' \ '--toggle --toggle' - expect "${getopts_long_lines[0]}" == "${getopts_long_lines[1]}" - expect "${getopts_long_lines[0]}" == 'toggle triggered -- OPTARG is unset' + expect "${getopts_long[1]}" == "${getopts_long[2]}" + expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG is unset' } @test "${FEATURE}: long option, multiple same arguments, verbose" { compare '-t -t' \ '--toggle --toggle' - expect "${getopts_long_lines[0]}" == "${getopts_long_lines[1]}" - expect "${getopts_long_lines[0]}" == 'toggle triggered -- OPTARG is unset' + expect "${getopts_long[1]}" == "${getopts_long[2]}" + expect "${getopts_long[1]}" == 'toggle triggered -- OPTARG is unset' } # terminator followed by options @@ -97,23 +97,23 @@ load ../test_helper @test "${FEATURE}: terminator, short option, extra arguments, silent" { compare '-- -t user_arg' \ '-- -t user_arg' - expect "${getopts_long_lines[4]}" == '$@: -t user_arg' + expect "${getopts_long[5]}" == '$@: -t user_arg' } @test "${FEATURE}: terminator, short option, extra arguments, verbose" { compare '-- -t user_arg' \ '-- -t user_arg' - expect "${getopts_long_lines[4]}" == '$@: -t user_arg' + expect "${getopts_long[5]}" == '$@: -t user_arg' } @test "${FEATURE}: terminator, long option, extra arguments, silent" { compare '-- -t user_arg' \ '-- --toggle user_arg' \ '/^\$@: /d' - expect "${getopts_long_lines[4]}" == '$@: --toggle user_arg' + expect "${getopts_long[5]}" == '$@: --toggle user_arg' } @test "${FEATURE}: terminator, long option, extra arguments, verbose" { compare '-- -t user_arg' \ '-- --toggle user_arg' \ '/^\$@: /d' - expect "${getopts_long_lines[4]}" == '$@: --toggle user_arg' + expect "${getopts_long[5]}" == '$@: --toggle user_arg' } diff --git a/test/bats/value_supplied.bats b/test/bats/value_supplied.bats index 2ee34d4..a0b8476 100644 --- a/test/bats/value_supplied.bats +++ b/test/bats/value_supplied.bats @@ -15,15 +15,15 @@ load ../test_helper compare '-v user_val' \ '--variable=user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } @test "${FEATURE}: long option, verbose" { compare '-v user_val' \ '--variable=user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } # extra arguments @@ -41,15 +41,15 @@ load ../test_helper compare '-v user_val user_arg' \ '--variable=user_val user_arg' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } @test "${FEATURE}: long option, extra arguments, verbose" { compare '-v user_val user_arg' \ '--variable=user_val user_arg' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } # extra arguments with terminator @@ -57,29 +57,29 @@ load ../test_helper @test "${FEATURE}: short option, terminator, extra arguments, silent" { compare '-v user_val -- user_arg' \ '-v user_val -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: short option, terminator, extra arguments, verbose" { compare '-v user_val -- user_arg' \ '-v user_val -- user_arg' - expect "${getopts_long_lines[5]}" == '$@: user_arg' + expect "${getopts_long[6]}" == '$@: user_arg' } @test "${FEATURE}: long option, terminator, extra arguments, silent" { compare '-v user_val -- user_arg' \ '--variable=user_val -- user_arg' \ '/^OPTIND: /d' - expect "${getopts_long_lines[5]}" == '$@: user_arg' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 4' - expect "${getopts_long_lines[4]}" == 'OPTIND: 3' + expect "${getopts_long[6]}" == '$@: user_arg' + expect "${bash_getopts[5]}" == 'OPTIND: 4' + expect "${getopts_long[5]}" == 'OPTIND: 3' } @test "${FEATURE}: long option, terminator, extra arguments, verbose" { compare '-v user_val -- user_arg' \ '--variable=user_val -- user_arg' \ '/^OPTIND: /d' - expect "${getopts_long_lines[5]}" == '$@: user_arg' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 4' - expect "${getopts_long_lines[4]}" == 'OPTIND: 3' + expect "${getopts_long[6]}" == '$@: user_arg' + expect "${bash_getopts[5]}" == 'OPTIND: 4' + expect "${getopts_long[5]}" == 'OPTIND: 3' } # multiple same arguments @@ -87,33 +87,33 @@ load ../test_helper @test "${FEATURE}: short option, multiple same arguments, silent" { compare '-v user_val1 -v user_val2' \ '-v user_val1 -v user_val2' - expect "${getopts_long_lines[0]}" == 'value supplied -- OPTARG=user_val1' - expect "${getopts_long_lines[1]}" == 'value supplied -- OPTARG=user_val2' + expect "${getopts_long[1]}" == 'value supplied -- OPTARG=user_val1' + expect "${getopts_long[2]}" == 'value supplied -- OPTARG=user_val2' } @test "${FEATURE}: short option, multiple same arguments, verbose" { compare '-v user_val1 -v user_val2' \ '-v user_val1 -v user_val2' - expect "${getopts_long_lines[0]}" == 'value supplied -- OPTARG=user_val1' - expect "${getopts_long_lines[1]}" == 'value supplied -- OPTARG=user_val2' + expect "${getopts_long[1]}" == 'value supplied -- OPTARG=user_val1' + expect "${getopts_long[2]}" == 'value supplied -- OPTARG=user_val2' } @test "${FEATURE}: long option, multiple same arguments, silent" { compare '-v user_val1 -v user_val2' \ '--variable=user_val1 --variable=user_val2' \ '/^OPTIND: /d' - expect "${getopts_long_lines[0]}" == 'value supplied -- OPTARG=user_val1' - expect "${getopts_long_lines[1]}" == 'value supplied -- OPTARG=user_val2' - expect "${bash_getopts_lines[5]}" == 'OPTIND: 5' - expect "${getopts_long_lines[5]}" == 'OPTIND: 3' + expect "${getopts_long[1]}" == 'value supplied -- OPTARG=user_val1' + expect "${getopts_long[2]}" == 'value supplied -- OPTARG=user_val2' + expect "${bash_getopts[6]}" == 'OPTIND: 5' + expect "${getopts_long[6]}" == 'OPTIND: 3' } @test "${FEATURE}: long option, multiple same arguments, verbose" { compare '-v user_val1 -v user_val2' \ '--variable=user_val1 --variable=user_val2' \ '/^OPTIND: /d' - expect "${getopts_long_lines[0]}" == 'value supplied -- OPTARG=user_val1' - expect "${getopts_long_lines[1]}" == 'value supplied -- OPTARG=user_val2' - expect "${bash_getopts_lines[5]}" == 'OPTIND: 5' - expect "${getopts_long_lines[5]}" == 'OPTIND: 3' + expect "${getopts_long[1]}" == 'value supplied -- OPTARG=user_val1' + expect "${getopts_long[2]}" == 'value supplied -- OPTARG=user_val2' + expect "${bash_getopts[6]}" == 'OPTIND: 5' + expect "${getopts_long[6]}" == 'OPTIND: 3' } # terminator followed by options @@ -121,25 +121,25 @@ load ../test_helper @test "${FEATURE}: terminator, short option, extra arguments, silent" { compare '-- -v user_val user_arg' \ '-- -v user_val user_arg' - expect "${getopts_long_lines[4]}" == '$@: -v user_val user_arg' + expect "${getopts_long[5]}" == '$@: -v user_val user_arg' } @test "${FEATURE}: terminator, short option, extra arguments, verbose" { compare '-- -v user_val user_arg' \ '-- -v user_val user_arg' - expect "${getopts_long_lines[4]}" == '$@: -v user_val user_arg' + expect "${getopts_long[5]}" == '$@: -v user_val user_arg' } @test "${FEATURE}: terminator, long option, extra arguments, silent" { compare '-- -v user_val user_arg' \ '-- --variable=user_val user_arg' \ '/^\$@: /d' - expect "${getopts_long_lines[4]}" == '$@: --variable=user_val user_arg' + expect "${getopts_long[5]}" == '$@: --variable=user_val user_arg' } @test "${FEATURE}: terminator, long option, extra arguments, verbose" { compare '-- -v user_val user_arg' \ '-- --variable=user_val user_arg' \ '/^\$@: /d' - expect "${getopts_long_lines[4]}" == '$@: --variable=user_val user_arg' + expect "${getopts_long[5]}" == '$@: --variable=user_val user_arg' } # variable without an argument @@ -158,8 +158,8 @@ load ../test_helper compare '-v' \ '--variable' \ '/^MISSING ARGUMENT -- /d' - expect "${bash_getopts_lines[0]}" == 'MISSING ARGUMENT -- OPTARG=v' - expect "${getopts_long_lines[0]}" == 'MISSING ARGUMENT -- OPTARG=variable' + expect "${bash_getopts[1]}" == 'MISSING ARGUMENT -- OPTARG=v' + expect "${getopts_long[1]}" == 'MISSING ARGUMENT -- OPTARG=variable' } @test "${FEATURE}: long option, missing value, verbose" { compare '-v' \ @@ -182,15 +182,15 @@ load ../test_helper compare '-v -user_val' \ '--variable=-user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } @test "${FEATURE}: long option, value starts with -, verbose" { compare '-v -user_val' \ '--variable=-user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } # option with a value that start with an equals sign @@ -208,13 +208,13 @@ load ../test_helper compare '-v =user_val' \ '--variable==user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } @test "${FEATURE}: long option, value starts with =, verbose" { compare '-v =user_val' \ '--variable==user_val' \ '/^OPTIND: /d' - expect "${bash_getopts_lines[4]}" == 'OPTIND: 3' - expect "${getopts_long_lines[4]}" == 'OPTIND: 2' + expect "${bash_getopts[5]}" == 'OPTIND: 3' + expect "${getopts_long[5]}" == 'OPTIND: 2' } diff --git a/test/bin/getopts_long-github_15b-silent b/test/bin/getopts_long-longspec_with_dash-silent similarity index 100% rename from test/bin/getopts_long-github_15b-silent rename to test/bin/getopts_long-longspec_with_dash-silent diff --git a/test/bin/getopts_long-github_15b-verbose b/test/bin/getopts_long-longspec_with_dash-verbose similarity index 100% rename from test/bin/getopts_long-github_15b-verbose rename to test/bin/getopts_long-longspec_with_dash-verbose diff --git a/test/bin/getopts_long-github_13-silent b/test/bin/getopts_long-no_shortspec-silent similarity index 100% rename from test/bin/getopts_long-github_13-silent rename to test/bin/getopts_long-no_shortspec-silent diff --git a/test/bin/getopts_long-github_13-verbose b/test/bin/getopts_long-no_shortspec-verbose similarity index 100% rename from test/bin/getopts_long-github_13-verbose rename to test/bin/getopts_long-no_shortspec-verbose diff --git a/test/bin/getopts-github_15b-silent b/test/bin/getopts_long-shortspec_with_dash-silent similarity index 71% rename from test/bin/getopts-github_15b-silent rename to test/bin/getopts_long-shortspec_with_dash-silent index f38624f..4ae434e 100755 --- a/test/bin/getopts-github_15b-silent +++ b/test/bin/getopts_long-shortspec_with_dash-silent @@ -1,14 +1,18 @@ #!/usr/bin/env bash -while getopts ":to:v:-" OPTKEY; do +TOPDIR="$(cd "$(dirname "${0}")"/../.. && pwd)" +# shellcheck disable=SC1090 +source "${TOPDIR}/lib/getopts_long.bash" + +while getopts_long ':to:v:- toggle option: variable:' OPTKEY; do case ${OPTKEY} in - '-'|'t') + '-'|'t'|'toggle') printf 'toggle triggered' ;; - 'o') + 'o'|'option') printf 'option supplied' ;; - 'v') + 'v'|'variable') printf 'value supplied' ;; '?') diff --git a/test/bin/getopts-github_15b-verbose b/test/bin/getopts_long-shortspec_with_dash-verbose similarity index 70% rename from test/bin/getopts-github_15b-verbose rename to test/bin/getopts_long-shortspec_with_dash-verbose index 683e8a6..5ed6d39 100755 --- a/test/bin/getopts-github_15b-verbose +++ b/test/bin/getopts_long-shortspec_with_dash-verbose @@ -1,14 +1,18 @@ #!/usr/bin/env bash -while getopts "to:v:-" OPTKEY; do +TOPDIR="$(cd "$(dirname "${0}")"/../.. && pwd)" +# shellcheck disable=SC1090 +source "${TOPDIR}/lib/getopts_long.bash" + +while getopts_long 'to:v:- toggle option: variable:' OPTKEY; do case ${OPTKEY} in - '-'|'t') + '-'|'t'|'toggle') printf 'toggle triggered' ;; - 'o') + 'o'|'option') printf 'option supplied' ;; - 'v') + 'v'|'variable') printf 'value supplied' ;; '?') diff --git a/test/test_helper.bash b/test/test_helper.bash index dee4e31..0190178 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -45,15 +45,13 @@ compare() { run "${GETOPTS_TEST_BIN:-getopts}-${BATS_TEST_DESCRIPTION##* }" ${1} bash_getopts_output="${output}" - bash_getopts_lines=( "${lines[@]}" ) - bash_getopts_status=${status} - export bash_getopts_output bash_getopts_lines bash_getopts_status + bash_getopts=( "${status}" "${lines[@]}" ) + export bash_getopts run "${GETOPTS_LONG_TEST_BIN:-getopts_long}-${BATS_TEST_DESCRIPTION##* }" ${2} getopts_long_output="${output}" - getopts_long_lines=( "${lines[@]}" ) - getopts_long_status=${status} - export getopts_long_output getopts_long_lines getopts_long_status + getopts_long=( "${status}" "${lines[@]}" ) + export getopts_long if [[ -n "${3+SET}" ]]; then shift 2 @@ -65,5 +63,5 @@ compare() { fi expect "${getopts_long_output}" == "${bash_getopts_output}" - expect "${getopts_long_status}" == "${bash_getopts_status}" + expect "${getopts_long[0]}" == "${bash_getopts[0]}" }