1
0
Fork 0
mirror of https://github.com/rbenv/ruby-build.git synced 2025-06-25 21:21:01 +02:00

Improve cached_tarball test helper

- Now only generates a `configure` script if explicitly specified
- Add ability to add arbitrary files to the tarball
- Cache most common tarballs in fixtures directory to speed up tests
This commit is contained in:
Mislav Marohnić 2023-10-17 00:18:14 +02:00
parent fe933abbf8
commit a559b30fd8
No known key found for this signature in database
8 changed files with 100 additions and 67 deletions

View file

@ -3,21 +3,19 @@
load test_helper load test_helper
@test "not enough arguments for ruby-build" { @test "not enough arguments for ruby-build" {
mkdir -p "$TMP"
# use empty inline definition so nothing gets built anyway # use empty inline definition so nothing gets built anyway
local definition="${TMP}/build-definition" touch "${TMP}/empty-definition"
echo '' > "$definition" run ruby-build "${TMP}/empty-definition"
run ruby-build "$definition"
assert_failure assert_failure
assert_output_contains 'Usage: ruby-build' assert_output_contains 'Usage: ruby-build'
} }
@test "extra arguments for ruby-build" { @test "extra arguments for ruby-build" {
mkdir -p "$TMP"
# use empty inline definition so nothing gets built anyway # use empty inline definition so nothing gets built anyway
local definition="${TMP}/build-definition" touch "${TMP}/empty-definition"
echo '' > "$definition" run ruby-build "${TMP}/empty-definition" "${TMP}/install" ""
run ruby-build "$definition" "${TMP}/install" ""
assert_failure assert_failure
assert_output_contains 'Usage: ruby-build' assert_output_contains 'Usage: ruby-build'
} }

View file

