mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
fix: Prevent unbound variable error with nounset in asdf.sh (#1158)
`asdf` [v0.9.0][1] included a [bug fix][2] to not override an existing ASDF_DIR. However, if `ASDF_DIR` is not set at all, then this causes an error when using bash `set -u`, or `set -o nounset` - see [here][3] for additional info. [1]: https://github.com/asdf-vm/asdf/releases/tag/v0.9.0 [2]: https://github.com/asdf-vm/asdf/pull/1008 [3]: https://mywiki.wooledge.org/BashFAQ/112
This commit is contained in:
parent
853eede94e
commit
b7dd291c98
2
asdf.sh
2
asdf.sh
@ -3,7 +3,7 @@
|
|||||||
# For Bash, ${BASH_SOURCE[0]} will be used to obtain this script's path.
|
# For Bash, ${BASH_SOURCE[0]} will be used to obtain this script's path.
|
||||||
# For Zsh and others, $0 (the path to the shell or script) will be used.
|
# For Zsh and others, $0 (the path to the shell or script) will be used.
|
||||||
_under="$_"
|
_under="$_"
|
||||||
if [ -z "$ASDF_DIR" ]; then
|
if [ -z "${ASDF_DIR:-}" ]; then
|
||||||
if [ -n "${BASH_SOURCE[0]}" ]; then
|
if [ -n "${BASH_SOURCE[0]}" ]; then
|
||||||
current_script_path="${BASH_SOURCE[0]}"
|
current_script_path="${BASH_SOURCE[0]}"
|
||||||
elif [[ "$_under" == *".sh" ]]; then
|
elif [[ "$_under" == *".sh" ]]; then
|
||||||
|
@ -26,6 +26,22 @@ cleaned_path() {
|
|||||||
[ "$output" != "" ]
|
[ "$output" != "" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "does not error if nounset is enabled" {
|
||||||
|
result=$(
|
||||||
|
unset -f asdf
|
||||||
|
unset ASDF_DIR
|
||||||
|
PATH=$(cleaned_path)
|
||||||
|
set -o nounset
|
||||||
|
|
||||||
|
source_asdf_sh
|
||||||
|
echo $ASDF_DIR
|
||||||
|
)
|
||||||
|
|
||||||
|
output=$(echo "$result" | grep "asdf")
|
||||||
|
[ "$?" -eq 0 ]
|
||||||
|
[ "$output" != "" ]
|
||||||
|
}
|
||||||
|
|
||||||
@test "adds asdf dirs to PATH" {
|
@test "adds asdf dirs to PATH" {
|
||||||
result=$(
|
result=$(
|
||||||
unset -f asdf
|
unset -f asdf
|
||||||
|
Loading…
Reference in New Issue
Block a user