Commit 938b1a17 by Mislav Marohnić

Merge branch 'hooks'

Closes #368
parents 57d8918b eae699d6
......@@ -94,7 +94,7 @@ unset VERSION_NAME
# version is specified by rbenv. Show usage instructions if a local
# version is not specified.
DEFINITION="${ARGUMENTS[0]}"
[ -n "$DEFINITION" ] || DEFINITION="$(rbenv local 2>/dev/null || true)"
[ -n "$DEFINITION" ] || DEFINITION="$(rbenv-local 2>/dev/null || true)"
[ -n "$DEFINITION" ] || usage 1
......@@ -113,10 +113,10 @@ after_install() {
after_hooks["${#after_hooks[@]}"]="$hook"
}
# Load plugin hooks.
for script in $(rbenv-hooks install); do
source "$script"
done
OLDIFS="$IFS"
IFS=$'\n' scripts=(`rbenv-hooks install`)
IFS="$OLDIFS"
for script in "${scripts[@]}"; do source "$script"; done
# Set VERSION_NAME from $DEFINITION, if it is not already set. Then
......@@ -154,7 +154,7 @@ fi
# REE installer requires an existing Ruby installation to run. An
# unsatisfied local .ruby-version file can cause the installer to
# fail.)
export RBENV_VERSION="$(rbenv global 2>/dev/null || true)"
export RBENV_VERSION="$(rbenv-global 2>/dev/null || true)"
# Execute `before_install` hooks.
......@@ -193,7 +193,7 @@ for hook in "${after_hooks[@]}"; do eval "$hook"; done
# Run `rbenv-rehash` after a successful installation.
if [ "$STATUS" == "0" ]; then
rbenv rehash
rbenv-rehash
else
cleanup
fi
......
......@@ -38,6 +38,24 @@ case "$DEFINITION" in
;;
esac
declare -a before_hooks after_hooks
before_uninstall() {
local hook="$1"
before_hooks["${#before_hooks[@]}"]="$hook"
}
after_uninstall() {
local hook="$1"
after_hooks["${#after_hooks[@]}"]="$hook"
}
OLDIFS="$IFS"
IFS=$'\n' scripts=(`rbenv-hooks uninstall`)
IFS="$OLDIFS"
for script in "${scripts[@]}"; do source "$script"; done
VERSION_NAME="${DEFINITION##*/}"
PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"
......@@ -54,7 +72,11 @@ if [ -z "$FORCE" ]; then
esac
fi
for hook in "${before_hooks[@]}"; do eval "$hook"; done
if [ -d "$PREFIX" ]; then
rm -rf "$PREFIX"
rbenv rehash
rbenv-rehash
fi
for hook in "${after_hooks[@]}"; do eval "$hook"; done
#!/usr/bin/env bats
load test_helper
setup() {
export RBENV_ROOT="${TMP}/rbenv"
export HOOK_PATH="${TMP}/i has hooks"
mkdir -p "$HOOK_PATH"
}
@test "rbenv-install hooks" {
cat > "${HOOK_PATH}/install.bash" <<OUT
before_install 'echo before: \$PREFIX'
after_install 'echo after: \$STATUS'
OUT
stub rbenv-hooks "install : echo '$HOOK_PATH'/install.bash"
stub rbenv-rehash "echo rehashed"
definition="${TMP}/2.0.0"
cat > "$definition" <<<"echo ruby-build"
run rbenv-install "$definition"
assert_success
assert_output <<-OUT
before: ${RBENV_ROOT}/versions/2.0.0
ruby-build
after: 0
rehashed
OUT
}
@test "rbenv-uninstall hooks" {
cat > "${HOOK_PATH}/uninstall.bash" <<OUT
before_uninstall 'echo before: \$PREFIX'
after_uninstall 'echo after.'
rm() {
echo "rm \$@"
command rm "\$@"
}
OUT
stub rbenv-hooks "uninstall : echo '$HOOK_PATH'/uninstall.bash"
stub rbenv-rehash "echo rehashed"
mkdir -p "${RBENV_ROOT}/versions/2.0.0"
run rbenv-uninstall -f 2.0.0
assert_success
assert_output <<-OUT
before: ${RBENV_ROOT}/versions/2.0.0
rm -rf ${RBENV_ROOT}/versions/2.0.0
rehashed
after.
OUT
assert [ ! -d "${RBENV_ROOT}/versions/2.0.0" ]
}
......@@ -3,7 +3,7 @@ set -e
status=0
program="${0##*/}"
PROGRAM="$(echo "$program" | tr a-z A-Z)"
PROGRAM="$(echo "$program" | tr a-z- A-Z_)"
[ -n "$TMPDIR" ] || TMPDIR="/tmp"
_STUB_PLAN="${PROGRAM}_STUB_PLAN"
......
......@@ -15,7 +15,7 @@ teardown() {
stub() {
local program="$1"
local prefix="$(echo "$program" | tr a-z A-Z)"
local prefix="$(echo "$program" | tr a-z- A-Z_)"
shift
export "${prefix}_STUB_PLAN"="${TMP}/${program}-stub-plan"
......@@ -31,7 +31,7 @@ stub() {
unstub() {
local program="$1"
local prefix="$(echo "$program" | tr a-z A-Z)"
local prefix="$(echo "$program" | tr a-z- A-Z_)"
local path="${TMP}/bin/${program}"
export "${prefix}_STUB_END"=1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment