mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-14 06:23:52 -05:00
init: fix shell detection when invoked from a script
- fixes `ps` command to lookup parent process - adds `assert_output_contains_not` test helper Ref: https://github.com/yyuu/pyenv/issues/373
This commit is contained in:
@@ -4,12 +4,29 @@ load test_helper
|
||||
|
||||
@test "detect parent shell" {
|
||||
unset PYENV_SHELL
|
||||
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
|
||||
SHELL=/bin/false run pyenv-virtualenv-init -
|
||||
assert_success
|
||||
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
|
||||
}
|
||||
|
||||
@test "detect parent shell from script (sh)" {
|
||||
unset PYENV_SHELL
|
||||
printf '#!/bin/sh\necho "$(pyenv-virtualenv-init -)"' > ${BATS_TEST_DIRNAME}/script.sh
|
||||
chmod +x ${BATS_TEST_DIRNAME}/script.sh
|
||||
run ${BATS_TEST_DIRNAME}/script.sh
|
||||
assert_success
|
||||
assert_output_contains_not ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
|
||||
}
|
||||
|
||||
@test "detect parent shell from script (bash)" {
|
||||
unset PYENV_SHELL
|
||||
printf '#!/bin/bash\necho "$(pyenv-virtualenv-init -)"' > ${BATS_TEST_DIRNAME}/script.sh
|
||||
chmod +x ${BATS_TEST_DIRNAME}/script.sh
|
||||
run ${BATS_TEST_DIRNAME}/script.sh
|
||||
assert_success
|
||||
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
|
||||
}
|
||||
|
||||
@test "sh-compatible instructions" {
|
||||
run pyenv-virtualenv-init bash
|
||||
assert [ "$status" -eq 1 ]
|
||||
|
||||
@@ -97,6 +97,16 @@ assert_output_contains() {
|
||||
}
|
||||
}
|
||||
|
||||
assert_output_contains_not() {
|
||||
local expected="$1"
|
||||
echo "$output" | grep -F "$expected" >/dev/null && {
|
||||
{ echo "expected output to not contain $expected"
|
||||
echo "actual: $output"
|
||||
} | flunk; return
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
create_executable() {
|
||||
mkdir -p "${PYENV_ROOT}/versions/$1/bin"
|
||||
touch "${PYENV_ROOT}/versions/$1/bin/$2"
|
||||
|
||||
Reference in New Issue
Block a user