Work with Git entirely in a test repo

This commit is contained in:
Ivan Pozdeev 2025-12-23 19:14:47 +03:00
parent c02421b51d
commit 7af5ea261e
No known key found for this signature in database
GPG key ID: FB6A628DCF06DCD7
3 changed files with 9 additions and 7 deletions

View file

@ -265,7 +265,8 @@ for DEFINITION in "${DEFINITIONS[@]}"; do
echo "See all available versions with \`pyenv install --list'."
echo
echo -n "If the version you need is missing, try upgrading pyenv"
if [[ command -v brew && "${_PYENV_INSTALL_PREFIX}" == "$(brew --prefix)/"* ]; then
declare brew_prefix
if brew_prefix="$(brew --prefix 2>/dev/null)" && [[ $_PYENV_INSTALL_PREFIX/ == "$brew_prefix/"* ]]; then
printf ":\n\n"
echo " brew update && brew upgrade pyenv"
elif [ -d "${_PYENV_INSTALL_PREFIX}/.git" ]; then

View file

@ -141,6 +141,9 @@ OUT
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
mkdir "$BATS_TEST_TMPDIR/.git"
#Faking the Pyenv installation prefix may break things.
# May have to move some dependent stuff into the fake root for the code to find it
# or introduce an overriding test variable in the code specifically for the hint.
_PYENV_INSTALL_PREFIX="$BATS_TEST_TMPDIR" run pyenv-install 2.7.9
assert_failure
assert_output <<OUT
@ -161,7 +164,7 @@ OUT
}
@test "homebrew upgrade instructions given when pyenv is homebrew-installed" {
stub brew "--prefix : echo '${BATS_TEST_TMPDIR}'"
stub brew "--prefix : echo '${_PYENV_INSTALL_PREFIX}'"
stub_python_build_lib
stub_python_build 'echo ERROR >&2 && exit 2' \
"--definitions : true"

View file

@ -3,8 +3,9 @@
load test_helper
_setup() {
export GIT_DIR="${PYENV_TEST_DIR}/.git"
mkdir -p "$GIT_DIR"
export GIT_DIR="${PYENV_TEST_DIR}"
export GIT_WORK_TREE="$GIT_DIR"
git init --quiet
git config user.name "Tester"
git config user.email "tester@test.local"
cd "$PYENV_TEST_DIR"
@ -22,7 +23,6 @@ git_commit() {
}
@test "doesn't read version from non-pyenv repo" {
git init
git remote add origin https://github.com/homebrew/homebrew.git
git_commit
git tag v1.0
@ -33,7 +33,6 @@ git_commit() {
}
@test "reads version from git repo" {
git init
git remote add origin https://github.com/pyenv/pyenv.git
git_commit
git tag v0.4.1
@ -45,7 +44,6 @@ git_commit() {
}
@test "prints default version if no tags in git repo" {
git init
git remote add origin https://github.com/pyenv/pyenv.git
git_commit