pyenv-binary-package: refactor tests

* make them more human-readable
* don't double-test external code outside of integration tests
This commit is contained in:
Ivan Pozdeev 2026-08-10 20:31:00 +03:00
parent f9ffb73a7e
commit 9962f8cb39

View File

@ -24,17 +24,15 @@ stub_build_environment() {
done done
} }
@test "completion lists the option and definitions provided by another plugin" { @test "completions" {
mkdir -p "${PYENV_ROOT}/plugins/example/share/python-build" create_stub pyenv-install 'echo "${0##*/} $*"'
touch "${PYENV_ROOT}/plugins/example/share/python-build/3.12.7-example"
PATH="${BATS_TEST_DIRNAME}/../../python-build/bin:${PATH}"
run pyenv-binary-package --complete run pyenv-binary-package --complete
assert_success assert_success <<!
assert_line "--archive-base-url" --archive-base-url
assert_line "--verbose" --verbose
assert_line "3.12.7-example" pyenv-install --list --bare
refute_line "Available versions:" !
} }
@test "fails with no arguments" { @test "fails with no arguments" {
@ -89,7 +87,7 @@ stub_build_environment() {
assert_failure "pyenv-binary: macOS archives are not supported yet" assert_failure "pyenv-binary: macOS archives are not supported yet"
} }
@test "writes the archive, metadata and definition under the entry name" { @test "writes the archive, metadata and definition under the entry name (integration)" {
stub_build_environment stub_build_environment
cd "${BATS_TEST_TMPDIR}" cd "${BATS_TEST_TMPDIR}"
@ -103,12 +101,24 @@ stub_build_environment() {
assert_success "ARCHIVE_URL=http://example.com/binaries/3.12.7-test.tar.gz" assert_success "ARCHIVE_URL=http://example.com/binaries/3.12.7-test.tar.gz"
} }
@test "strips a trailing slash from the archive base url" { @test "correctly joins archive base url with a trailing slash" {
stub_build_environment stub_build_environment
create_stub pyenv-binary-save true
create_stub pyenv-binary-generate-installer <<'!'
echo -n "${0##*/} "
while (($#)); do
case $1 in
--archive-url)
echo "$1 ${2:?}"
break
;;
esac
shift
done
!
run pyenv-binary-package 3.12.7:3.12.7-test \ run pyenv-binary-package 3.12.7:3.12.7-test \
--archive-base-url http://example.com/binaries/ --archive-base-url http://example.com/binaries/
assert_success assert_success
run grep '^ARCHIVE_URL=' "${BATS_TEST_TMPDIR}/3.12.7-test" assert_line "pyenv-binary-generate-installer --archive-url http://example.com/binaries/3.12.7-test.tar.gz"
assert_success "ARCHIVE_URL=http://example.com/binaries/3.12.7-test.tar.gz"
} }