diff --git a/bin/terraform b/bin/terraform index cec01d26..c613df93 100755 --- a/bin/terraform +++ b/bin/terraform @@ -11,19 +11,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "${target_file%/*}" || early_death "Failed to 'cd \$(${target_file%/*})' while trying to determine TFENV_ROOT"; - file_name="${target_file##*/}" || early_death "Failed to '\"${target_file##*/}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; TFENV_SHIM=$(readlink_f "${0}") TFENV_ROOT="${TFENV_SHIM%/*/*}"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT"; diff --git a/bin/tfenv b/bin/tfenv index 28c24a18..d2fe3139 100755 --- a/bin/tfenv +++ b/bin/tfenv @@ -11,19 +11,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "${target_file%/*}" || early_death "Failed to 'cd \$(${target_file%/*})' while trying to determine TFENV_ROOT"; - file_name="${target_file##*/}" || early_death "Failed to '\"${target_file##*/}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; TFENV_SHIM=$(readlink_f "${0}") TFENV_ROOT="${TFENV_SHIM%/*/*}"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT"; diff --git a/lib/helpers.sh b/lib/helpers.sh index 535232dc..dd5e21ac 100755 --- a/lib/helpers.sh +++ b/lib/helpers.sh @@ -2,20 +2,22 @@ set -uo pipefail; +# http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac +readlink_f() { + local target_file="${1}"; + local file_name; + + while [ "${target_file}" != "" ]; do + cd "$(dirname "${target_file}")" || early_death "Failed to 'cd \$(${target_file%/*})'"; + file_name="${target_file##*/}" || early_death "Failed to '\"${target_file##*/}\"'"; + target_file="$(readlink "${file_name}")"; + done; + + echo "$(pwd -P)/${file_name}"; +}; +export -f readlink_f; + if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "${target_file%/*}" || early_death "Failed to 'cd \$(${target_file%/*})' while trying to determine TFENV_ROOT"; - file_name="${target_file##*/}" || early_death "Failed to '\"${target_file##*/}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; TFENV_SHIM=$(readlink_f "${0}") TFENV_ROOT="${TFENV_SHIM%/*/*}"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to determine TFENV_ROOT"; diff --git a/lib/tfenv-exec.sh b/lib/tfenv-exec.sh index 189d222e..d0bd2472 100644 --- a/lib/tfenv-exec.sh +++ b/lib/tfenv-exec.sh @@ -2,11 +2,24 @@ set -uo pipefail; +function realpath-relative-to() { + # A basic implementation of GNU `realpath --relative-to=$1 $2` + # that can also be used on macOS. + local relative_to="$(readlink_f "${1}")"; + local path="$(readlink_f "${2}")"; + + echo "${path#"${relative_to}/"}"; + return 0; +} +export -f realpath-relative-to; + function tfenv-exec() { for _arg in ${@:1}; do if [[ "${_arg}" == -chdir=* ]]; then - log 'debug' "Found -chdir arg. Setting TFENV_DIR to: ${_arg#-chdir=}"; - export TFENV_DIR="${PWD}/${_arg#-chdir=}"; + chdir="${_arg#-chdir=}"; + log 'debug' "Found -chdir arg: ${chdir}"; + export TFENV_DIR="${PWD}/$(realpath-relative-to "${PWD}" "${chdir}")"; + log 'debug' "Setting TFENV_DIR to: ${TFENV_DIR}"; fi; done; diff --git a/libexec/tfenv---version b/libexec/tfenv---version index 52198f83..57533acc 100755 --- a/libexec/tfenv---version +++ b/libexec/tfenv---version @@ -21,20 +21,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-exec b/libexec/tfenv-exec index 9d3be482..93193303 100755 --- a/libexec/tfenv-exec +++ b/libexec/tfenv-exec @@ -25,20 +25,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-install b/libexec/tfenv-install index d13b3847..99c916d4 100755 --- a/libexec/tfenv-install +++ b/libexec/tfenv-install @@ -11,20 +11,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-list b/libexec/tfenv-list index 3e50c51c..8685cab1 100755 --- a/libexec/tfenv-list +++ b/libexec/tfenv-list @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-list-remote b/libexec/tfenv-list-remote index 0e8a6fcf..b847ad9a 100755 --- a/libexec/tfenv-list-remote +++ b/libexec/tfenv-list-remote @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname "${target_file}")" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-min-required b/libexec/tfenv-min-required index 80d91b1b..bccaf778 100755 --- a/libexec/tfenv-min-required +++ b/libexec/tfenv-min-required @@ -14,20 +14,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-pin b/libexec/tfenv-pin index 1c7077cf..8f548bc5 100755 --- a/libexec/tfenv-pin +++ b/libexec/tfenv-pin @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-resolve-version b/libexec/tfenv-resolve-version index d0b66bce..b9b45ce4 100755 --- a/libexec/tfenv-resolve-version +++ b/libexec/tfenv-resolve-version @@ -14,20 +14,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-uninstall b/libexec/tfenv-uninstall index 83289c85..86acc597 100755 --- a/libexec/tfenv-uninstall +++ b/libexec/tfenv-uninstall @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-use b/libexec/tfenv-use index 0c411cc6..5094de23 100755 --- a/libexec/tfenv-use +++ b/libexec/tfenv-use @@ -11,20 +11,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-version-file b/libexec/tfenv-version-file index 153a29ea..c3204318 100755 --- a/libexec/tfenv-version-file +++ b/libexec/tfenv-version-file @@ -14,20 +14,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/libexec/tfenv-version-name b/libexec/tfenv-version-name index db4ee4c8..35ec3133 100755 --- a/libexec/tfenv-version-name +++ b/libexec/tfenv-version-name @@ -13,20 +13,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/test/run.sh b/test/run.sh index 0e1d3629..010b437b 100755 --- a/test/run.sh +++ b/test/run.sh @@ -11,20 +11,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/test/test_install_and_use.sh b/test/test_install_and_use.sh index fd2b6f01..bdc9ac89 100755 --- a/test/test_install_and_use.sh +++ b/test/test_install_and_use.sh @@ -11,20 +11,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/test/test_list.sh b/test/test_list.sh index bcb8d57d..93879eaa 100755 --- a/test/test_list.sh +++ b/test/test_list.sh @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/test/test_symlink.sh b/test/test_symlink.sh index 3c99bfd2..21b674ed 100755 --- a/test/test_symlink.sh +++ b/test/test_symlink.sh @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/test/test_uninstall.sh b/test/test_uninstall.sh index 70fe803c..98a9603f 100755 --- a/test/test_uninstall.sh +++ b/test/test_uninstall.sh @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/test/test_use_latestallowed.sh b/test/test_use_latestallowed.sh index 10af0d57..1032bf5e 100755 --- a/test/test_use_latestallowed.sh +++ b/test/test_use_latestallowed.sh @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else diff --git a/test/test_use_minrequired.sh b/test/test_use_minrequired.sh index b53b2fad..5bad29c3 100755 --- a/test/test_use_minrequired.sh +++ b/test/test_use_minrequired.sh @@ -12,20 +12,6 @@ function early_death() { }; if [ -z "${TFENV_ROOT:-""}" ]; then - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac - readlink_f() { - local target_file="${1}"; - local file_name; - - while [ "${target_file}" != "" ]; do - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; - target_file="$(readlink "${file_name}")"; - done; - - echo "$(pwd -P)/${file_name}"; - }; - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else @@ -121,7 +107,7 @@ echo 'min-required' > .terraform-version; cleanup || log 'error' 'Cleanup failed?!'; -log 'info' '### Install min-required with TFENV_AUTO_INSTALL & -chdir'; +log 'info' '### Install min-required with TFENV_AUTO_INSTALL & -chdir with rel path'; minv='1.1.0'; @@ -138,6 +124,24 @@ echo 'min-required' > chdir-dir/.terraform-version cleanup || log 'error' 'Cleanup failed?!'; + +log 'info' '### Install min-required with TFENV_AUTO_INSTALL & -chdir with abs path'; + +minv='1.2.3'; + +mkdir -p chdir-dir +echo "terraform { + required_version = \">=${minv}\" +}" >> chdir-dir/min_required.tf; +echo 'min-required' > chdir-dir/.terraform-version + +( + TFENV_AUTO_INSTALL=true terraform -chdir="${PWD}/chdir-dir" version; + check_active_version "${minv}" chdir-dir; +) || error_and_proceed 'Min required version from -chdir does not match'; + +cleanup || log 'error' 'Cleanup failed?!'; + if [ "${#errors[@]}" -gt 0 ]; then log 'warn' '===== The following use_minrequired tests failed ====='; for error in "${errors[@]}"; do