Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Aug 3, 2023
1 parent 0be9193 commit 488cad7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
6 changes: 2 additions & 4 deletions bin/ruby-build
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,9 @@ fetch_tarball() {
local tarball_filename="$(basename "$package_url")"
log_info "Downloading ${tarball_filename}..."
# Explicitly connect downloader utilities to the original stderr.
if http head "$mirror_url"; then
download_tarball "$mirror_url" "$package_filename" "$checksum" 2>&3
else
http head "$mirror_url" &&
download_tarball "$mirror_url" "$package_filename" "$checksum" 2>&3 ||
download_tarball "$package_url" "$package_filename" "$checksum" 2>&3
fi
fi

if log_command tar $tar_args "$package_filename" >/dev/null; then
Expand Down
5 changes: 3 additions & 2 deletions test/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -721,15 +721,16 @@ DEF
@test "TruffleRuby post-install hook" {
rmdir "$INSTALL_ROOT"
executable "${RUBY_BUILD_CACHE_PATH}/truffleruby-test/lib/truffle/post_install_hook.sh" <<OUT
echo Running post-install hook
#!$BASH
touch post_install_ran
OUT
cached_tarball "truffleruby-test" bin/truffleruby

run_inline_definition <<DEF
install_package "truffleruby-test" "URL" truffleruby
DEF
assert_success
assert_output_contains "Running post-install hook"
assert [ -e "$INSTALL_ROOT"/post_install_ran ]
}

@test "non-writable TMPDIR aborts build" {
Expand Down
6 changes: 3 additions & 3 deletions test/cache.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setup() {


@test "packages are saved to download cache" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
stub curl "-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

install_fixture definitions/without-checksum

Expand Down Expand Up @@ -58,7 +58,7 @@ setup() {

stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* : true" \
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
"-q -fL -o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4"

touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"

Expand All @@ -75,7 +75,7 @@ setup() {


@test "nonexistent cache directory is ignored" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
stub curl "-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent"

Expand Down
27 changes: 12 additions & 15 deletions test/mirror.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com

@test "package URL without checksum bypasses mirror" {
stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
stub curl "-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

install_fixture definitions/without-checksum
echo "$output" >&2

assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
Expand All @@ -23,7 +22,7 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com

@test "package URL with checksum but no shasum support bypasses mirror" {
stub shasum false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
stub curl "-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

install_fixture definitions/with-checksum

Expand All @@ -41,7 +40,7 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com

stub shasum true "echo $checksum"
stub curl "-*I* $mirror_url : true" \
"-q -o * -*S* $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
"-q -fL -o * $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4"

install_fixture definitions/with-checksum

Expand All @@ -59,7 +58,7 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com

stub shasum true "echo $checksum"
stub curl "-*I* $mirror_url : false" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
"-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

install_fixture definitions/with-checksum

Expand All @@ -77,11 +76,10 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com

stub shasum true "echo invalid" "echo $checksum"
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"
"-q -fL -o * $mirror_url : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4" \
"-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

install_fixture definitions/with-checksum
echo "$output" >&2

assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
Expand All @@ -97,7 +95,7 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com

stub shasum true "echo $checksum"
stub curl "-*I* : true" \
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
"-q -fL -o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4" \

install_fixture definitions/with-checksum

Expand All @@ -114,7 +112,7 @@ export RUBY_BUILD_MIRROR_URL=http://mirror.example.com
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"

stub shasum true "echo $checksum"
stub curl "-q -o * -*S* https://cache.ruby-lang.org/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
stub curl "-q -fL -o * https://cache.ruby-lang.org/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

run_inline_definition <<DEF
install_package "package-1.0.0" "https://cache.ruby-lang.org/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
Expand All @@ -135,7 +133,7 @@ DEF

stub shasum true "echo $checksum"
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : true" \
"-q -o * -*S* $RUBY_BUILD_MIRROR_PACKAGE_URL : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
"-q -fL -o * $RUBY_BUILD_MIRROR_PACKAGE_URL : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4"

install_fixture definitions/with-checksum

Expand All @@ -154,7 +152,7 @@ DEF

stub shasum true "echo $checksum"
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : false" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
"-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

install_fixture definitions/with-checksum

Expand All @@ -173,11 +171,10 @@ DEF

stub shasum true "echo invalid" "echo $checksum"
stub curl "-*I* $RUBY_BUILD_MIRROR_PACKAGE_URL : true" \
"-q -o * -*S* $RUBY_BUILD_MIRROR_PACKAGE_URL : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" \
"-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
"-q -fL -o * $RUBY_BUILD_MIRROR_PACKAGE_URL : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$4" \
"-q -fL -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

install_fixture definitions/with-checksum
echo "$output" >&2

assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
Expand Down

0 comments on commit 488cad7

Please sign in to comment.