From 0965577b931b1e83b4e264440321248ce66e4d0e Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Jan 2014 01:48:22 +0900 Subject: [PATCH 1/4] Import tests from rbenv with `sed -e s/rbenv/pyenv/g` --- .travis.yml | 4 ++ test/--version.bats | 46 ++++++++++++++ test/commands.bats | 39 ++++++++++++ test/completions.bats | 46 ++++++++++++++ test/exec.bats | 113 ++++++++++++++++++++++++++++++++++ test/global.bats | 31 ++++++++++ test/help.bats | 115 +++++++++++++++++++++++++++++++++++ test/hooks.bats | 65 ++++++++++++++++++++ test/init.bats | 79 ++++++++++++++++++++++++ test/libexec/rbenv-echo | 2 + test/local.bats | 103 +++++++++++++++++++++++++++++++ test/prefix.bats | 39 ++++++++++++ test/rbenv.bats | 47 ++++++++++++++ test/rehash.bats | 114 ++++++++++++++++++++++++++++++++++ test/shell.bats | 52 ++++++++++++++++ test/shims.bats | 29 +++++++++ test/test_helper.bash | 95 +++++++++++++++++++++++++++++ test/version-file-read.bats | 66 ++++++++++++++++++++ test/version-file-write.bats | 30 +++++++++ test/version-file.bats | 99 ++++++++++++++++++++++++++++++ test/version-name.bats | 65 ++++++++++++++++++++ test/version-origin.bats | 38 ++++++++++++ test/version.bats | 38 ++++++++++++ test/versions.bats | 115 +++++++++++++++++++++++++++++++++++ test/whence.bats | 30 +++++++++ test/which.bats | 74 ++++++++++++++++++++++ 26 files changed, 1574 insertions(+) create mode 100644 .travis.yml create mode 100644 test/--version.bats create mode 100644 test/commands.bats create mode 100644 test/completions.bats create mode 100644 test/exec.bats create mode 100644 test/global.bats create mode 100644 test/help.bats create mode 100644 test/hooks.bats create mode 100644 test/init.bats create mode 100755 test/libexec/rbenv-echo create mode 100644 test/local.bats create mode 100644 test/prefix.bats create mode 100644 test/rbenv.bats create mode 100755 test/rehash.bats create mode 100644 test/shell.bats create mode 100644 test/shims.bats create mode 100644 test/test_helper.bash create mode 100644 test/version-file-read.bats create mode 100644 test/version-file-write.bats create mode 100644 test/version-file.bats create mode 100644 test/version-name.bats create mode 100644 test/version-origin.bats create mode 100644 test/version.bats create mode 100644 test/versions.bats create mode 100644 test/whence.bats create mode 100644 test/which.bats diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ef43ae71 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +install: git clone https://github.com/sstephenson/bats.git +script: bats/bin/bats --tap test +# skips unnecessary Python-specific setup +language: c diff --git a/test/--version.bats b/test/--version.bats new file mode 100644 index 00000000..e035211a --- /dev/null +++ b/test/--version.bats @@ -0,0 +1,46 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "$HOME" + git config --global user.name "Tester" + git config --global user.email "tester@test.local" +} + +git_commit() { + git commit --quiet --allow-empty -m "empty" +} + +@test "default version" { + assert [ ! -e "$PYENV_ROOT" ] + run pyenv---version + assert_success + [[ $output == "pyenv 0."* ]] +} + +@test "reads version from git repo" { + mkdir -p "$PYENV_ROOT" + cd "$PYENV_ROOT" + git init + git_commit + git tag v0.4.1 + git_commit + git_commit + + cd "$PYENV_TEST_DIR" + run pyenv---version + assert_success + [[ $output == "pyenv 0.4.1-2-g"* ]] +} + +@test "prints default version if no tags in git repo" { + mkdir -p "$PYENV_ROOT" + cd "$PYENV_ROOT" + git init + git_commit + + cd "$PYENV_TEST_DIR" + run pyenv---version + [[ $output == "pyenv 0."* ]] +} diff --git a/test/commands.bats b/test/commands.bats new file mode 100644 index 00000000..b0664a6f --- /dev/null +++ b/test/commands.bats @@ -0,0 +1,39 @@ +#!/usr/bin/env bats + +load test_helper + +@test "commands" { + run pyenv-commands + assert_success + assert_line "init" + assert_line "rehash" + assert_line "shell" + refute_line "sh-shell" + assert_line "echo" +} + +@test "commands --sh" { + run pyenv-commands --sh + assert_success + refute_line "init" + assert_line "shell" +} + +@test "commands in path with spaces" { + path="${PYENV_TEST_DIR}/my commands" + cmd="${path}/pyenv-sh-hello" + mkdir -p "$path" + touch "$cmd" + chmod +x "$cmd" + + PATH="${path}:$PATH" run pyenv-commands --sh + assert_success + assert_line "hello" +} + +@test "commands --no-sh" { + run pyenv-commands --no-sh + assert_success + assert_line "init" + refute_line "shell" +} diff --git a/test/completions.bats b/test/completions.bats new file mode 100644 index 00000000..8012a98d --- /dev/null +++ b/test/completions.bats @@ -0,0 +1,46 @@ +#!/usr/bin/env bats + +load test_helper + +create_command() { + bin="${PYENV_TEST_DIR}/bin" + mkdir -p "$bin" + echo "$2" > "${bin}/$1" + chmod +x "${bin}/$1" +} + +@test "command with no completion support" { + create_command "pyenv-hello" "#!$BASH + echo hello" + run pyenv-completions hello + assert_success "" +} + +@test "command with completion support" { + create_command "pyenv-hello" "#!$BASH +# provide pyenv completions +if [[ \$1 = --complete ]]; then + echo hello +else + exit 1 +fi" + run pyenv-completions hello + assert_success "hello" +} + +@test "forwards extra arguments" { + create_command "pyenv-hello" "#!$BASH +# provide pyenv completions +if [[ \$1 = --complete ]]; then + shift 1 + for arg; do echo \$arg; done +else + exit 1 +fi" + run pyenv-completions hello happy world + assert_success + assert_output < "${bin}/$name" + chmod +x "${bin}/$name" +} + +@test "fails with invalid version" { + export PYENV_VERSION="2.0" + run pyenv-exec python -v + assert_failure "pyenv: version \`2.0' is not installed" +} + +@test "completes with names of executables" { + export PYENV_VERSION="2.0" + create_executable "python" "#!/bin/sh" + create_executable "rake" "#!/bin/sh" + + pyenv-rehash + run pyenv-completions exec + assert_success + assert_output < "${hook_path}/exec/hello.bash" + + export PYENV_VERSION=system + PYENV_HOOK_PATH="$hook_path" run pyenv-exec env + assert_success + assert_line "HELLO=from hook" +} + +@test "carries original IFS within hooks" { + hook_path="${PYENV_TEST_DIR}/pyenv.d" + mkdir -p "${hook_path}/exec" + cat > "${hook_path}/exec/hello.bash" <" { + export PYENV_VERSION="2.0" + + # emulate `python -S' behavior + create_executable "python" </dev/null; then + \$BASH "\$found" + else + echo "python: no Python script found in input (LoadError)" >&2 + exit 1 + fi +else + echo 'python 2.0 (pyenv test)' +fi +SH + + create_executable "rake" < "$PYENV_ROOT/version" + run pyenv-global + assert_success + assert_output "1.2.3" +} + +@test "set PYENV_ROOT/version" { + mkdir -p "$PYENV_ROOT/versions/1.2.3" + run pyenv-global "1.2.3" + assert_success + run pyenv global + assert_success "1.2.3" +} + +@test "fail setting invalid PYENV_ROOT/version" { + mkdir -p "$PYENV_ROOT" + run pyenv-global "1.2.3" + assert_failure "pyenv: version \`1.2.3' not installed" +} diff --git a/test/help.bats b/test/help.bats new file mode 100644 index 00000000..db178c2b --- /dev/null +++ b/test/help.bats @@ -0,0 +1,115 @@ +#!/usr/bin/env bats + +load test_helper + +@test "without args shows summary of common commands" { + run pyenv-help + assert_success + assert_line "Usage: pyenv []" + assert_line "Some useful pyenv commands are:" +} + +@test "invalid command" { + run pyenv-help hello + assert_failure "pyenv: no such command \`hello'" +} + +@test "shows help for a specific command" { + mkdir -p "${PYENV_TEST_DIR}/bin" + cat > "${PYENV_TEST_DIR}/bin/pyenv-hello" < +# Summary: Says "hello" to you, from pyenv +# This command is useful for saying hello. +echo hello +SH + + run pyenv-help hello + assert_success + assert_output < + +This command is useful for saying hello. +SH +} + +@test "replaces missing extended help with summary text" { + mkdir -p "${PYENV_TEST_DIR}/bin" + cat > "${PYENV_TEST_DIR}/bin/pyenv-hello" < +# Summary: Says "hello" to you, from pyenv +echo hello +SH + + run pyenv-help hello + assert_success + assert_output < + +Says "hello" to you, from pyenv +SH +} + +@test "extracts only usage" { + mkdir -p "${PYENV_TEST_DIR}/bin" + cat > "${PYENV_TEST_DIR}/bin/pyenv-hello" < +# Summary: Says "hello" to you, from pyenv +# This extended help won't be shown. +echo hello +SH + + run pyenv-help --usage hello + assert_success "Usage: pyenv hello " +} + +@test "multiline usage section" { + mkdir -p "${PYENV_TEST_DIR}/bin" + cat > "${PYENV_TEST_DIR}/bin/pyenv-hello" < +# pyenv hi [everybody] +# pyenv hola --translate +# Summary: Says "hello" to you, from pyenv +# Help text. +echo hello +SH + + run pyenv-help hello + assert_success + assert_output < + pyenv hi [everybody] + pyenv hola --translate + +Help text. +SH +} + +@test "multiline extended help section" { + mkdir -p "${PYENV_TEST_DIR}/bin" + cat > "${PYENV_TEST_DIR}/bin/pyenv-hello" < +# Summary: Says "hello" to you, from pyenv +# This is extended help text. +# It can contain multiple lines. +# +# And paragraphs. + +echo hello +SH + + run pyenv-help hello + assert_success + assert_output < + +This is extended help text. +It can contain multiple lines. + +And paragraphs. +SH +} diff --git a/test/hooks.bats b/test/hooks.bats new file mode 100644 index 00000000..46583aee --- /dev/null +++ b/test/hooks.bats @@ -0,0 +1,65 @@ +#!/usr/bin/env bats + +load test_helper + +create_hook() { + mkdir -p "$1/$2" + touch "$1/$2/$3" +} + +@test "prints usage help given no argument" { + run pyenv-hooks + assert_failure "Usage: pyenv hooks " +} + +@test "prints list of hooks" { + path1="${PYENV_TEST_DIR}/pyenv.d" + path2="${PYENV_TEST_DIR}/etc/pyenv_hooks" + create_hook "$path1" exec "hello.bash" + create_hook "$path1" exec "ahoy.bash" + create_hook "$path1" exec "invalid.sh" + create_hook "$path1" which "boom.bash" + create_hook "$path2" exec "bueno.bash" + + PYENV_HOOK_PATH="$path1:$path2" run pyenv-hooks exec + assert_success + assert_output </dev/null" +} + +@test "setup shell completions" { + root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" + run pyenv-init - bash + assert_success + assert_line "source '${root}/libexec/../completions/pyenv.bash'" +} + +@test "detect parent shell" { + root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" + SHELL=/bin/false run pyenv-init - + assert_success + assert_line "export PYENV_SHELL=bash" +} + +@test "setup shell completions (fish)" { + root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" + run pyenv-init - fish + assert_success + assert_line ". '${root}/libexec/../completions/pyenv.fish'" +} + +@test "fish instructions" { + run pyenv-init fish + assert [ "$status" -eq 1 ] + assert_line 'status --is-interactive; and . (pyenv init -|psub)' +} + +@test "option to skip rehash" { + run pyenv-init - --no-rehash + assert_success + refute_line "pyenv rehash 2>/dev/null" +} + +@test "adds shims to PATH" { + export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" + run pyenv-init - bash + assert_success + assert_line 0 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"' +} + +@test "adds shims to PATH (fish)" { + export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin" + run pyenv-init - fish + assert_success + assert_line 0 "setenv PATH '${PYENV_ROOT}/shims' \$PATH" +} + +@test "doesn't add shims to PATH more than once" { + export PATH="${PYENV_ROOT}/shims:$PATH" + run pyenv-init - bash + assert_success + refute_line 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"' +} + +@test "doesn't add shims to PATH more than once (fish)" { + export PATH="${PYENV_ROOT}/shims:$PATH" + run pyenv-init - fish + assert_success + refute_line 'setenv PATH "'${PYENV_ROOT}'/shims" $PATH ;' +} diff --git a/test/libexec/rbenv-echo b/test/libexec/rbenv-echo new file mode 100755 index 00000000..0a802df4 --- /dev/null +++ b/test/libexec/rbenv-echo @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +eval "echo \$$1" diff --git a/test/local.bats b/test/local.bats new file mode 100644 index 00000000..d9901822 --- /dev/null +++ b/test/local.bats @@ -0,0 +1,103 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "${PYENV_TEST_DIR}/myproject" + cd "${PYENV_TEST_DIR}/myproject" +} + +@test "no version" { + assert [ ! -e "${PWD}/.python-version" ] + run pyenv-local + assert_failure "pyenv: no local version configured for this directory" +} + +@test "local version" { + echo "1.2.3" > .python-version + run pyenv-local + assert_success "1.2.3" +} + +@test "supports legacy .pyenv-version file" { + echo "1.2.3" > .pyenv-version + run pyenv-local + assert_success "1.2.3" +} + +@test "local .python-version has precedence over .pyenv-version" { + echo "1.8" > .pyenv-version + echo "2.0" > .python-version + run pyenv-local + assert_success "2.0" +} + +@test "ignores version in parent directory" { + echo "1.2.3" > .python-version + mkdir -p "subdir" && cd "subdir" + run pyenv-local + assert_failure +} + +@test "ignores PYENV_DIR" { + echo "1.2.3" > .python-version + mkdir -p "$HOME" + echo "2.0-home" > "${HOME}/.python-version" + PYENV_DIR="$HOME" run pyenv-local + assert_success "1.2.3" +} + +@test "sets local version" { + mkdir -p "${PYENV_ROOT}/versions/1.2.3" + run pyenv-local 1.2.3 + assert_success "" + assert [ "$(cat .python-version)" = "1.2.3" ] +} + +@test "changes local version" { + echo "1.0-pre" > .python-version + mkdir -p "${PYENV_ROOT}/versions/1.2.3" + run pyenv-local + assert_success "1.0-pre" + run pyenv-local 1.2.3 + assert_success "" + assert [ "$(cat .python-version)" = "1.2.3" ] +} + +@test "renames .pyenv-version to .python-version" { + echo "1.8.7" > .pyenv-version + mkdir -p "${PYENV_ROOT}/versions/1.9.3" + run pyenv-local + assert_success "1.8.7" + run pyenv-local "1.9.3" + assert_success + assert_output < .pyenv-version + assert [ ! -e "${PYENV_ROOT}/versions/1.9.3" ] + run pyenv-local "1.9.3" + assert_failure "pyenv: version \`1.9.3' not installed" + assert [ ! -e .python-version ] + assert [ "$(cat .pyenv-version)" = "1.8.7" ] +} + +@test "unsets local version" { + touch .python-version + run pyenv-local --unset + assert_success "" + assert [ ! -e .pyenv-version ] +} + +@test "unsets alternate version file" { + touch .pyenv-version + run pyenv-local --unset + assert_success "" + assert [ ! -e .pyenv-version ] +} diff --git a/test/prefix.bats b/test/prefix.bats new file mode 100644 index 00000000..1245ceeb --- /dev/null +++ b/test/prefix.bats @@ -0,0 +1,39 @@ +#!/usr/bin/env bats + +load test_helper + +@test "prefix" { + mkdir -p "${PYENV_TEST_DIR}/myproject" + cd "${PYENV_TEST_DIR}/myproject" + echo "1.2.3" > .python-version + mkdir -p "${PYENV_ROOT}/versions/1.2.3" + run pyenv-prefix + assert_success "${PYENV_ROOT}/versions/1.2.3" +} + +@test "prefix for invalid version" { + PYENV_VERSION="1.2.3" run pyenv-prefix + assert_failure "pyenv: version \`1.2.3' not installed" +} + +@test "prefix for system" { + mkdir -p "${PYENV_TEST_DIR}/bin" + touch "${PYENV_TEST_DIR}/bin/python" + chmod +x "${PYENV_TEST_DIR}/bin/python" + PYENV_VERSION="system" run pyenv-prefix + assert_success "$PYENV_TEST_DIR" +} + +@test "prefix for invalid system" { + USRBIN_ALT="${PYENV_TEST_DIR}/usr-bin-alt" + mkdir -p "$USRBIN_ALT" + for util in head readlink greadlink; do + if [ -x "/usr/bin/$util" ]; then + ln -s "/usr/bin/$util" "${USRBIN_ALT}/$util" + fi + done + PATH_WITHOUT_PYTHON="${PATH/\/usr\/bin:/$USRBIN_ALT:}" + + PATH="$PATH_WITHOUT_PYTHON" run pyenv-prefix system + assert_failure "pyenv: system version not found in PATH" +} diff --git a/test/rbenv.bats b/test/rbenv.bats new file mode 100644 index 00000000..e16b636d --- /dev/null +++ b/test/rbenv.bats @@ -0,0 +1,47 @@ +#!/usr/bin/env bats + +load test_helper + +@test "blank invocation" { + run pyenv + assert_success + assert [ "${lines[0]}" = "pyenv 0.4.0" ] +} + +@test "invalid command" { + run pyenv does-not-exist + assert_failure + assert_output "pyenv: no such command \`does-not-exist'" +} + +@test "default PYENV_ROOT" { + PYENV_ROOT="" HOME=/home/mislav run pyenv root + assert_success + assert_output "/home/mislav/.pyenv" +} + +@test "inherited PYENV_ROOT" { + PYENV_ROOT=/opt/pyenv run pyenv root + assert_success + assert_output "/opt/pyenv" +} + +@test "default PYENV_DIR" { + run pyenv echo PYENV_DIR + assert_output "$(pwd)" +} + +@test "inherited PYENV_DIR" { + dir="${BATS_TMPDIR}/myproject" + mkdir -p "$dir" + PYENV_DIR="$dir" run pyenv echo PYENV_DIR + assert_output "$dir" +} + +@test "invalid PYENV_DIR" { + dir="${BATS_TMPDIR}/does-not-exist" + assert [ ! -d "$dir" ] + PYENV_DIR="$dir" run pyenv echo PYENV_DIR + assert_failure + assert_output "pyenv: cannot change working directory to \`$dir'" +} diff --git a/test/rehash.bats b/test/rehash.bats new file mode 100755 index 00000000..fbe70f83 --- /dev/null +++ b/test/rehash.bats @@ -0,0 +1,114 @@ +#!/usr/bin/env bats + +load test_helper + +create_executable() { + local bin="${PYENV_ROOT}/versions/${1}/bin" + mkdir -p "$bin" + touch "${bin}/$2" + chmod +x "${bin}/$2" +} + +@test "empty rehash" { + assert [ ! -d "${PYENV_ROOT}/shims" ] + run pyenv-rehash + assert_success "" + assert [ -d "${PYENV_ROOT}/shims" ] + rmdir "${PYENV_ROOT}/shims" +} + +@test "non-writable shims directory" { + mkdir -p "${PYENV_ROOT}/shims" + chmod -w "${PYENV_ROOT}/shims" + run pyenv-rehash + assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims isn't writable" +} + +@test "rehash in progress" { + mkdir -p "${PYENV_ROOT}/shims" + touch "${PYENV_ROOT}/shims/.pyenv-shim" + run pyenv-rehash + assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims/.pyenv-shim exists" +} + +@test "creates shims" { + create_executable "1.8" "python" + create_executable "1.8" "rake" + create_executable "2.0" "python" + create_executable "2.0" "rspec" + + assert [ ! -e "${PYENV_ROOT}/shims/python" ] + assert [ ! -e "${PYENV_ROOT}/shims/rake" ] + assert [ ! -e "${PYENV_ROOT}/shims/rspec" ] + + run pyenv-rehash + assert_success "" + + run ls "${PYENV_ROOT}/shims" + assert_success + assert_output < "${hook_path}/rehash/hello.bash" </dev/null || true" + assert [ -x "${PYENV_ROOT}/shims/python" ] +} + +@test "sh-rehash in fish" { + create_executable "2.0" "python" + PYENV_SHELL=fish run pyenv-sh-rehash + assert_success "" + assert [ -x "${PYENV_ROOT}/shims/python" ] +} diff --git a/test/shell.bats b/test/shell.bats new file mode 100644 index 00000000..30bf127b --- /dev/null +++ b/test/shell.bats @@ -0,0 +1,52 @@ +#!/usr/bin/env bats + +load test_helper + +@test "no shell version" { + mkdir -p "${PYENV_TEST_DIR}/myproject" + cd "${PYENV_TEST_DIR}/myproject" + echo "1.2.3" > .python-version + PYENV_VERSION="" run pyenv-sh-shell + assert_failure "pyenv: no shell-specific version configured" +} + +@test "shell version" { + PYENV_SHELL=bash PYENV_VERSION="1.2.3" run pyenv-sh-shell + assert_success 'echo "$PYENV_VERSION"' +} + +@test "shell version (fish)" { + PYENV_SHELL=fish PYENV_VERSION="1.2.3" run pyenv-sh-shell + assert_success 'echo "$PYENV_VERSION"' +} + +@test "shell unset" { + PYENV_SHELL=bash run pyenv-sh-shell --unset + assert_success "unset PYENV_VERSION" +} + +@test "shell unset (fish)" { + PYENV_SHELL=fish run pyenv-sh-shell --unset + assert_success "set -e PYENV_VERSION" +} + +@test "shell change invalid version" { + run pyenv-sh-shell 1.2.3 + assert_failure + assert_output <&2 + return 1 +} + +assert_success() { + if [ "$status" -ne 0 ]; then + flunk "command failed with exit status $status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_failure() { + if [ "$status" -eq 0 ]; then + flunk "expected failed exit status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_equal() { + if [ "$1" != "$2" ]; then + { echo "expected: $1" + echo "actual: $2" + } | flunk + fi +} + +assert_output() { + local expected + if [ $# -eq 0 ]; then expected="$(cat -)" + else expected="$1" + fi + assert_equal "$expected" "$output" +} + +assert_line() { + if [ "$1" -ge 0 ] 2>/dev/null; then + assert_equal "$2" "${lines[$1]}" + else + local line + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then return 0; fi + done + flunk "expected line \`$1'" + fi +} + +refute_line() { + if [ "$1" -ge 0 ] 2>/dev/null; then + local num_lines="${#lines[@]}" + if [ "$1" -lt "$num_lines" ]; then + flunk "output has $num_lines lines" + fi + else + local line + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then + flunk "expected to not find line \`$line'" + fi + done + fi +} + +assert() { + if ! "$@"; then + flunk "failed: $@" + fi +} diff --git a/test/version-file-read.bats b/test/version-file-read.bats new file mode 100644 index 00000000..c9d19e51 --- /dev/null +++ b/test/version-file-read.bats @@ -0,0 +1,66 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "${PYENV_TEST_DIR}/myproject" + cd "${PYENV_TEST_DIR}/myproject" +} + +@test "fails without arguments" { + run pyenv-version-file-read + assert_failure "" +} + +@test "fails for invalid file" { + run pyenv-version-file-read "non-existent" + assert_failure "" +} + +@test "fails for blank file" { + echo > my-version + run pyenv-version-file-read my-version + assert_failure "" +} + +@test "reads simple version file" { + cat > my-version <<<"1.9.3" + run pyenv-version-file-read my-version + assert_success "1.9.3" +} + +@test "ignores leading spaces" { + cat > my-version <<<" 1.9.3" + run pyenv-version-file-read my-version + assert_success "1.9.3" +} + +@test "reads only the first word from file" { + cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi" + run pyenv-version-file-read my-version + assert_success "1.9.3-p194@tag" +} + +@test "loads only the first line in file" { + cat > my-version < my-version < my-version + run pyenv-version-file-read my-version + assert_success "1.8.7" +} diff --git a/test/version-file-write.bats b/test/version-file-write.bats new file mode 100644 index 00000000..be23bbb4 --- /dev/null +++ b/test/version-file-write.bats @@ -0,0 +1,30 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "$PYENV_TEST_DIR" + cd "$PYENV_TEST_DIR" +} + +@test "invocation without 2 arguments prints usage" { + run pyenv-version-file-write + assert_failure "Usage: pyenv version-file-write " + run pyenv-version-file-write "one" "" + assert_failure +} + +@test "setting nonexistent version fails" { + assert [ ! -e ".python-version" ] + run pyenv-version-file-write ".python-version" "1.8.7" + assert_failure "pyenv: version \`1.8.7' not installed" + assert [ ! -e ".python-version" ] +} + +@test "writes value to arbitrary file" { + mkdir -p "${PYENV_ROOT}/versions/1.8.7" + assert [ ! -e "my-version" ] + run pyenv-version-file-write "${PWD}/my-version" "1.8.7" + assert_success "" + assert [ "$(cat my-version)" = "1.8.7" ] +} diff --git a/test/version-file.bats b/test/version-file.bats new file mode 100644 index 00000000..8ecf5b8a --- /dev/null +++ b/test/version-file.bats @@ -0,0 +1,99 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + mkdir -p "$PYENV_TEST_DIR" + cd "$PYENV_TEST_DIR" +} + +create_file() { + mkdir -p "$(dirname "$1")" + touch "$1" +} + +@test "prints global file if no version files exist" { + assert [ ! -e "${PYENV_ROOT}/version" ] + assert [ ! -e ".python-version" ] + run pyenv-version-file + assert_success "${PYENV_ROOT}/version" +} + +@test "detects 'global' file" { + create_file "${PYENV_ROOT}/global" + run pyenv-version-file + assert_success "${PYENV_ROOT}/global" +} + +@test "detects 'default' file" { + create_file "${PYENV_ROOT}/default" + run pyenv-version-file + assert_success "${PYENV_ROOT}/default" +} + +@test "'version' has precedence over 'global' and 'default'" { + create_file "${PYENV_ROOT}/version" + create_file "${PYENV_ROOT}/global" + create_file "${PYENV_ROOT}/default" + run pyenv-version-file + assert_success "${PYENV_ROOT}/version" +} + +@test "in current directory" { + create_file ".python-version" + run pyenv-version-file + assert_success "${PYENV_TEST_DIR}/.python-version" +} + +@test "legacy file in current directory" { + create_file ".pyenv-version" + run pyenv-version-file + assert_success "${PYENV_TEST_DIR}/.pyenv-version" +} + +@test ".python-version has precedence over legacy file" { + create_file ".python-version" + create_file ".pyenv-version" + run pyenv-version-file + assert_success "${PYENV_TEST_DIR}/.python-version" +} + +@test "in parent directory" { + create_file ".python-version" + mkdir -p project + cd project + run pyenv-version-file + assert_success "${PYENV_TEST_DIR}/.python-version" +} + +@test "topmost file has precedence" { + create_file ".python-version" + create_file "project/.python-version" + cd project + run pyenv-version-file + assert_success "${PYENV_TEST_DIR}/project/.python-version" +} + +@test "legacy file has precedence if higher" { + create_file ".python-version" + create_file "project/.pyenv-version" + cd project + run pyenv-version-file + assert_success "${PYENV_TEST_DIR}/project/.pyenv-version" +} + +@test "PYENV_DIR has precedence over PWD" { + create_file "widget/.python-version" + create_file "project/.python-version" + cd project + PYENV_DIR="${PYENV_TEST_DIR}/widget" run pyenv-version-file + assert_success "${PYENV_TEST_DIR}/widget/.python-version" +} + +@test "PWD is searched if PYENV_DIR yields no results" { + mkdir -p "widget/blank" + create_file "project/.python-version" + cd project + PYENV_DIR="${PYENV_TEST_DIR}/widget/blank" run pyenv-version-file + assert_success "${PYENV_TEST_DIR}/project/.python-version" +} diff --git a/test/version-name.bats b/test/version-name.bats new file mode 100644 index 00000000..efbaa347 --- /dev/null +++ b/test/version-name.bats @@ -0,0 +1,65 @@ +#!/usr/bin/env bats + +load test_helper + +create_version() { + mkdir -p "${PYENV_ROOT}/versions/$1" +} + +setup() { + mkdir -p "$PYENV_TEST_DIR" + cd "$PYENV_TEST_DIR" +} + +@test "no version selected" { + assert [ ! -d "${PYENV_ROOT}/versions" ] + run pyenv-version-name + assert_success "system" +} + +@test "system version is not checked for existance" { + PYENV_VERSION=system run pyenv-version-name + assert_success "system" +} + +@test "PYENV_VERSION has precedence over local" { + create_version "1.8.7" + create_version "1.9.3" + + cat > ".python-version" <<<"1.8.7" + run pyenv-version-name + assert_success "1.8.7" + + PYENV_VERSION=1.9.3 run pyenv-version-name + assert_success "1.9.3" +} + +@test "local file has precedence over global" { + create_version "1.8.7" + create_version "1.9.3" + + cat > "${PYENV_ROOT}/version" <<<"1.8.7" + run pyenv-version-name + assert_success "1.8.7" + + cat > ".python-version" <<<"1.9.3" + run pyenv-version-name + assert_success "1.9.3" +} + +@test "missing version" { + PYENV_VERSION=1.2 run pyenv-version-name + assert_failure "pyenv: version \`1.2' is not installed" +} + +@test "version with prefix in name" { + create_version "1.8.7" + cat > ".python-version" <<<"python-1.8.7" + run pyenv-version-name + assert_success + assert_output < ".python-version" <<<"1.9.3" + run pyenv-version + assert_success "1.9.3 (set by ${PWD}/.python-version)" +} + +@test "set by global file" { + create_version "1.9.3" + cat > "${PYENV_ROOT}/version" <<<"1.9.3" + run pyenv-version + assert_success "1.9.3 (set by ${PYENV_ROOT}/version)" +} diff --git a/test/versions.bats b/test/versions.bats new file mode 100644 index 00000000..44fad1de --- /dev/null +++ b/test/versions.bats @@ -0,0 +1,115 @@ +#!/usr/bin/env bats + +load test_helper + +create_version() { + mkdir -p "${PYENV_ROOT}/versions/$1" +} + +setup() { + mkdir -p "$PYENV_TEST_DIR" + cd "$PYENV_TEST_DIR" +} + +stub_system_python() { + local stub="${PYENV_TEST_DIR}/bin/python" + mkdir -p "$(dirname "$stub")" + touch "$stub" && chmod +x "$stub" +} + +@test "no versions installed" { + stub_system_python + assert [ ! -d "${PYENV_ROOT}/versions" ] + run pyenv-versions + assert_success "* system (set by ${PYENV_ROOT}/version)" +} + +@test "bare output no versions installed" { + assert [ ! -d "${PYENV_ROOT}/versions" ] + run pyenv-versions --bare + assert_success "" +} + +@test "single version installed" { + stub_system_python + create_version "1.9" + run pyenv-versions + assert_success + assert_output < "${PYENV_ROOT}/version" <<<"1.9.3" + run pyenv-versions + assert_success + assert_output < ".python-version" <<<"1.9.3" + run pyenv-versions + assert_success + assert_output < "${hook_path}/which/hello.bash" < Date: Fri, 3 Jan 2014 01:56:32 +0900 Subject: [PATCH 2/4] Remove `version-ext-compat` plugin to make test success --- plugins/version-ext-compat/README.md | 67 -------------------- plugins/version-ext-compat/bin/pyenv-sh-pop | 21 ------ plugins/version-ext-compat/bin/pyenv-sh-push | 17 ----- plugins/version-ext-compat/install.sh | 17 ----- 4 files changed, 122 deletions(-) delete mode 100644 plugins/version-ext-compat/README.md delete mode 100755 plugins/version-ext-compat/bin/pyenv-sh-pop delete mode 100755 plugins/version-ext-compat/bin/pyenv-sh-push delete mode 100755 plugins/version-ext-compat/install.sh diff --git a/plugins/version-ext-compat/README.md b/plugins/version-ext-compat/README.md deleted file mode 100644 index ac8ef824..00000000 --- a/plugins/version-ext-compat/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# pyenv-version-ext - -pyenv-version-ext is a [pyenv](https://github.com/yyuu/pyenv) plugin -that provides a `pyenv push` and `pyenv pop` commands to manage Python -versions. - -(NOTICE: -This project has been moved out as external plugin of pyenv. -The version-ext-compat has left for backward compatibility, but will be removed from future release of pyenv. -See also [pyenv-version-ext](https://github.com/yyuu/pyenv-version-ext).) - -## Installation - -### Installing as an pyenv plugin - -Installing pyenv-version-ext as a pyenv plugin will give you access to the -`pyenv push` and `pyenv pop` commands. - - $ git clone git://github.com/yyuu/pyenv-version-ext.git ~/.pyenv/plugins/pyenv-version-ext - -This will install the latest development version of pyenv-version-ext into -the `~/.pyenv/plugins/pyenv-version-ext` directory. From that directory, you -can check out a specific release tag. To update pyenv-version-ext, run `git -pull` to download the latest changes. - -## Usage - -You can manage your version stack by `pyenv push` and `pyenv pop`. - - $ pyenv global - 2.7.5 - 3.2.5 - $ pyenv push 3.3.2 - $ pyenv global - 2.7.5 - 3.2.5 - 3.3.2 - $ pyenv pop - 2.7.5 - 3.2.5 - -The push/pop operation is also efective for local and shell versions. - -### License - -(The MIT License) - -* Copyright (c) 2013 Yamashita, Yuu - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/plugins/version-ext-compat/bin/pyenv-sh-pop b/plugins/version-ext-compat/bin/pyenv-sh-pop deleted file mode 100755 index 8c53a7f7..00000000 --- a/plugins/version-ext-compat/bin/pyenv-sh-pop +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# Usage: pyenv pop -set -e -[ -n "$PYENV_DEBUG" ] && set -x - -IFS=: versions=($(pyenv-version-name)) - -echo "WARNING: The \`pop' command will be removed from pyenv. Please install https://github.com/yyuu/pyenv-version-ext." 1>&2 - -length="${#versions[@]}" -PYENV_VERSION_NAMES=() -for ((i=0; i -set -e -[ -n "$PYENV_DEBUG" ] && set -x - -IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) -versions=("$@") -PYENV_VERSION_NAMES=("${PYENV_VERSION_NAMES[@]}" "${versions[@]}") - -echo "WARNING: The \`push' command will be removed from pyenv. Please install https://github.com/yyuu/pyenv-version-ext." 1>&2 - -if [ -n "$PYENV_VERSION" ]; then - IFS=: PYENV_VERSION="${PYENV_VERSION_NAMES[*]}" - echo "export PYENV_VERSION=\"${PYENV_VERSION}\"" -else - pyenv-version-file-write "$(pyenv-version-file)" "${PYENV_VERSION_NAMES[@]}" -fi diff --git a/plugins/version-ext-compat/install.sh b/plugins/version-ext-compat/install.sh deleted file mode 100755 index 33a71fec..00000000 --- a/plugins/version-ext-compat/install.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -set -e - -if [ -z "${PREFIX}" ]; then - PREFIX="/usr/local" -fi - -BIN_PATH="${PREFIX}/bin" - -mkdir -p "${BIN_PATH}" - -for file in bin/*; do - cp "${file}" "${BIN_PATH}" -done - -echo "Installed pyenv-version-ext at ${PREFIX}" From 3dd9332eee7cb5a4012fe91dc4f479cf76071703 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Jan 2014 02:05:40 +0900 Subject: [PATCH 3/4] Fix broken tests --- libexec/pyenv-local | 5 +-- libexec/pyenv-prefix | 48 ++++++++++++++----------- libexec/pyenv-version-file-write | 2 +- libexec/pyenv-version-name | 42 +++++++++++++--------- test/exec.bats | 2 +- test/libexec/{rbenv-echo => pyenv-echo} | 0 test/{rbenv.bats => pyenv.bats} | 2 +- test/rehash.bats | 4 +-- test/version-file-read.bats | 4 +-- 9 files changed, 62 insertions(+), 47 deletions(-) rename test/libexec/{rbenv-echo => pyenv-echo} (100%) rename test/{rbenv.bats => pyenv.bats} (94%) diff --git a/libexec/pyenv-local b/libexec/pyenv-local index 8bb40fab..529cbf01 100755 --- a/libexec/pyenv-local +++ b/libexec/pyenv-local @@ -38,13 +38,14 @@ versions=($@) if [ "$versions" = "--unset" ]; then rm -f .python-version .pyenv-version elif [ -n "$versions" ]; then - if [ "$(PYENV_VERSION= pyenv-version-origin)" -ef .pyenv-version ]; then + previous_file="$(PYENV_VERSION= pyenv-version-origin || true)" + pyenv-version-file-write .python-version "${versions[@]}" + if [ "$previous_file" -ef .pyenv-version ]; then rm -f .pyenv-version { echo "pyenv: removed existing \`.pyenv-version' file and migrated" echo " local version specification to \`.python-version' file" } >&2 fi - pyenv-version-file-write .python-version "${versions[@]}" else OLDIFS="$IFS" IFS=: versions=($( diff --git a/libexec/pyenv-prefix b/libexec/pyenv-prefix index 64f6f391..a25ff030 100755 --- a/libexec/pyenv-prefix +++ b/libexec/pyenv-prefix @@ -16,32 +16,38 @@ if [ "$1" = "--complete" ]; then fi if [ -n "$1" ]; then - versions=($@) OLDIFS="$IFS" - IFS=: PYENV_VERSION="${versions[*]}" - IFS="$OLDIFS" - export PYENV_VERSION -else - OLDIFS="$IFS" - IFS=: versions=($(pyenv-version-name)) + { IFS=: + export PYENV_VERSION="$*" + } IFS="$OLDIFS" +elif [ -z "$PYENV_VERSION" ]; then + PYENV_VERSION="$(pyenv-version-name)" fi PYENV_PREFIX_PATHS=() -for version in "${versions[@]}"; do - if [ "$version" = "system" ]; then - PYTHON_PATH="$(PYENV_VERSION="${version}" pyenv-which python || true)" - PYENV_PREFIX_PATH="${PYTHON_PATH%/bin/*}" - else - PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}" - fi - if [ -d "$PYENV_PREFIX_PATH" ]; then - PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH") - else - echo "pyenv: version \`${version}' not installed" >&2 - exit 1 - fi -done +OLDIFS="$IFS" +{ IFS=: + for version in ${PYENV_VERSION}; do + if [ "$version" = "system" ]; then + if PYTHON_PATH="$(pyenv-which python 2>/dev/null)"; then + PYENV_PREFIX_PATH="${PYTHON_PATH%/bin/*}" + else + echo "pyenv: system version not found in PATH" >&2 + exit 1 + fi + else + PYENV_PREFIX_PATH="${PYENV_ROOT}/versions/${version}" + fi + if [ -d "$PYENV_PREFIX_PATH" ]; then + PYENV_PREFIX_PATHS=("${PYENV_PREFIX_PATHS[@]}" "$PYENV_PREFIX_PATH") + else + echo "pyenv: version \`${version}' not installed" >&2 + exit 1 + fi + done +} +IFS="$OLDIFS" OLDIFS="$IFS" { IFS=: diff --git a/libexec/pyenv-version-file-write b/libexec/pyenv-version-file-write index 6441909e..5ec01b6c 100755 --- a/libexec/pyenv-version-file-write +++ b/libexec/pyenv-version-file-write @@ -5,7 +5,7 @@ set -e [ -n "$PYENV_DEBUG" ] && set -x PYENV_VERSION_FILE="$1" -shift +shift || true versions=("$@") if [ -z "$versions" ] || [ -z "$PYENV_VERSION_FILE" ]; then diff --git a/libexec/pyenv-version-name b/libexec/pyenv-version-name index 368ccb97..c15178e2 100755 --- a/libexec/pyenv-version-name +++ b/libexec/pyenv-version-name @@ -5,18 +5,10 @@ set -e if [ -z "$PYENV_VERSION" ]; then PYENV_VERSION_FILE="$(pyenv-version-file)" - OLDIFS="$IFS" - IFS=: versions=($(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)) - IFS=: PYENV_VERSION="${versions[*]}" - IFS="$OLDIFS" - export PYENV_VERSION -else - OLDIFS="$IFS" - IFS=: versions=($(echo "${PYENV_VERSION}")) - IFS="$OLDIFS" + PYENV_VERSION="$(pyenv-version-file-read "$PYENV_VERSION_FILE" || true)" fi -if [ -z "$versions" ] || [ "$versions" = "system" ]; then +if [ -z "$PYENV_VERSION" ] || [ "$PYENV_VERSION" = "system" ]; then echo "system" exit fi @@ -26,11 +18,27 @@ version_exists() { [ -d "${PYENV_ROOT}/versions/${version}" ] } -for version in "${versions[@]}"; do - if [ "$version" != "system" ] && ! version_exists "$version"; then - echo "pyenv: version \`$version' is not installed" >&2 - exit 1 - fi -done +versions=() +OLDIFS="$IFS" +{ IFS=: + for version in ${PYENV_VERSION}; do + if version_exists "$version" || [ "$version" = "system" ]; then + versions=("${versions[@]}" "${version}") + elif version_exists "${version#python-}"; then + { echo "warning: ignoring extraneous \`python-' prefix in version \`${version}'" + echo " (set by $(pyenv-version-origin))" + } >&2 + versions=("${versions[@]}" "${version#python-}") + else + echo "pyenv: version \`$version' is not installed" >&2 + exit 1 + fi + done +} +IFS="$OLDIFS" -echo "${PYENV_VERSION}" +OLDIFS="$IFS" +{ IFS=: + echo "${versions[*]}" +} +IFS="$OLDIFS" diff --git a/test/exec.bats b/test/exec.bats index c81db709..817d1aee 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -29,8 +29,8 @@ create_executable() { run pyenv-completions exec assert_success assert_output < my-version <<<"1.9.3-p194@tag 1.8.7 hi" run pyenv-version-file-read my-version - assert_success "1.9.3-p194@tag" + assert_success "1.9.3-p194@tag:1.8.7:hi" } @test "loads only the first line in file" { @@ -47,7 +47,7 @@ setup() { 1.9.3 two IN run pyenv-version-file-read my-version - assert_success "1.8.7" + assert_success "1.8.7:one:1.9.3:two" } @test "ignores leading blank lines" { From 319721b3800010dd2875ad4b4ee039d81ced23c6 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 3 Jan 2014 04:38:29 +0900 Subject: [PATCH 4/4] Modify applications and versions for Python --- test/exec.bats | 26 ++++++++-------- test/local.bats | 28 ++++++++--------- test/rehash.bats | 30 +++++++++--------- test/version-file-read.bats | 26 ++++++++-------- test/version-file-write.bats | 10 +++--- test/version-name.bats | 32 +++++++++---------- test/version.bats | 18 +++++------ test/versions.bats | 60 ++++++++++++++++++------------------ test/whence.bats | 20 ++++++------ test/which.bats | 40 ++++++++++++------------ 10 files changed, 145 insertions(+), 145 deletions(-) diff --git a/test/exec.bats b/test/exec.bats index 817d1aee..952ffeb7 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -15,22 +15,22 @@ create_executable() { } @test "fails with invalid version" { - export PYENV_VERSION="2.0" + export PYENV_VERSION="3.4" run pyenv-exec python -v - assert_failure "pyenv: version \`2.0' is not installed" + assert_failure "pyenv: version \`3.4' is not installed" } @test "completes with names of executables" { - export PYENV_VERSION="2.0" + export PYENV_VERSION="3.4" + create_executable "fab" "#!/bin/sh" create_executable "python" "#!/bin/sh" - create_executable "rake" "#!/bin/sh" pyenv-rehash run pyenv-completions exec assert_success assert_output <" { - export PYENV_VERSION="2.0" + export PYENV_VERSION="3.4" # emulate `python -S' behavior create_executable "python" < .pyenv-version - echo "2.0" > .python-version + echo "2.7" > .pyenv-version + echo "3.4" > .python-version run pyenv-local - assert_success "2.0" + assert_success "3.4" } @test "ignores version in parent directory" { @@ -42,7 +42,7 @@ setup() { @test "ignores PYENV_DIR" { echo "1.2.3" > .python-version mkdir -p "$HOME" - echo "2.0-home" > "${HOME}/.python-version" + echo "3.4-home" > "${HOME}/.python-version" PYENV_DIR="$HOME" run pyenv-local assert_success "1.2.3" } @@ -65,27 +65,27 @@ setup() { } @test "renames .pyenv-version to .python-version" { - echo "1.8.7" > .pyenv-version - mkdir -p "${PYENV_ROOT}/versions/1.9.3" + echo "2.7.6" > .pyenv-version + mkdir -p "${PYENV_ROOT}/versions/3.3.3" run pyenv-local - assert_success "1.8.7" - run pyenv-local "1.9.3" + assert_success "2.7.6" + run pyenv-local "3.3.3" assert_success assert_output < .pyenv-version - assert [ ! -e "${PYENV_ROOT}/versions/1.9.3" ] - run pyenv-local "1.9.3" - assert_failure "pyenv: version \`1.9.3' not installed" + echo "2.7.6" > .pyenv-version + assert [ ! -e "${PYENV_ROOT}/versions/3.3.3" ] + run pyenv-local "3.3.3" + assert_failure "pyenv: version \`3.3.3' not installed" assert [ ! -e .python-version ] - assert [ "$(cat .pyenv-version)" = "1.8.7" ] + assert [ "$(cat .pyenv-version)" = "2.7.6" ] } @test "unsets local version" { diff --git a/test/rehash.bats b/test/rehash.bats index b6682a98..ab049527 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -32,14 +32,14 @@ create_executable() { } @test "creates shims" { - create_executable "1.8" "python" - create_executable "1.8" "rake" - create_executable "2.0" "python" - create_executable "2.0" "rspec" + create_executable "2.7" "python" + create_executable "2.7" "fab" + create_executable "3.4" "python" + create_executable "3.4" "py.test" + assert [ ! -e "${PYENV_ROOT}/shims/fab" ] assert [ ! -e "${PYENV_ROOT}/shims/python" ] - assert [ ! -e "${PYENV_ROOT}/shims/rake" ] - assert [ ! -e "${PYENV_ROOT}/shims/rspec" ] + assert [ ! -e "${PYENV_ROOT}/shims/py.test" ] run pyenv-rehash assert_success "" @@ -47,9 +47,9 @@ create_executable() { run ls "${PYENV_ROOT}/shims" assert_success assert_output </dev/null || true" assert [ -x "${PYENV_ROOT}/shims/python" ] } @test "sh-rehash in fish" { - create_executable "2.0" "python" + create_executable "3.4" "python" PYENV_SHELL=fish run pyenv-sh-rehash assert_success "" assert [ -x "${PYENV_ROOT}/shims/python" ] diff --git a/test/version-file-read.bats b/test/version-file-read.bats index 7414aa01..851505d2 100644 --- a/test/version-file-read.bats +++ b/test/version-file-read.bats @@ -24,43 +24,43 @@ setup() { } @test "reads simple version file" { - cat > my-version <<<"1.9.3" + cat > my-version <<<"3.3.3" run pyenv-version-file-read my-version - assert_success "1.9.3" + assert_success "3.3.3" } @test "ignores leading spaces" { - cat > my-version <<<" 1.9.3" + cat > my-version <<<" 3.3.3" run pyenv-version-file-read my-version - assert_success "1.9.3" + assert_success "3.3.3" } @test "reads only the first word from file" { - cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi" + cat > my-version <<<"3.3.3-p194@tag 2.7.6 hi" run pyenv-version-file-read my-version - assert_success "1.9.3-p194@tag:1.8.7:hi" + assert_success "3.3.3-p194@tag:2.7.6:hi" } @test "loads only the first line in file" { cat > my-version < my-version < my-version + echo -n "2.7.6" > my-version run pyenv-version-file-read my-version - assert_success "1.8.7" + assert_success "2.7.6" } diff --git a/test/version-file-write.bats b/test/version-file-write.bats index be23bbb4..aa7100d6 100644 --- a/test/version-file-write.bats +++ b/test/version-file-write.bats @@ -16,15 +16,15 @@ setup() { @test "setting nonexistent version fails" { assert [ ! -e ".python-version" ] - run pyenv-version-file-write ".python-version" "1.8.7" - assert_failure "pyenv: version \`1.8.7' not installed" + run pyenv-version-file-write ".python-version" "2.7.6" + assert_failure "pyenv: version \`2.7.6' not installed" assert [ ! -e ".python-version" ] } @test "writes value to arbitrary file" { - mkdir -p "${PYENV_ROOT}/versions/1.8.7" + mkdir -p "${PYENV_ROOT}/versions/2.7.6" assert [ ! -e "my-version" ] - run pyenv-version-file-write "${PWD}/my-version" "1.8.7" + run pyenv-version-file-write "${PWD}/my-version" "2.7.6" assert_success "" - assert [ "$(cat my-version)" = "1.8.7" ] + assert [ "$(cat my-version)" = "2.7.6" ] } diff --git a/test/version-name.bats b/test/version-name.bats index efbaa347..2d7ebe20 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -23,28 +23,28 @@ setup() { } @test "PYENV_VERSION has precedence over local" { - create_version "1.8.7" - create_version "1.9.3" + create_version "2.7.6" + create_version "3.3.3" - cat > ".python-version" <<<"1.8.7" + cat > ".python-version" <<<"2.7.6" run pyenv-version-name - assert_success "1.8.7" + assert_success "2.7.6" - PYENV_VERSION=1.9.3 run pyenv-version-name - assert_success "1.9.3" + PYENV_VERSION=3.3.3 run pyenv-version-name + assert_success "3.3.3" } @test "local file has precedence over global" { - create_version "1.8.7" - create_version "1.9.3" + create_version "2.7.6" + create_version "3.3.3" - cat > "${PYENV_ROOT}/version" <<<"1.8.7" + cat > "${PYENV_ROOT}/version" <<<"2.7.6" run pyenv-version-name - assert_success "1.8.7" + assert_success "2.7.6" - cat > ".python-version" <<<"1.9.3" + cat > ".python-version" <<<"3.3.3" run pyenv-version-name - assert_success "1.9.3" + assert_success "3.3.3" } @test "missing version" { @@ -53,13 +53,13 @@ setup() { } @test "version with prefix in name" { - create_version "1.8.7" - cat > ".python-version" <<<"python-1.8.7" + create_version "2.7.6" + cat > ".python-version" <<<"python-2.7.6" run pyenv-version-name assert_success assert_output < ".python-version" <<<"1.9.3" + create_version "3.3.3" + cat > ".python-version" <<<"3.3.3" run pyenv-version - assert_success "1.9.3 (set by ${PWD}/.python-version)" + assert_success "3.3.3 (set by ${PWD}/.python-version)" } @test "set by global file" { - create_version "1.9.3" - cat > "${PYENV_ROOT}/version" <<<"1.9.3" + create_version "3.3.3" + cat > "${PYENV_ROOT}/version" <<<"3.3.3" run pyenv-version - assert_success "1.9.3 (set by ${PYENV_ROOT}/version)" + assert_success "3.3.3 (set by ${PYENV_ROOT}/version)" } diff --git a/test/versions.bats b/test/versions.bats index 44fad1de..840a0adc 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -32,84 +32,84 @@ stub_system_python() { @test "single version installed" { stub_system_python - create_version "1.9" + create_version "3.3" run pyenv-versions assert_success assert_output < "${PYENV_ROOT}/version" <<<"1.9.3" + create_version "3.3.3" + create_version "3.4.0" + cat > "${PYENV_ROOT}/version" <<<"3.3.3" run pyenv-versions assert_success assert_output < ".python-version" <<<"1.9.3" + create_version "3.3.3" + create_version "3.4.0" + cat > ".python-version" <<<"3.3.3" run pyenv-versions assert_success assert_output <