diff --git a/.travis.yml b/.travis.yml index fe9b90d..a67096f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -before_install: - - 'if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install bash; fi' # Bash4 Required language: generic matrix: include: @@ -12,10 +10,10 @@ matrix: - os: linux dist: trusty - os: osx - osx_image: xcode11.2 + osx_image: xcode11.3 - os: osx osx_image: xcode10.3 - #- os: osx - # osx_image: xcode9.4 # brew update is excruciatingly slow on xcode9.4 + - os: osx + osx_image: xcode9.4 script: - ./test/run.sh diff --git a/bin/terraform b/bin/terraform index 08137ce..a2e12a9 100755 --- a/bin/terraform +++ b/bin/terraform @@ -62,8 +62,8 @@ log 'debug' "program=\"${0##*/}\""; declare tfenv_path="${TFENV_ROOT}/bin/tfenv"; -log 'debug' "Exec: \"${tfenv_path}\" exec \"${@}\""; -exec "${tfenv_path}" exec "${@}" \ - || log 'error' "Failed to exec: \"${tfenv_path}\" exec \"${@}\""; +log 'debug' "Exec: \"${tfenv_path}\" exec \"$*\""; +exec "${tfenv_path}" exec "$@" \ + || log 'error' "Failed to exec: \"${tfenv_path}\" exec \"$*\""; log 'error' 'This line should not be reachable. Something catastrophic has occurred'; diff --git a/bin/tfenv b/bin/tfenv index ccc135d..ae6334a 100755 --- a/bin/tfenv +++ b/bin/tfenv @@ -104,8 +104,8 @@ exit 1; } | abort && exit 1; fi; shift 1; - log 'debug' "Exec: \"${command_path}\" \"${@}\""; - exec "${command_path}" "${@}"; + log 'debug' "Exec: \"${command_path}\" \"$*\""; + exec "${command_path}" "$@"; ;; esac; diff --git a/lib/bashlog.sh b/lib/bashlog.sh index 52ad6db..aa8a450 100755 --- a/lib/bashlog.sh +++ b/lib/bashlog.sh @@ -8,7 +8,7 @@ function _log_exception() { BASHLOG_JSON=0; BASHLOG_SYSLOG=0; - log 'error' "Logging Exception: ${@}"; + log 'error' "Logging Exception: $*"; ); }; export -f _log_exception; @@ -39,7 +39,7 @@ function log() { shift 1; - local line="${@}"; + local line="$@"; # RFC 5424 # @@ -154,7 +154,7 @@ function log() { fi; ;; *) - log 'error' "Undefined log level trying to log: ${@}"; + log 'error' "Undefined log level trying to log: $*"; ;; esac }; diff --git a/libexec/tfenv-exec b/libexec/tfenv-exec index 4195fd2..6ebcb04 100755 --- a/libexec/tfenv-exec +++ b/libexec/tfenv-exec @@ -95,9 +95,9 @@ fi; TF_BIN_PATH="${TFENV_ROOT}/versions/${TFENV_VERSION}/terraform"; export PATH="${TF_BIN_PATH}:${PATH}"; log 'debug' "TF_BIN_PATH added to PATH: ${TF_BIN_PATH}"; -log 'debug' "Executing: ${TF_BIN_PATH} ${@}"; +log 'debug' "Executing: ${TF_BIN_PATH} $@"; -exec "${TF_BIN_PATH}" "${@}" \ - || log 'error' "Failed to execute: ${TF_BIN_PATH} ${@}"; +exec "${TF_BIN_PATH}" "$@" \ + || log 'error' "Failed to execute: ${TF_BIN_PATH} $*"; exit 0; diff --git a/test/run.sh b/test/run.sh index 3a24dd5..0e1d362 100755 --- a/test/run.sh +++ b/test/run.sh @@ -51,7 +51,7 @@ export PATH="${TFENV_ROOT}/bin:${PATH}"; errors=(); if [ "${#}" -ne 0 ]; then - targets="${@}"; + targets="$@"; else targets="$(\ls "$(dirname "${0}")" | grep 'test_')"; fi; diff --git a/test/test_install_and_use.sh b/test/test_install_and_use.sh index 65d608d..c66ffab 100755 --- a/test/test_install_and_use.sh +++ b/test/test_install_and_use.sh @@ -67,52 +67,64 @@ test_install_and_use_overridden() { tfenv use "${k}" || return 1; check_default_version "${v}" || return 1; return 0; -} +}; declare -a errors=(); -log 'info' '### Test Suite: Install and Use' - -declare -A string_tests=(); - -string_tests['latest version']="$(tfenv list-remote | grep -e "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | head -n 1),latest"; -string_tests['latest possibly-unstable version']="$(tfenv list-remote | head -n 1),latest:"; -string_tests['latest alpha']="$(tfenv list-remote | grep 'alpha' | head -n 1),latest:alpha"; -string_tests['latest beta']="$(tfenv list-remote | grep 'beta' | head -n 1),latest:beta"; -string_tests['latest rc']="$(tfenv list-remote | grep 'rc' | head -n 1),latest:rc"; -string_tests['latest possibly-unstable version from 0.11']="$(tfenv list-remote | grep '^0\.11\.' | head -n 1),latest:^0.11."; -string_tests['0.11.15-oci']='0.11.15-oci,0.11.15-oci'; -string_tests['latest version matching regex']='0.8.8,latest:^0.8'; -string_tests['specific version']="0.7.13,0.7.13"; - -declare kv k v; -declare -i test_num=1; - -for desc in "${!string_tests[@]}"; do +log 'info' '### Test Suite: Install and Use'; + +tests__desc=( + 'latest version' + 'latest possibly-unstable version' + 'latest alpha' + 'latest beta' + 'latest rc' + 'latest possibly-unstable version from 0.11' + '0.11.15-oci' + 'latest version matching regex' + 'specific version' +); + +tests__kv=( + "$(tfenv list-remote | grep -e "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | head -n 1),latest" + "$(tfenv list-remote | head -n 1),latest:" + "$(tfenv list-remote | grep 'alpha' | head -n 1),latest:alpha" + "$(tfenv list-remote | grep 'beta' | head -n 1),latest:beta" + "$(tfenv list-remote | grep 'rc' | head -n 1),latest:rc" + "$(tfenv list-remote | grep '^0\.11\.' | head -n 1),latest:^0.11." + '0.11.15-oci,0.11.15-oci' + '0.8.8,latest:^0.8' + "0.7.13,0.7.13" +); + +tests_count=${#tests__desc[@]}; + +declare desc kv k v; + +for ((test_num=0; test_num<${tests_count}; ++test_num )) ; do cleanup || log 'error' 'Cleanup failed?!'; - kv="${string_tests[${desc}]}"; + desc=${tests__desc[${test_num}]}; + kv="${tests__kv[${test_num}]}"; v="${kv%,*}"; k="${kv##*,}"; - log 'info' "## Param Test ${test_num}/${#string_tests[*]}: ${desc} ( ${k} / ${v} )"; + log 'info' "## Param Test ${test_num}/${tests_count}: ${desc} ( ${k} / ${v} )"; test_install_and_use "${v}" "${k}" \ - && log info "## Param Test ${test_num}/${#string_tests[*]}: ${desc} ( ${k} / ${v} ) succeeded" \ - || error_and_proceed "## Param Test ${test_num}/${#string_tests[*]}: ${desc} ( ${k} / ${v} ) failed"; - test_num+=1; + && log info "## Param Test ${test_num}/${tests_count}: ${desc} ( ${k} / ${v} ) succeeded" \ + || error_and_proceed "## Param Test ${test_num}/${tests_count}: ${desc} ( ${k} / ${v} ) failed"; done; -test_num=1; -for desc in "${!string_tests[@]}"; do +for ((test_num=0; test_num<${tests_count}; ++test_num )) ; do cleanup || log 'error' 'Cleanup failed?!'; - kv="${string_tests[${desc}]}"; + desc=${tests__desc[${test_num}]}; + kv="${tests__kv[${test_num}]}"; v="${kv%,*}"; k="${kv##*,}"; - log 'info' "## ./.terraform-version Test ${test_num}/${#string_tests[*]}: ${desc} ( ${k} / ${v} )"; + log 'info' "## ./.terraform-version Test ${test_num}/${tests_count}: ${desc} ( ${k} / ${v} )"; log 'info' "Writing ${k} to ./.terraform-version"; echo "${k}" > ./.terraform-version; test_install_and_use "${v}" \ - && log info "## ./.terraform-version Test ${test_num}/${#string_tests[*]}: ${desc} ( ${k} / ${v} ) succeeded" \ - || error_and_proceed "## ./.terraform-version Test ${test_num}/${#string_tests[*]}: ${desc} ( ${k} / ${v} ) failed"; - test_num+=1; + && log info "## ./.terraform-version Test ${test_num}/${tests_count}: ${desc} ( ${k} / ${v} ) succeeded" \ + || error_and_proceed "## ./.terraform-version Test ${test_num}/${tests_count}: ${desc} ( ${k} / ${v} ) failed"; done; cleanup || log 'error' 'Cleanup failed?!'; @@ -157,21 +169,26 @@ fi; log 'info' 'Install invalid specific version'; cleanup || log 'error' 'Cleanup failed?!'; +neg_tests__desc=( + 'specific version' + 'latest:word' +); -declare -A neg_tests=(); -neg_tests['specific version']="9.9.9"; -neg_tests['latest:word']="latest:word"; +neg_tests__kv=( + '9.9.9' + "latest:word" +); -test_num=1; +neg_tests_count=${#neg_tests__desc[@]}; -for desc in "${!neg_tests[@]}"; do +for ((test_num=0; test_num<${neg_tests_count}; ++test_num )) ; do cleanup || log 'error' 'Cleanup failed?!'; - k="${neg_tests[${desc}]}"; + desc=${neg_tests__desc[${test_num}]} + k="${neg_tests__kv[${test_num}]}"; expected_error_message="No versions matching '${k}' found in remote"; - log 'info' "## Invalid Version Test ${test_num}/${#neg_tests[*]}: ${desc} ( ${k} )"; + log 'info' "## Invalid Version Test ${test_num}/${neg_tests_count}: ${desc} ( ${k} )"; [ -z "$(tfenv install "${k}" 2>&1 | grep "${expected_error_message}")" ] \ && error_and_proceed "Installing invalid version ${k}"; - test_num+=1; done; if [ "${#errors[@]}" -gt 0 ]; then diff --git a/test/test_uninstall.sh b/test/test_uninstall.sh index ccaad83..e3dde27 100755 --- a/test/test_uninstall.sh +++ b/test/test_uninstall.sh @@ -57,24 +57,34 @@ function test_uninstall() { tfenv uninstall "${v}" || return 1; log 'info' 'Confirming uninstall success; an error indicates success:'; check_active_version "${v}" && return 1 || return 0; -} +}; -log 'info' '### Test Suite: Uninstall Local Versions' +log 'info' '### Test Suite: Uninstall Local Versions'; cleanup || log 'error' 'Cleanup failed?!'; -declare -A tests; -tests['0.9.1']='0.9.1'; -tests['0.11.15-oci']='0.11.15-oci'; -tests['latest']="$(tfenv list-remote | head -n1)"; -tests['latest:^0.8']="$(tfenv list-remote | grep -e "^0.8" | head -n1)"; - -declare -i test_num=1; -for k in "${!tests[@]}"; do - log 'info' "Test ${test_num}/${#tests[@]}: Testing uninstall of version ${tests[${k}]} via keyword ${k}"; - test_uninstall "${k}" "${tests[${k}]}" \ - && log info "Test uninstall of version ${tests[${k}]} succeeded" \ - || error_and_proceed "Test uninstall of version ${tests[${k}]} failed"; - test_num+=1; +tests__keywords=( + '0.9.1' + '0.11.15-oci' + 'latest' + 'latest:^0.8' +); + +tests__versions=( + '0.9.1' + '0.11.15-oci' + "$(tfenv list-remote | head -n1)" + "$(tfenv list-remote | grep -e "^0.8" | head -n1)" +); + +tests_count=${#tests__keywords[@]}; + +for ((test_num=0; test_num<${tests_count}; ++test_num )) ; do + keyword=${tests__keywords[${test_num}]}; + version=${tests__versions[${test_num}]}; + log 'info' "Test $(( ${test_num} + 1 ))/${tests_count}: Testing uninstall of version ${version} via keyword ${keyword}"; + test_uninstall "${keyword}" "${version}" \ + && log info "Test uninstall of version ${version} (via ${keyword}) succeeded" \ + || error_and_proceed "Test uninstall of version ${version} (via ${keyword}) failed"; done; if [ "${#errors[@]}" -gt 0 ]; then