#!/usr/bin/env bats load test_helper # Make the build deterministic: `pyenv-install' just creates the prefix, and # the platform tools report a fixed Linux target so the real `save' and # `generate-installer' behave the same on any test host. stub_build_environment() { create_stub pyenv-install 'echo "${0##*/} $*"; mkdir -p "${PYENV_ROOT}/versions/${1##*:}/bin"' create_stub pyenv-latest 'while (($#)); do case "$1" in -f|-k);; *)break;; esac; shift; done; echo "$*"' create_stub uname 'case "$1" in -s) echo Linux;; -m) echo x86_64;; esac' create_stub getconf 'echo "glibc 2.17"' create_stub readelf true } @test "-v|--verbose runs pyenv install verbosely" { stub_build_environment create_stub pyenv-binary-save true create_stub pyenv-binary-generate-installer true for opt in "" -v --verbose; do run pyenv-binary-package $opt 3.12.7:3.12.7-test \ --archive-base-url http://example.com/binaries assert_success "pyenv-install ${opt:+--verbose }3.12.7:3.12.7-test" done } @test "completions" { create_stub pyenv-install 'echo "${0##*/} $*"' run pyenv-binary-package --complete assert_success < custom-python run pyenv-binary-package "${BATS_TEST_TMPDIR}/custom-python:custom-build" \ --archive-base-url http://example.com/binaries assert_success run grep '^source_version=' custom-build.meta assert_success "source_version=custom-python" } @test "rejects an entry name containing a slash" { run pyenv-binary-package "3.12.7:foo/bar" --archive-base-url http://x/b assert_failure "pyenv-binary: invalid entry name \`foo/bar'" } @test "rejects \`latest' as an entry name" { run pyenv-binary-package 3.12:latest --archive-base-url http://x/b assert_failure "pyenv-binary: \`latest' cannot be used as an entry name" } @test "packages on macOS" { create_stub uname 'case "$1" in -s) echo Darwin;; -m) echo arm64;; esac' create_stub pyenv-latest 'echo 3.12.7' create_stub pyenv-install 'echo install' create_stub pyenv-binary-save 'echo save' create_stub pyenv-binary-generate-installer 'echo generate-installer' run pyenv-binary-package 3.12.7:3.12.7-test --archive-base-url http://x/b assert_success "install save generate-installer" } @test "writes the archive, metadata and definition under the entry name (integration)" { stub_build_environment cd "${BATS_TEST_TMPDIR}" run pyenv-binary-package 3.12.7:3.12.7-test \ --archive-base-url http://example.com/binaries assert_success assert [ -d "${PYENV_ROOT}/versions/3.12.7-test" ] assert [ -f "${BATS_TEST_TMPDIR}/3.12.7-test.tar.xz" ] assert [ -f "${BATS_TEST_TMPDIR}/3.12.7-test.meta" ] run grep '^ARCHIVE_URL=' "${BATS_TEST_TMPDIR}/3.12.7-test" assert_success "ARCHIVE_URL=http://example.com/binaries/3.12.7-test.tar.xz" } @test "correctly joins archive base url with a trailing slash" { 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 \ --archive-base-url http://example.com/binaries/ assert_success assert_line "pyenv-binary-generate-installer --archive-url http://example.com/binaries/3.12.7-test.tar.xz" }