Commit e2b1da83 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Assert error shown when curl, wget, & aria2c are unavailable

Closes #1234
parent fe5986d6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
}

+9 −0
Original line number Diff line number Diff line
@@ -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
+13 −0
Original line number Diff line number Diff line
@@ -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:?}"/*
}