Commit f666e716 by Mislav Marohnić Committed by GitHub

Merge pull request #965 from yyuu/workaround-aria2c-stdout

`aria2c` doesn't support writing remote content to stdout
parents 1a37ab18 6baed1ff
......@@ -313,11 +313,16 @@ http() {
}
http_head_aria2c() {
aria2c --dry-run ${ARIA2_OPTS} "$1" >&4 2>&1
aria2c --dry-run --no-conf=true ${ARIA2_OPTS} "$1" >&4 2>&1
}
http_get_aria2c() {
aria2c -o "${2:--}" ${ARIA2_OPTS} "$1"
local out="${2:-$(mktemp "out.XXXXXX")}"
if aria2c --allow-overwrite=true --no-conf=true -o "${out}" ${ARIA2_OPTS} "$1" >&4; then
[ -n "$2" ] || cat "${out}"
else
false
fi
}
http_head_curl() {
......
......@@ -8,9 +8,10 @@ export CC=cc
export -n RUBY_CONFIGURE_OPTS
setup() {
ensure_not_found_in_path aria2c
mkdir -p "$INSTALL_ROOT"
stub md5 false
stub aria2c false
stub curl false
}
executable() {
......
......@@ -3,27 +3,28 @@
load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH="$TMP/cache"
export RUBY_BUILD_ARIA2_OPTS=
export RUBY_BUILD_CURL_OPTS=
setup() {
ensure_not_found_in_path aria2c
mkdir "$RUBY_BUILD_CACHE_PATH"
}
@test "packages are saved to download cache" {
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
assert_success
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub aria2c
unstub curl
}
@test "cached package without checksum" {
stub aria2c
stub curl
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
......@@ -32,13 +33,13 @@ setup() {
assert_success
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub aria2c
unstub curl
}
@test "cached package with valid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub aria2c
stub curl
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
......@@ -48,7 +49,7 @@ setup() {
assert [ -x "${INSTALL_ROOT}/bin/package" ]
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub aria2c
unstub curl
unstub shasum
}
......@@ -58,8 +59,8 @@ setup() {
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub shasum true "echo invalid" "echo $checksum"
stub aria2c "--dry-run * : true" \
"-o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$2"
stub curl "-*I* : true" \
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"
......@@ -70,13 +71,13 @@ setup() {
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
assert diff -q "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz"
unstub aria2c
unstub curl
unstub shasum
}
@test "nonexistent cache directory is ignored" {
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent"
......@@ -86,5 +87,5 @@ setup() {
assert [ -x "${INSTALL_ROOT}/bin/package" ]
refute [ -d "$RUBY_BUILD_CACHE_PATH" ]
unstub aria2c
unstub curl
}
......@@ -3,107 +3,107 @@
load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH=
export RUBY_BUILD_ARIA2_OPTS=
export RUBY_BUILD_CURL_OPTS=
@test "package URL without checksum" {
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
}
@test "package URL with valid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
@test "package URL with invalid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-invalid-checksum
assert_failure
refute [ -f "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
@test "package URL with checksum but no shasum support" {
stub shasum false
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
@test "package URL with valid md5 checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-md5-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub md5
}
@test "package URL with md5 checksum but no md5 support" {
stub md5 false
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-md5-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub md5
}
@test "package with invalid checksum" {
stub shasum true "echo invalid"
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
assert_failure
refute [ -f "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
@test "existing tarball in build location is reused" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub aria2c false
stub curl false
stub wget false
export -n RUBY_BUILD_CACHE_PATH
......@@ -126,7 +126,7 @@ DEF
stub shasum true \
"echo invalid" \
"echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export -n RUBY_BUILD_CACHE_PATH
export RUBY_BUILD_BUILD_PATH="${TMP}/build"
......@@ -145,7 +145,7 @@ DEF
}
@test "package URL with checksum of unexpected length" {
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#checksum_of_unexpected_length" copy
......
......@@ -3,14 +3,16 @@
load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH=
export RUBY_BUILD_ARIA2_OPTS=
setup() {
ensure_not_found_in_path aria2c
export RUBY_BUILD_BUILD_PATH="${TMP}/source"
mkdir -p "${RUBY_BUILD_BUILD_PATH}"
}
@test "failed download displays error message" {
stub aria2c false
stub curl false
install_fixture definitions/without-checksum
assert_failure
......@@ -18,6 +20,20 @@ setup() {
assert_output_contains "error: failed to download package-1.0.0.tar.gz"
}
@test "using aria2c if available" {
stub aria2c "--allow-overwrite=true --no-conf=true -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"
install_fixture definitions/without-checksum
assert_success
assert_output <<OUT
Downloading package-1.0.0.tar.gz...
-> http://example.com/packages/package-1.0.0.tar.gz
Installing package-1.0.0...
Installed package-1.0.0 to ${TMP}/install
OUT
unstub aria2c
}
@test "fetching from git repository" {
stub git "clone --depth 1 --branch master http://example.com/packages/package.git package-dev : mkdir package-dev"
......
......@@ -3,6 +3,7 @@
load test_helper
setup() {
ensure_not_found_in_path aria2c
export RBENV_ROOT="${TMP}/rbenv"
export HOOK_PATH="${TMP}/i has hooks"
mkdir -p "$HOOK_PATH"
......
......@@ -4,12 +4,12 @@ load test_helper
export RUBY_BUILD_SKIP_MIRROR=
export RUBY_BUILD_CACHE_PATH=
export RUBY_BUILD_MIRROR_URL=http://mirror.example.com
export RUBY_BUILD_ARIA2_OPTS=
export RUBY_BUILD_CURL_OPTS=
@test "package URL without checksum bypasses mirror" {
stub shasum true
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
echo "$output" >&2
......@@ -17,21 +17,21 @@ export RUBY_BUILD_ARIA2_OPTS=
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
@test "package URL with checksum but no shasum support bypasses mirror" {
stub shasum false
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
......@@ -41,15 +41,15 @@ export RUBY_BUILD_ARIA2_OPTS=
local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
stub shasum true "echo $checksum"
stub aria2c "--dry-run $mirror_url : true" \
"-o * $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$2"
stub curl "-*I* $mirror_url : true" \
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
......@@ -59,15 +59,15 @@ export RUBY_BUILD_ARIA2_OPTS=
local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
stub shasum true "echo $checksum"
stub aria2c "--dry-run $mirror_url : false" \
"-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-*I* $mirror_url : false" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
......@@ -77,9 +77,9 @@ export RUBY_BUILD_ARIA2_OPTS=
local mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
stub shasum true "echo invalid" "echo $checksum"
stub aria2c "--dry-run $mirror_url : true" \
"-o * $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$2" \
"-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-*I* $mirror_url : true" \
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
echo "$output" >&2
......@@ -87,7 +87,7 @@ export RUBY_BUILD_ARIA2_OPTS=
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
......@@ -97,15 +97,15 @@ export RUBY_BUILD_ARIA2_OPTS=
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub shasum true "echo $checksum"
stub aria2c "--dry-run : true" \
"-o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$2" \
stub curl "-*I* : true" \
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
......@@ -115,7 +115,7 @@ export RUBY_BUILD_ARIA2_OPTS=
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub shasum true "echo $checksum"
stub aria2c "-o * https://cache.ruby-lang.org/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
stub curl "-q -o * -*S* https://cache.ruby-lang.org/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
run_inline_definition <<DEF
install_package "package-1.0.0" "https://cache.ruby-lang.org/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
......@@ -124,6 +124,6 @@ DEF
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub aria2c
unstub curl
unstub shasum
}
......@@ -4,6 +4,7 @@ load test_helper
export RBENV_ROOT="${TMP}/rbenv"
setup() {
ensure_not_found_in_path aria2c
stub rbenv-hooks 'install : true'
stub rbenv-rehash 'true'
}
......
......@@ -9,6 +9,39 @@ if [ "$FIXTURE_ROOT" != "$BATS_TEST_DIRNAME/fixtures" ]; then
export PATH
fi
remove_command_from_path() {
OLDIFS="${IFS}"
local cmd="$1"
local path
local paths=()
IFS=:
for path in ${PATH}; do
if [ -e "${path}/${cmd}" ]; then
local tmp_path="$(mktemp -d "${TMP}/path.XXXXX")"
ln -fs "${path}"/* "${tmp_path}"
rm -f "${tmp_path}/${cmd}"
paths["${#paths[@]}"]="${tmp_path}"
else
paths["${#paths[@]}"]="${path}"
fi
done
export PATH="${paths[*]}"
IFS="${OLDIFS}"
}
ensure_not_found_in_path() {
local cmd
for cmd; do
if command -v "${cmd}" 1>/dev/null 2>&1; then
remove_command_from_path "${cmd}"
fi
done
}
setup() {
ensure_not_found_in_path aria2c
}
teardown() {
rm -fr "${TMP:?}"/*
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment