From a559b30fd827e6ef70c1fc2636af458d6eb11dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 17 Oct 2023 00:18:14 +0200 Subject: [PATCH] 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 --- test/arguments.bats | 14 ++- test/build.bats | 136 +++++++++++++++++----------- test/cache.bats | 9 +- test/fixtures/jruby-9000.dev.tar.gz | Bin 0 -> 164 bytes test/fixtures/ruby-2.0.0.tar.gz | Bin 0 -> 222 bytes test/fixtures/yaml-0.1.6.tar.gz | Bin 0 -> 222 bytes test/installer.bats | 4 + test/test_helper.bash | 4 +- 8 files changed, 100 insertions(+), 67 deletions(-) create mode 100644 test/fixtures/jruby-9000.dev.tar.gz create mode 100644 test/fixtures/ruby-2.0.0.tar.gz create mode 100644 test/fixtures/yaml-0.1.6.tar.gz diff --git a/test/arguments.bats b/test/arguments.bats index efd642713b..2f91ea973b 100644 --- a/test/arguments.bats +++ b/test/arguments.bats @@ -3,21 +3,19 @@ load test_helper @test "not enough arguments for ruby-build" { + mkdir -p "$TMP" # use empty inline definition so nothing gets built anyway - local definition="${TMP}/build-definition" - echo '' > "$definition" - - run ruby-build "$definition" + touch "${TMP}/empty-definition" + run ruby-build "${TMP}/empty-definition" assert_failure assert_output_contains 'Usage: ruby-build' } @test "extra arguments for ruby-build" { + mkdir -p "$TMP" # use empty inline definition so nothing gets built anyway - local definition="${TMP}/build-definition" - echo '' > "$definition" - - run ruby-build "$definition" "${TMP}/install" "" + touch "${TMP}/empty-definition" + run ruby-build "${TMP}/empty-definition" "${TMP}/install" "" assert_failure assert_output_contains 'Usage: ruby-build' } diff --git a/test/build.bats b/test/build.bats index aa31041c00..2ab941b7c2 100755 --- a/test/build.bats +++ b/test/build.bats @@ -21,30 +21,63 @@ executable() { } cached_tarball() { - mkdir -p "$RUBY_BUILD_CACHE_PATH" - pushd "$RUBY_BUILD_CACHE_PATH" >/dev/null - tarball "$@" - popd >/dev/null + local save_to_fixtures + case "$*" in + "ruby-2.0.0 configure" | "yaml-0.1.6 configure" | "jruby-9000.dev bin/jruby" ) + 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() { - local name="$1" - local path="$PWD/$name" - local configure="$path/configure" +generate_tarball() { + local tarfile="$1" shift 1 + local name path + name="$(basename "${tarfile%.tar.gz}")" + path="$(mktemp -d "$TMP/tarball.XXXXX")/${name}" - executable "$configure" < "${path}/${file}" <> build.log OUT - - for file; do - mkdir -p "$(dirname "${path}/${file}")" - touch "${path}/${file}" + chmod +x "${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 - tar czf "${path}.tar.gz" -C "${path%/*}" "$name" + mkdir -p "$(dirname "$tarfile")" + tar czf "$tarfile" -C "${path%/*}" "$name" + rm -rf "$path" } stub_make_install() { @@ -59,8 +92,8 @@ assert_build_log() { } @test "yaml is installed for ruby" { - cached_tarball "yaml-0.1.6" - cached_tarball "ruby-2.0.0" + cached_tarball "yaml-0.1.6" configure + cached_tarball "ruby-2.0.0" configure stub_repeated uname '-s : echo Linux' stub_repeated brew false @@ -85,8 +118,8 @@ OUT } @test "apply ruby patch before building" { - cached_tarball "yaml-0.1.6" - cached_tarball "ruby-2.0.0" + cached_tarball "yaml-0.1.6" configure + cached_tarball "ruby-2.0.0" configure stub_repeated uname '-s : echo Linux' stub_repeated brew false @@ -118,8 +151,8 @@ OUT } @test "striplevel ruby patch before building" { - cached_tarball "yaml-0.1.6" - cached_tarball "ruby-2.0.0" + cached_tarball "yaml-0.1.6" configure + cached_tarball "ruby-2.0.0" configure stub_repeated uname '-s : echo Linux' stub_repeated brew false @@ -151,8 +184,8 @@ OUT } @test "apply ruby patch from git diff before building" { - cached_tarball "yaml-0.1.6" - cached_tarball "ruby-2.0.0" + cached_tarball "yaml-0.1.6" configure + cached_tarball "ruby-2.0.0" configure stub_repeated uname '-s : echo Linux' stub_repeated brew false @@ -185,7 +218,7 @@ OUT } @test "yaml is linked from Homebrew" { - cached_tarball "ruby-2.0.0" + cached_tarball "ruby-2.0.0" configure brew_libdir="$TMP/homebrew-yaml" mkdir -p "$brew_libdir" @@ -211,7 +244,7 @@ OUT } @test "gmp is linked from Homebrew" { - cached_tarball "ruby-2.0.0" + cached_tarball "ruby-2.0.0" configure gmp_libdir="$TMP/homebrew-gmp" mkdir -p "$gmp_libdir" @@ -235,7 +268,7 @@ OUT } @test "readline is linked from Homebrew" { - cached_tarball "ruby-2.0.0" + cached_tarball "ruby-2.0.0" configure readline_libdir="$TMP/homebrew-readline" mkdir -p "$readline_libdir" @@ -259,7 +292,7 @@ OUT } @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" mkdir -p "$readline_libdir" @@ -284,7 +317,7 @@ OUT } @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_make_install @@ -307,7 +340,7 @@ OUT } @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 sysctl false @@ -330,7 +363,7 @@ OUT } @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 sysctl '-n hw.ncpu : echo 4' @@ -354,7 +387,7 @@ OUT } @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 sysctl '-n hw.ncpu : echo 1' @@ -379,7 +412,7 @@ OUT } @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_make_install @@ -411,7 +444,7 @@ OUT } @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" <>' 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 rake \ @@ -567,16 +597,18 @@ OUT } @test "JRuby build" { - executable "${RUBY_BUILD_CACHE_PATH}/jruby-1.7.9/bin/jruby" <> ../build.log OUT - executable "${RUBY_BUILD_CACHE_PATH}/jruby-1.7.9/bin/gem" <> build.log 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 <11`U)Jmn0SeosyeboRe6FTOCkYS{fd6p#Ff< zLj+`@#(z>~9`(}z8S!swJ{tdY0a)T6EJRH^fQFlyn2-|xre?+_3taeEG-R>IZ%JV=^+A& z5b>X!pO==IURsn&Z953Xzafx=8vmvSCI$=&2Gn*4HZa2DUs+K|36U96rA*nPoCq*wOKb>o! Y{WJgMul|T!aKli%SxVfKJKHEY3+R!>taeEG-R>IZ%JV=^+9t z5%Hg#pO==IURsn&Z953Xzafx=8vmvSMrI5O2Gn*4HZa2DUs+K|36U96rA*nPoCq*wOKb>o! Y{WJ