@ -21,30 +21,63 @@ executable() {
} }
cached_tarball() { cached_tarball() {
mkdir -p "$RUBY_BUILD_CACHE_PATH" local save_to_fixtures
pushd "$RUBY_BUILD_CACHE_PATH" >/dev/null case "$*" in
tarball "$@" "ruby-2.0.0 configure" | "yaml-0.1.6 configure" | "jruby-9000.dev bin/jruby" )
popd >/dev/null save_to_fixtures=1
;;
esac
local tarball="${1}.tar.gz"
local fixture_tarball="${FIXTURE_ROOT}/${tarball}"
local cached_tarball="${RUBY_BUILD_CACHE_PATH}/${tarball}"
shift 1
if [ -n "$save_to_fixtures" ] && [ -e "$fixture_tarball" ]; then
mkdir -p "$(dirname "$cached_tarball")"
cp "$fixture_tarball" "$cached_tarball"
return 0
fi
generate_tarball "$cached_tarball" "$@"
[ -z "$save_to_fixtures" ] || cp "$cached_tarball" "$fixture_tarball"
} }
tarball() { generate_tarball() {
local name="$1" local tarfile="$1"
local path="$PWD/$name"
local configure="$path/configure"
shift 1 shift 1
local name path
name="$(basename "${tarfile%.tar.gz}")"
path="$(mktemp -d "$TMP/tarball.XXXXX")/${name}"
executable "$configure" <<OUT local file target
for file; do
case "$file" in
config | configure )
mkdir -p "$(dirname "${path}/${file}")"
cat > "${path}/${file}" <<OUT
#!$BASH #!$BASH
IFS=, IFS=,
echo "$name: [\$*]" \${RUBYOPT:+RUBYOPT=\$RUBYOPT} >> build.log echo "$name: [\$*]" \${RUBYOPT:+RUBYOPT=\$RUBYOPT} >> build.log
OUT OUT
chmod +x "${path}/${file}"
for file; do ;;
mkdir -p "$(dirname "${path}/${file}")" *:* )
touch "${path}/${file}" target="${file#*:}"
file="${file%:*}"
mkdir -p "$(dirname "${path}/${file}")"
cp "$target" "${path}/${file}"
;;
* )
mkdir -p "$(dirname "${path}/${file}")"
touch "${path}/${file}"
;;
esac
done done
tar czf "${path}.tar.gz" -C "${path%/*}" "$name" mkdir -p "$(dirname "$tarfile")"
tar czf "$tarfile" -C "${path%/*}" "$name"
rm -rf "$path"
} }
stub_make_install() { stub_make_install() {
@ -59,8 +92,8 @@ assert_build_log() {
} }
@test "yaml is installed for ruby" { @test "yaml is installed for ruby" {
cached_tarball "yaml-0.1.6" cached_tarball "yaml-0.1.6" configure
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated uname '-s : echo Linux' stub_repeated uname '-s : echo Linux'
stub_repeated brew false stub_repeated brew false
@ -85,8 +118,8 @@ OUT
} }
@test "apply ruby patch before building" { @test "apply ruby patch before building" {
cached_tarball "yaml-0.1.6" cached_tarball "yaml-0.1.6" configure
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated uname '-s : echo Linux' stub_repeated uname '-s : echo Linux'
stub_repeated brew false stub_repeated brew false
@ -118,8 +151,8 @@ OUT
} }
@test "striplevel ruby patch before building" { @test "striplevel ruby patch before building" {
cached_tarball "yaml-0.1.6" cached_tarball "yaml-0.1.6" configure
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated uname '-s : echo Linux' stub_repeated uname '-s : echo Linux'
stub_repeated brew false stub_repeated brew false
@ -151,8 +184,8 @@ OUT
} }
@test "apply ruby patch from git diff before building" { @test "apply ruby patch from git diff before building" {
cached_tarball "yaml-0.1.6" cached_tarball "yaml-0.1.6" configure
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated uname '-s : echo Linux' stub_repeated uname '-s : echo Linux'
stub_repeated brew false stub_repeated brew false
@ -185,7 +218,7 @@ OUT
} }
@test "yaml is linked from Homebrew" { @test "yaml is linked from Homebrew" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
brew_libdir="$TMP/homebrew-yaml" brew_libdir="$TMP/homebrew-yaml"
mkdir -p "$brew_libdir" mkdir -p "$brew_libdir"
@ -211,7 +244,7 @@ OUT
} }
@test "gmp is linked from Homebrew" { @test "gmp is linked from Homebrew" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
gmp_libdir="$TMP/homebrew-gmp" gmp_libdir="$TMP/homebrew-gmp"
mkdir -p "$gmp_libdir" mkdir -p "$gmp_libdir"
@ -235,7 +268,7 @@ OUT
} }
@test "readline is linked from Homebrew" { @test "readline is linked from Homebrew" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
readline_libdir="$TMP/homebrew-readline" readline_libdir="$TMP/homebrew-readline"
mkdir -p "$readline_libdir" mkdir -p "$readline_libdir"
@ -259,7 +292,7 @@ OUT
} }
@test "readline is not linked from Homebrew when explicitly defined" { @test "readline is not linked from Homebrew when explicitly defined" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
readline_libdir="$TMP/homebrew-readline" readline_libdir="$TMP/homebrew-readline"
mkdir -p "$readline_libdir" mkdir -p "$readline_libdir"
@ -284,7 +317,7 @@ OUT
} }
@test "forward extra command-line arguments as configure flags" { @test "forward extra command-line arguments as configure flags" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated brew false stub_repeated brew false
stub_make_install stub_make_install
@ -307,7 +340,7 @@ OUT
} }
@test "number of CPU cores defaults to 2" { @test "number of CPU cores defaults to 2" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated uname '-s : echo Darwin' stub_repeated uname '-s : echo Darwin'
stub sysctl false stub sysctl false
@ -330,7 +363,7 @@ OUT
} }
@test "number of CPU cores is detected on Mac" { @test "number of CPU cores is detected on Mac" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated uname '-s : echo Darwin' stub_repeated uname '-s : echo Darwin'
stub sysctl '-n hw.ncpu : echo 4' stub sysctl '-n hw.ncpu : echo 4'
@ -354,7 +387,7 @@ OUT
} }
@test "number of CPU cores is detected on FreeBSD" { @test "number of CPU cores is detected on FreeBSD" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated uname '-s : echo FreeBSD' stub_repeated uname '-s : echo FreeBSD'
stub sysctl '-n hw.ncpu : echo 1' stub sysctl '-n hw.ncpu : echo 1'
@ -379,7 +412,7 @@ OUT
} }
@test "using MAKE_INSTALL_OPTS" { @test "using MAKE_INSTALL_OPTS" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
stub_repeated uname '-s : echo Linux' stub_repeated uname '-s : echo Linux'
stub_make_install stub_make_install
@ -411,7 +444,7 @@ OUT
} }
@test "can use RUBY_CONFIGURE to apply a patch" { @test "can use RUBY_CONFIGURE to apply a patch" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
executable "${TMP}/custom-configure" <<CONF executable "${TMP}/custom-configure" <<CONF
#!$BASH #!$BASH
@ -456,8 +489,7 @@ OUT
} }
@test "mruby strategy" { @test "mruby strategy" {
package="$TMP/mruby-1.0" executable "$TMP/minirake" <<OUT
executable "$package/minirake" <<OUT
#!$BASH #!$BASH
set -e set -e
IFS=, IFS=,
@ -466,11 +498,7 @@ mkdir -p build/host/bin
touch build/host/bin/{mruby,mirb} touch build/host/bin/{mruby,mirb}
chmod +x build/host/bin/{mruby,mirb} chmod +x build/host/bin/{mruby,mirb}
OUT OUT
mkdir -p "$package/include" cached_tarball "mruby-1.0" "minirake:$TMP/minirake" include/mruby.h
touch "$package/include/mruby.h"
mkdir -p "$RUBY_BUILD_CACHE_PATH"
tar czf "$RUBY_BUILD_CACHE_PATH/${package##*/}.tar.gz" -C "${package%/*}" "${package##*/}"
rm -rf "$package"
stub gem false stub gem false
stub rake false stub rake false
@ -494,7 +522,7 @@ OUT
} }
@test "rbx uses bundle then rake" { @test "rbx uses bundle then rake" {
cached_tarball "rubinius-2.0.0" "Gemfile" cached_tarball "rubinius-2.0.0" Gemfile configure
stub gem false stub gem false
stub rake false stub rake false
@ -519,15 +547,17 @@ OUT
} }
@test "fixes rbx binstubs" { @test "fixes rbx binstubs" {
executable "${RUBY_BUILD_CACHE_PATH}/rubinius-2.0.0/gems/bin/rake" <<OUT executable "${TMP}/rbx-rake" <<OUT
#!rbx #!rbx
puts 'rake' puts 'rake'
OUT OUT
executable "${RUBY_BUILD_CACHE_PATH}/rubinius-2.0.0/gems/bin/irb" <<OUT executable "${TMP}/rbx-irb" <<OUT
#!rbx #!rbx
print '>>' print '>>'
OUT OUT
cached_tarball "rubinius-2.0.0" bin/ruby cached_tarball "rubinius-2.0.0" configure bin/ruby \
gems/bin/rake:"$TMP"/rbx-rake \
gems/bin/irb:"$TMP"/rbx-irb
stub bundle false stub bundle false
stub rake \ stub rake \
@ -567,16 +597,18 @@ OUT
} }
@test "JRuby build" { @test "JRuby build" {
executable "${RUBY_BUILD_CACHE_PATH}/jruby-1.7.9/bin/jruby" <<OUT executable "${TMP}/jruby-bin" <<OUT
#!${BASH} #!${BASH}
IFS=, IFS=,
echo "jruby [\$*]" >> ../build.log echo "jruby [\$*]" >> ../build.log
OUT OUT
executable "${RUBY_BUILD_CACHE_PATH}/jruby-1.7.9/bin/gem" <<OUT executable "${TMP}/jruby-gem" <<OUT
#!/usr/bin/env jruby #!/usr/bin/env jruby
nice gem things nice gem things
OUT OUT
cached_tarball "jruby-1.7.9" bin/foo.exe bin/bar.dll bin/baz.bat cached_tarball "jruby-1.7.9" bin/foo.exe bin/bar.dll bin/baz.bat \
bin/jruby:"$TMP"/jruby-bin \
bin/gem:"$TMP"/jruby-gem
run_inline_definition <<DEF run_inline_definition <<DEF
install_package "jruby-1.7.9" "http://jruby.org/downloads/jruby-bin-1.7.9.tar.gz" jruby install_package "jruby-1.7.9" "http://jruby.org/downloads/jruby-bin-1.7.9.tar.gz" jruby
@ -715,17 +747,17 @@ DEF
} }
@test "TruffleRuby post-install hook" { @test "TruffleRuby post-install hook" {
rmdir "$INSTALL_ROOT" executable "${TMP}/hook.sh" <<OUT
executable "${RUBY_BUILD_CACHE_PATH}/truffleruby-test/lib/truffle/post_install_hook.sh" <<OUT echo Running post-install hook >> build.log
echo Running post-install hook
OUT OUT
cached_tarball "truffleruby-test" bin/truffleruby cached_tarball "truffleruby-test" bin/truffleruby lib/truffle/post_install_hook.sh:"$TMP"/hook.sh
run_inline_definition <<DEF run_inline_definition <<DEF
install_package "truffleruby-test" "URL" truffleruby install_package "truffleruby-test" "URL" truffleruby
DEF DEF
assert_success assert_success
assert_output_contains "Running post-install hook" run cat "$INSTALL_ROOT"/build.log
assert_success "Running post-install hook"
} }
@test "non-writable TMPDIR aborts build" { @test "non-writable TMPDIR aborts build" {
@ -749,7 +781,7 @@ DEF
} }
@test "does not initialize LDFLAGS directories" { @test "does not initialize LDFLAGS directories" {
cached_tarball "ruby-2.0.0" cached_tarball "ruby-2.0.0" configure
export LDFLAGS="-L ${BATS_TEST_DIRNAME}/what/evs" export LDFLAGS="-L ${BATS_TEST_DIRNAME}/what/evs"
run_inline_definition <<DEF run_inline_definition <<DEF

View file

@ -4,14 +4,10 @@ load test_helper
export RUBY_BUILD_SKIP_MIRROR=1 export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH="$TMP/cache" export RUBY_BUILD_CACHE_PATH="$TMP/cache"
setup() {
mkdir "$RUBY_BUILD_CACHE_PATH"
}
@test "packages are saved to download cache" { @test "packages are saved to download cache" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3" stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
mkdir -p "$RUBY_BUILD_CACHE_PATH"
install_fixture definitions/without-checksum install_fixture definitions/without-checksum
assert_success assert_success
@ -24,6 +20,7 @@ setup() {
@test "cached package without checksum" { @test "cached package without checksum" {
stub curl stub curl
mkdir -p "$RUBY_BUILD_CACHE_PATH"
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
install_fixture definitions/without-checksum install_fixture definitions/without-checksum
@ -39,6 +36,7 @@ setup() {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl stub curl
mkdir -p "$RUBY_BUILD_CACHE_PATH"
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH" cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum
@ -60,6 +58,7 @@ setup() {
stub curl "-*I* : true" \ stub curl "-*I* : true" \
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3" "-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
mkdir -p "$RUBY_BUILD_CACHE_PATH"
touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"
install_fixture definitions/with-checksum install_fixture definitions/with-checksum

BIN
test/fixtures/jruby-9000.dev.tar.gz vendored Normal file

Binary file not shown.

BIN
test/fixtures/ruby-2.0.0.tar.gz vendored Normal file

Binary file not shown.

BIN
test/fixtures/yaml-0.1.6.tar.gz vendored Normal file

Binary file not shown.

View file

@ -3,6 +3,7 @@
load test_helper load test_helper
@test "installs ruby-build into PREFIX" { @test "installs ruby-build into PREFIX" {
mkdir -p "$TMP"
cd "$TMP" cd "$TMP"
PREFIX="${PWD}/usr" run "${BATS_TEST_DIRNAME}/../install.sh" PREFIX="${PWD}/usr" run "${BATS_TEST_DIRNAME}/../install.sh"
assert_success "" assert_success ""
@ -18,6 +19,7 @@ load test_helper
} }
@test "build definitions don't have the executable bit" { @test "build definitions don't have the executable bit" {
mkdir -p "$TMP"
cd "$TMP" cd "$TMP"
PREFIX="${PWD}/usr" run "${BATS_TEST_DIRNAME}/../install.sh" PREFIX="${PWD}/usr" run "${BATS_TEST_DIRNAME}/../install.sh"
assert_success "" assert_success ""
@ -30,6 +32,7 @@ OUT
} }
@test "overwrites old installation" { @test "overwrites old installation" {
mkdir -p "$TMP"
cd "$TMP" cd "$TMP"
mkdir -p bin share/ruby-build mkdir -p bin share/ruby-build
touch bin/ruby-build touch bin/ruby-build
@ -44,6 +47,7 @@ OUT
} }
@test "unrelated files are untouched" { @test "unrelated files are untouched" {
mkdir -p "$TMP"
cd "$TMP" cd "$TMP"
mkdir -p bin share/bananas mkdir -p bin share/bananas
chmod g-w bin chmod g-w bin

View file

@ -1,4 +1,4 @@
export TMP="$BATS_TEST_DIRNAME/tmp" export TMP="$BATS_TMPDIR"/ruby-build-test
export RUBY_BUILD_CURL_OPTS= export RUBY_BUILD_CURL_OPTS=
export RUBY_BUILD_HTTP_CLIENT="curl" export RUBY_BUILD_HTTP_CLIENT="curl"
export RUBY_BUILD_TESTING=true export RUBY_BUILD_TESTING=true
@ -31,7 +31,7 @@ remove_commands_from_path() {
} }
teardown() { teardown() {
rm -fr "${TMP:?}"/* rm -fr "${TMP:?}"
} }
stub() { stub() {