Unverified Commit 1dc3628b authored by Mislav Marohnić's avatar Mislav Marohnić Committed by GitHub
Browse files

Merge pull request #2276 from rbenv/openssl-test

Add tests for functionality related to linking to OpenSSL
parents fe933abb 08b1cfaf
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -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'
}
+144 −53
Original line number Diff line number Diff line
@@ -21,36 +21,69 @@ 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" <<OUT
  local file target
  for file; do
    case "$file" in
    config | configure )
      mkdir -p "$(dirname "${path}/${file}")"
      cat > "${path}/${file}" <<OUT
#!$BASH
IFS=,
echo "$name: [\$*]" \${RUBYOPT:+RUBYOPT=\$RUBYOPT} >> build.log
OUT

  for file; do
      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() {
  stub "$MAKE" \
    " : echo \"$MAKE \$(inspect_args \"\$@\")\" >> build.log" \
    "install : echo \"$MAKE \$(inspect_args \"\$@\")\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
    "install* : echo \"$MAKE \$(inspect_args \"\$@\")\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
}

assert_build_log() {
@@ -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"
@@ -283,8 +316,67 @@ make install
OUT
}

@test "install bundled OpenSSL" {
  cached_tarball "openssl-1.1.1w" config
  cached_tarball "ruby-2.0.0" configure

  mkdir -p "${TMP}/ssl/certs"
  touch "${TMP}/ssl/cert.pem"

  stub_repeated uname '-s : echo Linux'
  stub_repeated brew false
  stub cc '-xc -E - : echo "OpenSSL 1.0.1a  1 Aug 2023"'
  stub openssl "version -d : echo 'OPENSSLDIR: \"${TMP}/ssl\"'"
  stub_make_install
  stub_make_install

  mkdir -p "$INSTALL_ROOT"/openssl/ssl # OPENSSLDIR
  run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl_102_300
install_package "ruby-2.0.0" "http://ruby-lang.org/ruby/2.0/ruby-2.0.0.tar.gz"
DEF
  assert_success

  unstub uname
  unstub brew
  unstub make

  assert_build_log <<OUT
openssl-1.1.1w: [--prefix=${INSTALL_ROOT}/openssl,--openssldir=${INSTALL_ROOT}/openssl/ssl,zlib-dynamic,no-ssl3,shared]
make -j 2
make install_sw install_ssldirs
ruby-2.0.0: [--prefix=$INSTALL_ROOT,--with-openssl-dir=$INSTALL_ROOT/openssl]
make -j 2
make install
OUT
}

@test "skip bundling OpenSSL if custom openssl dir was specified" {
  cached_tarball "ruby-2.0.0" configure

  stub_repeated uname '-s : echo Darwin'
  stub_repeated brew false
  stub_make_install

  RUBY_CONFIGURE_OPTS="--with-openssl-dir=/path/to/openssl" run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl_102_300
install_package "ruby-2.0.0" "http://ruby-lang.org/ruby/2.0/ruby-2.0.0.tar.gz"
DEF
  assert_success

  unstub uname
  unstub brew
  unstub make

  assert_build_log <<OUT
ruby-2.0.0: [--prefix=$INSTALL_ROOT,--with-openssl-dir=/path/to/openssl]
make -j 2
make install
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 +399,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 +422,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 +446,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 +471,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 +503,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" <<CONF
#!$BASH
@@ -456,8 +548,7 @@ OUT
}

@test "mruby strategy" {
  package="$TMP/mruby-1.0"
  executable "$package/minirake" <<OUT
  executable "$TMP/minirake" <<OUT
#!$BASH
set -e
IFS=,
@@ -466,11 +557,7 @@ mkdir -p build/host/bin
touch build/host/bin/{mruby,mirb}
chmod +x build/host/bin/{mruby,mirb}
OUT
  mkdir -p "$package/include"
  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"
  cached_tarball "mruby-1.0" "minirake:$TMP/minirake" include/mruby.h

  stub gem false
  stub rake false
@@ -494,7 +581,7 @@ OUT
}

@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 rake false
@@ -519,15 +606,17 @@ OUT
}

@test "fixes rbx binstubs" {
  executable "${RUBY_BUILD_CACHE_PATH}/rubinius-2.0.0/gems/bin/rake" <<OUT
  executable "${TMP}/rbx-rake" <<OUT
#!rbx
puts 'rake'
OUT
  executable "${RUBY_BUILD_CACHE_PATH}/rubinius-2.0.0/gems/bin/irb" <<OUT
  executable "${TMP}/rbx-irb" <<OUT
#!rbx
print '>>'
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 +656,18 @@ OUT
}

@test "JRuby build" {
  executable "${RUBY_BUILD_CACHE_PATH}/jruby-1.7.9/bin/jruby" <<OUT
  executable "${TMP}/jruby-bin" <<OUT
#!${BASH}
IFS=,
echo "jruby [\$*]" >> ../build.log
OUT
  executable "${RUBY_BUILD_CACHE_PATH}/jruby-1.7.9/bin/gem" <<OUT
  executable "${TMP}/jruby-gem" <<OUT
#!/usr/bin/env jruby
nice gem things
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
install_package "jruby-1.7.9" "http://jruby.org/downloads/jruby-bin-1.7.9.tar.gz" jruby
@@ -715,17 +806,17 @@ 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
  executable "${TMP}/hook.sh" <<OUT
echo Running post-install hook >> 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 <<DEF
install_package "truffleruby-test" "URL" truffleruby
DEF
  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" {
@@ -749,7 +840,7 @@ DEF
}

@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"
  run_inline_definition <<DEF
+4 −5
Original line number Diff line number Diff line
@@ -4,14 +4,10 @@ load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH="$TMP/cache"

setup() {
  mkdir "$RUBY_BUILD_CACHE_PATH"
}


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

  mkdir -p "$RUBY_BUILD_CACHE_PATH"
  install_fixture definitions/without-checksum

  assert_success
@@ -24,6 +20,7 @@ setup() {
@test "cached package without checksum" {
  stub curl

  mkdir -p "$RUBY_BUILD_CACHE_PATH"
  cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"

  install_fixture definitions/without-checksum
@@ -39,6 +36,7 @@ setup() {
  stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
  stub curl

  mkdir -p "$RUBY_BUILD_CACHE_PATH"
  cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"

  install_fixture definitions/with-checksum
@@ -60,6 +58,7 @@ setup() {
  stub curl "-*I* : true" \
    "-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"

  install_fixture definitions/with-checksum
+164 B

File added.

No diff preview for this file type.

+222 B

File added.

No diff preview for this file type.

Loading