2014-01-02 11:48:22 -05:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
mkdir -p "$PYENV_TEST_DIR"
|
|
|
|
cd "$PYENV_TEST_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "reports global file even if it doesn't exist" {
|
|
|
|
assert [ ! -e "${PYENV_ROOT}/version" ]
|
|
|
|
run pyenv-version-origin
|
|
|
|
assert_success "${PYENV_ROOT}/version"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "detects global file" {
|
|
|
|
mkdir -p "$PYENV_ROOT"
|
|
|
|
touch "${PYENV_ROOT}/version"
|
|
|
|
run pyenv-version-origin
|
|
|
|
assert_success "${PYENV_ROOT}/version"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "detects PYENV_VERSION" {
|
|
|
|
PYENV_VERSION=1 run pyenv-version-origin
|
|
|
|
assert_success "PYENV_VERSION environment variable"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "detects local file" {
|
|
|
|
touch .python-version
|
|
|
|
run pyenv-version-origin
|
|
|
|
assert_success "${PWD}/.python-version"
|
|
|
|
}
|
|
|
|
|
create hook: version-origin
Expose a `version-origin` hook.
It is invoked *before* the traditional `rbenv-version-file` lookup. Because `version-origin` is traditionally run immediately after `version-name`, then any plugin hooks that alter `version-name` would have done so. Thus, running `version-origin` prior to printing the origin gives those plugins a chance to alter the `version-origin` to match.
If any of the hooks set `$RBENV_VERSION_ORIGIN`, then it is used as the return value. Otherwise, the existing logic continues to return "environment variable" or "filename" as appropriate.
This change, in conjunction with the `version-name` hook, makes a clean seam by which plugins can inject their own ruby version setting logic. Using this seam, as opposed to altering `$RBENV_COMMAND_PATH` from the `which` hook, means that the version name and origin are set more reliably and so `version`, `version-name`, `version-origin` and `which` all work as expected. Indeed, even PS1 works now.
2015-05-27 23:29:11 -04:00
|
|
|
@test "reports from hook" {
|
2016-03-01 20:39:52 -05:00
|
|
|
create_hook version-origin test.bash <<<"PYENV_VERSION_ORIGIN=plugin"
|
create hook: version-origin
Expose a `version-origin` hook.
It is invoked *before* the traditional `rbenv-version-file` lookup. Because `version-origin` is traditionally run immediately after `version-name`, then any plugin hooks that alter `version-name` would have done so. Thus, running `version-origin` prior to printing the origin gives those plugins a chance to alter the `version-origin` to match.
If any of the hooks set `$RBENV_VERSION_ORIGIN`, then it is used as the return value. Otherwise, the existing logic continues to return "environment variable" or "filename" as appropriate.
This change, in conjunction with the `version-name` hook, makes a clean seam by which plugins can inject their own ruby version setting logic. Using this seam, as opposed to altering `$RBENV_COMMAND_PATH` from the `which` hook, means that the version name and origin are set more reliably and so `version`, `version-name`, `version-origin` and `which` all work as expected. Indeed, even PS1 works now.
2015-05-27 23:29:11 -04:00
|
|
|
|
2016-03-01 20:39:52 -05:00
|
|
|
PYENV_VERSION=1 run pyenv-version-origin
|
create hook: version-origin
Expose a `version-origin` hook.
It is invoked *before* the traditional `rbenv-version-file` lookup. Because `version-origin` is traditionally run immediately after `version-name`, then any plugin hooks that alter `version-name` would have done so. Thus, running `version-origin` prior to printing the origin gives those plugins a chance to alter the `version-origin` to match.
If any of the hooks set `$RBENV_VERSION_ORIGIN`, then it is used as the return value. Otherwise, the existing logic continues to return "environment variable" or "filename" as appropriate.
This change, in conjunction with the `version-name` hook, makes a clean seam by which plugins can inject their own ruby version setting logic. Using this seam, as opposed to altering `$RBENV_COMMAND_PATH` from the `which` hook, means that the version name and origin are set more reliably and so `version`, `version-name`, `version-origin` and `which` all work as expected. Indeed, even PS1 works now.
2015-05-27 23:29:11 -04:00
|
|
|
assert_success "plugin"
|
|
|
|
}
|
2015-12-23 11:26:53 -05:00
|
|
|
|
2015-12-29 11:15:27 -05:00
|
|
|
@test "carries original IFS within hooks" {
|
|
|
|
create_hook version-origin hello.bash <<SH
|
|
|
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
|
|
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
|
|
|
SH
|
|
|
|
|
2016-03-01 20:39:52 -05:00
|
|
|
export PYENV_VERSION=system
|
|
|
|
IFS=$' \t\n' run pyenv-version-origin env
|
2015-12-29 11:15:27 -05:00
|
|
|
assert_success
|
|
|
|
assert_line "HELLO=:hello:ugly:world:again"
|
|
|
|
}
|
|
|
|
|
2016-03-01 20:39:52 -05:00
|
|
|
@test "doesn't inherit PYENV_VERSION_ORIGIN from environment" {
|
|
|
|
PYENV_VERSION_ORIGIN=ignored run pyenv-version-origin
|
|
|
|
assert_success "${PYENV_ROOT}/version"
|
2014-01-02 11:48:22 -05:00
|
|
|
}
|