Skip to content

Commit

Permalink
Assert error shown when curl, wget, & aria2c are unavailable
Browse files Browse the repository at this point in the history
Closes rbenv#1234
  • Loading branch information
mislav committed Nov 4, 2019
1 parent fe5986d commit e2b1da8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/ruby-build
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ detect_http_client() {
return
fi
done
echo "error: please install \`aria2c\`, \`curl\`, or \`wget\` and try again" >&2
echo "error: install \`curl\`, \`wget\`, or \`aria2c\` to download packages" >&2
return 1
}

Expand Down
9 changes: 9 additions & 0 deletions test/fetch.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ setup() {
assert_output_contains "error: failed to download package-1.0.0.tar.gz"
}

@test "no download tool" {
export -n RUBY_BUILD_HTTP_CLIENT
clean_path="$(remove_commands_from_path curl wget aria2c)"

PATH="$clean_path" install_fixture definitions/without-checksum
assert_failure
assert_output_contains 'error: install `curl`, `wget`, or `aria2c` to download packages'
}

@test "using aria2c if available" {
export RUBY_BUILD_ARIA2_OPTS=
export -n RUBY_BUILD_HTTP_CLIENT
Expand Down
13 changes: 13 additions & 0 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ if [ "$FIXTURE_ROOT" != "$BATS_TEST_DIRNAME/fixtures" ]; then
export PATH
fi

remove_commands_from_path() {
local path cmd
local paths=( $(command -v "$@" | sed 's!/[^/]*$!!' | sort -u) )
local NEWPATH=":$PATH:"
for path in "${paths[@]}"; do
local tmp_path="$(mktemp -d "$TMP/path.XXXXX")"
ln -fs "$path"/* "$tmp_path/"
for cmd; do rm -f "$tmp_path/$cmd"; done
NEWPATH="${NEWPATH/:$path:/:$tmp_path:}"
done
echo "${NEWPATH#:}"
}

teardown() {
rm -fr "${TMP:?}"/*
}
Expand Down

0 comments on commit e2b1da8

Please sign in to comment.