From ba0e7150cb889dc728e8f527622e851cb7082003 Mon Sep 17 00:00:00 2001 From: Manuel Streuhofer Date: Mon, 3 Sep 2018 12:00:55 +0200 Subject: [PATCH] close issue #108 (#109) * added test for issue-108 * Closes #108 * fixed some easy shellcheck complaints * trying to fix travis/debian-sid/shellcheck problem --- .travis.yml | 8 ++++---- main.sh | 6 ++++-- test/acceptance.sh | 4 +++- test/fixture/main-usage-validation.stdio | 14 ++++++++++++++ test/scenario/main-usage-validation/run.sh | 6 ++++++ 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 822d00f..318005e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,16 +18,16 @@ addons: apt: sources: - debian-sid - packages: - - shellcheck install: - npm install - if [ "$TRAVIS_OS_NAME" = "linux" ]; then npm run install:lanyon; fi before_install: +- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get install -y cabal-install; fi +- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cabal update; fi +- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cabal install shellcheck; fi - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi - if [ "$TRAVIS_OS_NAME" = "osx" ]; then which gsed || brew install gnu-sed; fi -- if [ "$TRAVIS_OS_NAME" = "osx" ]; then which gtimeout || brew install coreutils; - fi +- if [ "$TRAVIS_OS_NAME" = "osx" ]; then which gtimeout || brew install coreutils; fi - if [ "$TRAVIS_OS_NAME" = "osx" ]; then which bundle || gem install bundler; fi - bash --version - awk --version diff --git a/main.sh b/main.sh index 1543ec6..0ed656a 100755 --- a/main.sh +++ b/main.sh @@ -247,9 +247,11 @@ if [[ "${__b3bp_tmp_opts:-}" ]]; then printf -v "__b3bp_tmp_opt" '%s' "${!__b3bp_tmp_varname}" # Only assign OPTARG if option takes an argument __b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt}" - printf -v "OPTARG" '%s' "${@:OPTIND:${!__b3bp_tmp_varname}}" + __b3bp_tmp_varvalue="${!__b3bp_tmp_varname}" + [[ "${__b3bp_tmp_varvalue}" != "0" ]] && __b3bp_tmp_varvalue="1" + printf -v "OPTARG" '%s' "${@:OPTIND:${__b3bp_tmp_varvalue}}" # shift over the argument if argument is expected - ((OPTIND+=__b3bp_tmp_has_arg_${__b3bp_tmp_opt})) + ((OPTIND+=__b3bp_tmp_varvalue)) fi # we have set opt/OPTARG to the short value and the argument as OPTARG if it exists fi diff --git a/test/acceptance.sh b/test/acceptance.sh index b2c7380..fa09e7e 100755 --- a/test/acceptance.sh +++ b/test/acceptance.sh @@ -59,7 +59,7 @@ if [[ ! "$(command -v ${cmdTimeout})" ]]; then exit 1 fi -__node="$(which node)" +__node="$(command -v node)" __arch="amd64" # explicitly setting NO_COLOR to false will make b3bp ignore TERM @@ -195,6 +195,8 @@ done <<< "$(find "${__dir}/scenario" -type f -iname 'run.sh')" # Ensure correct syntax with all available bashes +# shellcheck disable=SC2230 +# "command -v" is not a substitute for "which -a" while IFS=$'\n' read -r bash; do # shellcheck disable=SC2016 echo "==> ${bash} -n $(${bash} -c 'echo "(${BASH_VERSION})"')" diff --git a/test/fixture/main-usage-validation.stdio b/test/fixture/main-usage-validation.stdio index ff7e59b..e3968cb 100644 --- a/test/fixture/main-usage-validation.stdio +++ b/test/fixture/main-usage-validation.stdio @@ -153,3 +153,17 @@ ACCPTST:STDIO_REPLACE_DATETIMES {datetime} UTC [ info] arg_b: do-b {datetime} UTC [ info] arg_c: do-c {datetime} UTC [ info] arg_d: argd +# test for issue #108 +{datetime} UTC [ info] arg_0: 1 +{datetime} UTC [ info] arg_1: 0 +{datetime} UTC [ info] arg_2: 0 +{datetime} UTC [ info] arg_3: arg3 +{datetime} UTC [ info] arg_4: value +{datetime} UTC [ info] arg_5: arg5 +{datetime} UTC [ info] arg_6: +{datetime} UTC [ info] arg_7: +{datetime} UTC [ info] arg_8: arg8 +{datetime} UTC [ info] arg_a: do-a +{datetime} UTC [ info] arg_b: do-b +{datetime} UTC [ info] arg_c: do-c +{datetime} UTC [ info] arg_d: argd diff --git a/test/scenario/main-usage-validation/run.sh b/test/scenario/main-usage-validation/run.sh index 7525c03..60fa066 100755 --- a/test/scenario/main-usage-validation/run.sh +++ b/test/scenario/main-usage-validation/run.sh @@ -56,3 +56,9 @@ echo "# complain about nothing" source "${__root}/main.sh" -3 arg3 -4 arg4 -5 arg5 -8 arg8 -d argd for argument in ${!arg_*}; do info "${argument}: ${!argument}"; done ) + +echo "# test for issue #108" +( + source "${__root}/main.sh" -3 arg3 -5 arg5 -8 arg8 -d argd --four value --zero + for argument in ${!arg_*}; do info "${argument}: ${!argument}"; done +)