Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Fix rbenv -> phpenv test
Browse files Browse the repository at this point in the history
  • Loading branch information
sptndc committed Nov 15, 2018
1 parent 0f28675 commit 67cc945
Show file tree
Hide file tree
Showing 26 changed files with 678 additions and 710 deletions.
28 changes: 14 additions & 14 deletions test/--version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,54 @@

load test_helper

export GIT_DIR="${RBENV_TEST_DIR}/.git"
export GIT_DIR="${PHPENV_TEST_DIR}/.git"

setup() {
mkdir -p "$HOME"
git config --global user.name "Tester"
git config --global user.email "tester@test.local"
cd "$RBENV_TEST_DIR"
cd "$PHPENV_TEST_DIR"
}

git_commit() {
git commit --quiet --allow-empty -m "empty"
}

@test "default version" {
assert [ ! -e "$RBENV_ROOT" ]
run rbenv---version
assert [ ! -e "$PHPENV_ROOT" ]
run phpenv---version
assert_success
[[ $output == "rbenv "?.?.? ]]
[[ $output == "phpenv "?.?.? ]]
}

@test "doesn't read version from non-rbenv repo" {
@test "doesn't read version from non-phpenv repo" {
git init
git remote add origin https://github.com/homebrew/homebrew.git
git_commit
git tag v1.0

run rbenv---version
run phpenv---version
assert_success
[[ $output == "rbenv "?.?.? ]]
[[ $output == "phpenv "?.?.? ]]
}

@test "reads version from git repo" {
git init
git remote add origin https://github.com/rbenv/rbenv.git
git remote add origin https://github.com/sptndc/phpenv.git
git_commit
git tag v0.4.1
git_commit
git_commit

run rbenv---version
assert_success "rbenv 0.4.1-2-g$(git rev-parse --short HEAD)"
run phpenv---version
assert_success "phpenv 0.4.1-2-g$(git rev-parse --short HEAD)"
}

@test "prints default version if no tags in git repo" {
git init
git remote add origin https://github.com/rbenv/rbenv.git
git remote add origin https://github.com/sptndc/phpenv.git
git_commit

run rbenv---version
[[ $output == "rbenv "?.?.? ]]
run phpenv---version
[[ $output == "phpenv "?.?.? ]]
}
12 changes: 6 additions & 6 deletions test/commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load test_helper

@test "commands" {
run rbenv-commands
run phpenv-commands
assert_success
assert_line "init"
assert_line "rehash"
Expand All @@ -13,26 +13,26 @@ load test_helper
}

@test "commands --sh" {
run rbenv-commands --sh
run phpenv-commands --sh
assert_success
refute_line "init"
assert_line "shell"
}

@test "commands in path with spaces" {
path="${RBENV_TEST_DIR}/my commands"
cmd="${path}/rbenv-sh-hello"
path="${PHPENV_TEST_DIR}/my commands"
cmd="${path}/phpenv-sh-hello"
mkdir -p "$path"
touch "$cmd"
chmod +x "$cmd"

PATH="${path}:$PATH" run rbenv-commands --sh
PATH="${path}:$PATH" run phpenv-commands --sh
assert_success
assert_line "hello"
}

@test "commands --no-sh" {
run rbenv-commands --no-sh
run phpenv-commands --no-sh
assert_success
assert_line "init"
refute_line "shell"
Expand Down
18 changes: 9 additions & 9 deletions test/completions.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
load test_helper

create_command() {
bin="${RBENV_TEST_DIR}/bin"
bin="${PHPENV_TEST_DIR}/bin"
mkdir -p "$bin"
echo "$2" > "${bin}/$1"
chmod +x "${bin}/$1"
}

@test "command with no completion support" {
create_command "rbenv-hello" "#!$BASH
create_command "phpenv-hello" "#!$BASH
echo hello"
run rbenv-completions hello
run phpenv-completions hello
assert_success "--help"
}

@test "command with completion support" {
create_command "rbenv-hello" "#!$BASH
# Provide rbenv completions
create_command "phpenv-hello" "#!$BASH
# Provide phpenv completions
if [[ \$1 = --complete ]]; then
echo hello
else
exit 1
fi"
run rbenv-completions hello
run phpenv-completions hello
assert_success
assert_output <<OUT
--help
Expand All @@ -33,15 +33,15 @@ OUT
}

@test "forwards extra arguments" {
create_command "rbenv-hello" "#!$BASH
# provide rbenv completions
create_command "phpenv-hello" "#!$BASH
# provide phpenv completions
if [[ \$1 = --complete ]]; then
shift 1
for arg; do echo \$arg; done
else
exit 1
fi"
run rbenv-completions hello happy world
run phpenv-completions hello happy world
assert_success
assert_output <<OUT
--help
Expand Down
84 changes: 27 additions & 57 deletions test/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load test_helper
create_executable() {
name="${1?}"
shift 1
bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin"
bin="${PHPENV_ROOT}/versions/${PHPENV_VERSION}/bin"
mkdir -p "$bin"
{ if [ $# -eq 0 ]; then cat -
else echo "$@"
Expand All @@ -15,62 +15,62 @@ create_executable() {
}

@test "fails with invalid version" {
export RBENV_VERSION="2.0"
run rbenv-exec ruby -v
assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)"
export PHPENV_VERSION="2.0"
run phpenv-exec php -v
assert_failure "phpenv: version \`2.0' is not installed (set by PHPENV_VERSION environment variable)"
}

@test "fails with invalid version set from file" {
mkdir -p "$RBENV_TEST_DIR"
cd "$RBENV_TEST_DIR"
echo 1.9 > .ruby-version
run rbenv-exec rspec
assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)"
mkdir -p "$PHPENV_TEST_DIR"
cd "$PHPENV_TEST_DIR"
echo 7.1 > .php-version
run phpenv-exec phpize
assert_failure "phpenv: version \`7.1' is not installed (set by $PWD/.php-version)"
}

@test "completes with names of executables" {
export RBENV_VERSION="2.0"
create_executable "ruby" "#!/bin/sh"
create_executable "rake" "#!/bin/sh"
export PHPENV_VERSION="7.2"
create_executable "php" "#!/bin/sh"
create_executable "php-cgi" "#!/bin/sh"

rbenv-rehash
run rbenv-completions exec
phpenv-rehash
run phpenv-completions exec
assert_success
assert_output <<OUT
--help
rake
ruby
php
php-cgi
OUT
}

@test "supports hook path with spaces" {
hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks"
hook_path="${PHPENV_TEST_DIR}/custom stuff/phpenv hooks"
mkdir -p "${hook_path}/exec"
echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash"

export RBENV_VERSION=system
RBENV_HOOK_PATH="$hook_path" run rbenv-exec env
export PHPENV_VERSION=system
PHPENV_HOOK_PATH="$hook_path" run phpenv-exec env
assert_success
assert_line "HELLO=from hook"
}

@test "carries original IFS within hooks" {
hook_path="${RBENV_TEST_DIR}/rbenv.d"
hook_path="${PHPENV_TEST_DIR}/phpenv.d"
mkdir -p "${hook_path}/exec"
cat > "${hook_path}/exec/hello.bash" <<SH
hellos=(\$(printf "hello\\tugly world\\nagain"))
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
SH

export RBENV_VERSION=system
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-exec env
export PHPENV_VERSION=system
PHPENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run phpenv-exec env
assert_success
assert_line "HELLO=:hello:ugly:world:again"
}

@test "forwards all arguments" {
export RBENV_VERSION="2.0"
create_executable "ruby" <<SH
export PHPENV_VERSION="7.2"
create_executable "php" <<SH
#!$BASH
echo \$0
for arg; do
Expand All @@ -79,44 +79,14 @@ for arg; do
done
SH

run rbenv-exec ruby -w "/path to/ruby script.rb" -- extra args
run phpenv-exec php -w "/path to/php script.php" -- extra args
assert_success
assert_output <<OUT
${RBENV_ROOT}/versions/2.0/bin/ruby
${PHPENV_ROOT}/versions/7.2/bin/php
-w
/path to/ruby script.rb
/path to/php script.php
--
extra
args
OUT
}

@test "supports ruby -S <cmd>" {
export RBENV_VERSION="2.0"

# emulate `ruby -S' behavior
create_executable "ruby" <<SH
#!$BASH
if [[ \$1 == "-S"* ]]; then
found="\$(PATH="\${RUBYPATH:-\$PATH}" which \$2)"
# assert that the found executable has ruby for shebang
if head -1 "\$found" | grep ruby >/dev/null; then
\$BASH "\$found"
else
echo "ruby: no Ruby script found in input (LoadError)" >&2
exit 1
fi
else
echo 'ruby 2.0 (rbenv test)'
fi
SH

create_executable "rake" <<SH
#!/usr/bin/env ruby
echo hello rake
SH

rbenv-rehash
run ruby -S rake
assert_success "hello rake"
}
26 changes: 13 additions & 13 deletions test/global.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
load test_helper

@test "default" {
run rbenv global
run phpenv global
assert_success
assert_output "system"
}

@test "read RBENV_ROOT/version" {
mkdir -p "$RBENV_ROOT"
echo "1.2.3" > "$RBENV_ROOT/version"
run rbenv-global
@test "read PHPENV_ROOT/version" {
mkdir -p "$PHPENV_ROOT"
echo "1.2.3" > "$PHPENV_ROOT/version"
run phpenv-global
assert_success
assert_output "1.2.3"
}

@test "set RBENV_ROOT/version" {
mkdir -p "$RBENV_ROOT/versions/1.2.3"
run rbenv-global "1.2.3"
@test "set PHPENV_ROOT/version" {
mkdir -p "$PHPENV_ROOT/versions/1.2.3"
run phpenv-global "1.2.3"
assert_success
run rbenv global
run phpenv global
assert_success "1.2.3"
}

@test "fail setting invalid RBENV_ROOT/version" {
mkdir -p "$RBENV_ROOT"
run rbenv-global "1.2.3"
assert_failure "rbenv: version \`1.2.3' not installed"
@test "fail setting invalid PHPENV_ROOT/version" {
mkdir -p "$PHPENV_ROOT"
run phpenv-global "1.2.3"
assert_failure "phpenv: version \`1.2.3' not installed"
}
Loading

0 comments on commit 67cc945

Please sign in to comment.