Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/runtime.func
Original file line number Diff line number Diff line change
Expand Up @@ -2432,12 +2432,16 @@ EOF
}
msg_ok "Updated ruby-build definitions"
fi
$STD "$RBENV_BIN" install "$RUBY_VERSION" || {
msg_error "Failed to install Ruby $RUBY_VERSION"
# /tmp is tmpfs on Debian 13 and counts against the container's memory
local build_tmp
build_tmp="$(mktemp -d -p /var/tmp ruby-build.XXXXXX 2>/dev/null)" || build_tmp=""
$STD env TMPDIR="${build_tmp:-/tmp}" RUBY_CONFIGURE_OPTS="--disable-install-doc ${RUBY_CONFIGURE_OPTS:-}" "$RBENV_BIN" install "$RUBY_VERSION" || {
msg_error "Failed to install Ruby $RUBY_VERSION - the build log is in ${build_tmp:-/tmp}"
cd "$PREV_DIR" 2>/dev/null || cd /
rm -rf "$TMP_DIR"
rm -rf "$TMP_DIR"
return 150
}
[[ -n "$build_tmp" ]] && rm -rf "$build_tmp"
fi

"$RBENV_BIN" global "$RUBY_VERSION" || {
Expand Down
74 changes: 74 additions & 0 deletions tests/ruby-build-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash
set -uo pipefail

CORE_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
eval "$(awk '/^setup_ruby\(\) \{/,/^}/' "$CORE_DIR/lib/runtime.func")"

TEST_DIR="$(mktemp -d)"
trap 'rm -rf -- "$TEST_DIR"' EXIT
passed=0 failed=0

check() {
if [[ "$3" == "$2" ]]; then
echo "PASS $1"
passed=$((passed + 1))
else
echo "FAIL $1: expected <$2>, got <$3>" >&2
failed=$((failed + 1))
fi
}

# shellcheck disable=SC2034 # read by setup_ruby
STD=""
msg_info() { :; }
msg_ok() { :; }
msg_warn() { :; }
msg_error() { :; }
ensure_apt_working() { :; }
apt-cache() { echo found; }
apt() { :; }
cache_installed_version() { :; }

export HOME="$TEST_DIR/home"
RBENV="$HOME/.rbenv"
mkdir -p "$RBENV/bin" "$RBENV/plugins/ruby-build/share/ruby-build"
: >"$RBENV/plugins/ruby-build/share/ruby-build/3.4.7"
cat >"$RBENV/bin/rbenv" <<EOF
#!/usr/bin/env bash
case "\$1" in
install)
{
echo "tmpdir=\$TMPDIR"
echo "opts=\$RUBY_CONFIGURE_OPTS"
[[ -d "\$TMPDIR" ]] && echo "tmpdir-exists=yes"
} >"$TEST_DIR/install.log"
exit "\${FAKE_INSTALL_RC:-0}"
;;
global) [[ -n "\${2:-}" ]] && exit 0 ;;
esac
exit 0
EOF
chmod +x "$RBENV/bin/rbenv"

run() {
: >"$TEST_DIR/install.log"
(RUBY_VERSION=3.4.7 RUBY_INSTALL_RAILS=false setup_ruby >/dev/null 2>&1)
}
logged() { sed -n "s/^$1=//p" "$TEST_DIR/install.log"; }

run
check "setup succeeds" 0 "$?"
check "the build tree is on disk, not in tmpfs /tmp" "/var/tmp" "$(dirname "$(logged tmpdir)")"
check "the build directory exists during the build" "yes" "$(logged tmpdir-exists)"
check "the build directory is removed afterwards" "no" "$([[ -e "$(logged tmpdir)" ]] && echo yes || echo no)"
check "docs are not built" "--disable-install-doc " "$(logged opts)"

RUBY_CONFIGURE_OPTS="--with-jemalloc" run
check "a caller's configure options are kept" "--disable-install-doc --with-jemalloc" "$(logged opts)"

FAKE_INSTALL_RC=1 run
check "a failed build fails the setup" 150 "$?"
check "a failed build keeps its log for inspection" "yes" "$([[ -d "$(logged tmpdir)" ]] && echo yes || echo no)"

echo "${passed} passed, ${failed} failed"
((failed == 0))
Loading