diff --git a/bin/ruby-build b/bin/ruby-build index 297f6d13da..bcd50caf5e 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -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 } diff --git a/test/fetch.bats b/test/fetch.bats index e4acbf4183..92b889c73e 100644 --- a/test/fetch.bats +++ b/test/fetch.bats @@ -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 diff --git a/test/test_helper.bash b/test/test_helper.bash index ee663fda4a..a53e33f70e 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -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:?}"/* }