Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent unbound variable error with nounset in asdf.sh #1158

Merged
merged 1 commit into from Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion asdf.sh
Expand Up @@ -3,7 +3,7 @@
# 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.
_under="$_"
if [ -z "$ASDF_DIR" ]; then
if [ -z "${ASDF_DIR:-}" ]; then
if [ -n "${BASH_SOURCE[0]}" ]; then
current_script_path="${BASH_SOURCE[0]}"
elif [[ "$_under" == *".sh" ]]; then
Expand Down
16 changes: 16 additions & 0 deletions test/asdf_sh.bats
Expand Up @@ -26,6 +26,22 @@ cleaned_path() {
[ "$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" {
result=$(
unset -f asdf
Expand Down