mirror of
https://github.com/pyenv/pyenv.git
synced 2026-10-03 07:51:06 +09:00
Merge pull request #3525 from native-api/test_improvements
Test improvements
This commit is contained in:
commit
495550afc8
12
Makefile
12
Makefile
@ -62,7 +62,8 @@ $(TEST_PYTHON_BUILD_DOCKER_TARGETS): $(TEST_PYTHON_BUILD_DOCKER_PREFIX)-% : $(TE
|
|||||||
$${CI+-e CI="$${CI}"} \
|
$${CI+-e CI="$${CI}"} \
|
||||||
$(INTERACTIVE) \
|
$(INTERACTIVE) \
|
||||||
$(DOCKER_IMAGE):$(DOCKER_TAG) \
|
$(DOCKER_IMAGE):$(DOCKER_TAG) \
|
||||||
bats $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/python-build/test/$${BATS_FILE_FILTER}
|
bats $${CI:+-F "/code/test/libexec/bats-format-tap-suite"} \
|
||||||
|
$${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/python-build/test/$${BATS_FILE_FILTER}
|
||||||
|
|
||||||
.PHONY: $(TEST_BINARY_DOCKER_PREFIX)
|
.PHONY: $(TEST_BINARY_DOCKER_PREFIX)
|
||||||
$(TEST_BINARY_DOCKER_PREFIX): $(TEST_BINARY_DOCKER_TARGETS)
|
$(TEST_BINARY_DOCKER_PREFIX): $(TEST_BINARY_DOCKER_TARGETS)
|
||||||
@ -84,7 +85,8 @@ $(TEST_BINARY_DOCKER_TARGETS): $(TEST_BINARY_DOCKER_PREFIX)-% : $(TEST_BATS_IMAG
|
|||||||
$${CI+-e CI="$${CI}"} \
|
$${CI+-e CI="$${CI}"} \
|
||||||
$(INTERACTIVE) \
|
$(INTERACTIVE) \
|
||||||
$(DOCKER_IMAGE):$(DOCKER_TAG) \
|
$(DOCKER_IMAGE):$(DOCKER_TAG) \
|
||||||
bats $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/pyenv-binary/test/$${BATS_FILE_FILTER}
|
bats $${CI:+-F "/code/test/libexec/bats-format-tap-suite"} \
|
||||||
|
$${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} plugins/pyenv-binary/test/$${BATS_FILE_FILTER}
|
||||||
|
|
||||||
# Build all images needed for bats under docker
|
# Build all images needed for bats under docker
|
||||||
.PHONY: $(TEST_BATS_IMAGE_PREFIX)
|
.PHONY: $(TEST_BATS_IMAGE_PREFIX)
|
||||||
@ -120,10 +122,12 @@ test-unit: bats
|
|||||||
PATH="./bats/bin:$$PATH" test/run
|
PATH="./bats/bin:$$PATH" test/run
|
||||||
|
|
||||||
test-python-build: bats
|
test-python-build: bats
|
||||||
cd plugins/python-build && $(PWD)/bats/bin/bats $${CI:+--tap} $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
|
cd plugins/python-build && $(PWD)/bats/bin/bats $${CI:+-F "$(PWD)/test/libexec/bats-format-tap-suite"} \
|
||||||
|
$${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
|
||||||
|
|
||||||
test-binary: bats
|
test-binary: bats
|
||||||
cd plugins/pyenv-binary && $(PWD)/bats/bin/bats $${CI:+--tap} $${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
|
cd plugins/pyenv-binary && $(PWD)/bats/bin/bats $${CI:+-F "$(PWD)/test/libexec/bats-format-tap-suite"} \
|
||||||
|
$${BATS_TEST_FILTER:+--filter "$${BATS_TEST_FILTER}"} test/$${BATS_FILE_FILTER}
|
||||||
|
|
||||||
.SECONDARY: bats-$(TEST_BATS_VERSION)
|
.SECONDARY: bats-$(TEST_BATS_VERSION)
|
||||||
bats-$(TEST_BATS_VERSION):
|
bats-$(TEST_BATS_VERSION):
|
||||||
|
|||||||
@ -1276,6 +1276,7 @@ OUT
|
|||||||
mkdir -p "$INSTALL_ROOT/bin"
|
mkdir -p "$INSTALL_ROOT/bin"
|
||||||
touch "$INSTALL_ROOT/bin/package"
|
touch "$INSTALL_ROOT/bin/package"
|
||||||
chmod -w "$INSTALL_ROOT/bin/package"
|
chmod -w "$INSTALL_ROOT/bin/package"
|
||||||
|
skip_if_nonposix_security -w "$INSTALL_ROOT/bin/package"
|
||||||
|
|
||||||
install_fixture definitions/without-checksum
|
install_fixture definitions/without-checksum
|
||||||
assert_success
|
assert_success
|
||||||
@ -1288,6 +1289,7 @@ OUT
|
|||||||
export TMPDIR="${BATS_TEST_TMPDIR}/build"
|
export TMPDIR="${BATS_TEST_TMPDIR}/build"
|
||||||
mkdir -p "$TMPDIR"
|
mkdir -p "$TMPDIR"
|
||||||
chmod -w "$TMPDIR"
|
chmod -w "$TMPDIR"
|
||||||
|
skip_if_nonposix_security -w "$TMPDIR"
|
||||||
|
|
||||||
touch "${BATS_TEST_TMPDIR}/build-definition"
|
touch "${BATS_TEST_TMPDIR}/build-definition"
|
||||||
run python-build "${BATS_TEST_TMPDIR}/build-definition" "$INSTALL_ROOT"
|
run python-build "${BATS_TEST_TMPDIR}/build-definition" "$INSTALL_ROOT"
|
||||||
@ -1298,6 +1300,7 @@ OUT
|
|||||||
export TMPDIR="${BATS_TEST_TMPDIR}/build"
|
export TMPDIR="${BATS_TEST_TMPDIR}/build"
|
||||||
mkdir -p "$TMPDIR"
|
mkdir -p "$TMPDIR"
|
||||||
chmod -x "$TMPDIR"
|
chmod -x "$TMPDIR"
|
||||||
|
skip_if_nonposix_security -x "$TMPDIR"
|
||||||
|
|
||||||
touch "${BATS_TEST_TMPDIR}/build-definition"
|
touch "${BATS_TEST_TMPDIR}/build-definition"
|
||||||
run python-build "${BATS_TEST_TMPDIR}/build-definition" "$INSTALL_ROOT"
|
run python-build "${BATS_TEST_TMPDIR}/build-definition" "$INSTALL_ROOT"
|
||||||
|
|||||||
@ -162,3 +162,7 @@ path_without() {
|
|||||||
echo "$path"
|
echo "$path"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skip_if_nonposix_security() {
|
||||||
|
true "${1:?}" "${2:?}"
|
||||||
|
test "$@" && skip "UNIX permission bits are being overridden" || true
|
||||||
|
}
|
||||||
|
|||||||
45
test/libexec/bats-format-tap-suite
Executable file
45
test/libexec/bats-format-tap-suite
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Wraps Bats TAP formatter, adding file names to the output
|
||||||
|
|
||||||
|
_BATS_FORMATTER_LIB_RELPATH="lib/bats-core/formatter.bash"
|
||||||
|
source "$BATS_ROOT/$_BATS_FORMATTER_LIB_RELPATH"
|
||||||
|
|
||||||
|
|
||||||
|
# `bats-format-tap` calls this fn at the end
|
||||||
|
# We must stub it to be able to source and alter it
|
||||||
|
# https://stackoverflow.com/questions/1203583/how-do-i-rename-a-bash-function
|
||||||
|
eval orig_"$(declare -f bats_parse_internal_extended_tap)"
|
||||||
|
bats_parse_internal_extended_tap() { true; }
|
||||||
|
|
||||||
|
|
||||||
|
# stub sourcing lib from `bats-format-tap`
|
||||||
|
# as that would've reset the stubbed fn
|
||||||
|
FAKE_BATS_ROOT=
|
||||||
|
_trap_rm_fakeroot() { rm -rf "$FAKE_BATS_ROOT"; }
|
||||||
|
REAL_BATS_ROOT="$BATS_ROOT"
|
||||||
|
FAKE_BATS_ROOT=$(mktemp -d)
|
||||||
|
trap _trap_rm_fakeroot ERR EXIT
|
||||||
|
mkdir -p "$(dirname "$FAKE_BATS_ROOT/$_BATS_FORMATTER_LIB_RELPATH")"
|
||||||
|
touch "$FAKE_BATS_ROOT/$_BATS_FORMATTER_LIB_RELPATH"
|
||||||
|
BATS_ROOT="$FAKE_BATS_ROOT"
|
||||||
|
|
||||||
|
source "$REAL_BATS_ROOT/libexec/bats-core/bats-format-tap"
|
||||||
|
|
||||||
|
_trap_rm_fakeroot
|
||||||
|
trap - ERR EXIT
|
||||||
|
BATS_ROOT="$REAL_BATS_ROOT"
|
||||||
|
unset FAKE_BATS_ROOT REAL_BATS_ROOT _trap_rm_fakeroot
|
||||||
|
|
||||||
|
|
||||||
|
# Finally, alter `bats-format-tap`'s logic and invoke it
|
||||||
|
|
||||||
|
# print as "Anything" line
|
||||||
|
bats_tap_stream_suite() { # <file name>
|
||||||
|
# bats only passes --base-name to specific built-in formatters
|
||||||
|
# so we don't have info where the test root is
|
||||||
|
printf '%s\n' "${1##*/}"
|
||||||
|
}
|
||||||
|
|
||||||
|
orig_bats_parse_internal_extended_tap
|
||||||
@ -13,6 +13,8 @@ load test_helper
|
|||||||
@test "non-writable shims directory" {
|
@test "non-writable shims directory" {
|
||||||
mkdir -p "${PYENV_ROOT}/shims"
|
mkdir -p "${PYENV_ROOT}/shims"
|
||||||
chmod -w "${PYENV_ROOT}/shims"
|
chmod -w "${PYENV_ROOT}/shims"
|
||||||
|
skip_if_nonposix_security -w "${PYENV_ROOT}/shims"
|
||||||
|
|
||||||
run pyenv-rehash
|
run pyenv-rehash
|
||||||
assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims isn't writable"
|
assert_failure "pyenv: cannot rehash: ${PYENV_ROOT}/shims isn't writable"
|
||||||
}
|
}
|
||||||
|
|||||||
2
test/run
2
test/run
@ -6,4 +6,4 @@ if [ -n "$PYENV_NATIVE_EXT" ]; then
|
|||||||
make -C src
|
make -C src
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec bats ${CI:+--tap} ${BATS_TEST_FILTER:+--filter "${BATS_TEST_FILTER}"} test/${BATS_FILE_FILTER}
|
exec bats ${CI:+-F "$PWD/test/libexec/bats-format-tap-suite"} ${BATS_TEST_FILTER:+--filter "${BATS_TEST_FILTER}"} test/${BATS_FILE_FILTER}
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
#!/usr/bin/env bats
|
|
||||||
|
|
||||||
load test_helper
|
|
||||||
|
|
||||||
@test "shims linked from elsewhere are chained, other programs at the same paths are unaffected (integration)" {
|
|
||||||
bats_require_minimum_version 1.5.0
|
|
||||||
progname=shimmed_program
|
|
||||||
called_progname=another_program
|
|
||||||
create_alt_executable_in_version "custom" "$progname" <<!
|
|
||||||
echo "called from \$0"
|
|
||||||
pyenv-exec "$called_progname"
|
|
||||||
!
|
|
||||||
pyenv-rehash
|
|
||||||
PATH="$(path_without "$progname" "$called_progname")"
|
|
||||||
for disguised_shim_path in "$BATS_TEST_TMPDIR/"{weird-location,even/weirder/location}; do
|
|
||||||
mkdir -p "$disguised_shim_path"
|
|
||||||
ln -s "${PYENV_ROOT}/shims/$progname" "$disguised_shim_path/$progname"
|
|
||||||
PATH="$PATH:$disguised_shim_path"
|
|
||||||
done
|
|
||||||
create_executable "$disguised_shim_path" "$called_progname" <<!
|
|
||||||
echo "convoluted call success!"
|
|
||||||
!
|
|
||||||
real_path="$BATS_TEST_TMPDIR/real-location"
|
|
||||||
mkdir -p "$real_path"
|
|
||||||
ln -s "${PYENV_ROOT}/versions/custom/bin/$progname" "$real_path/$progname"
|
|
||||||
PATH="$PATH:$real_path"
|
|
||||||
|
|
||||||
run "$progname"
|
|
||||||
assert_success
|
|
||||||
assert_output <<!
|
|
||||||
called from $real_path/$progname
|
|
||||||
convoluted call success!
|
|
||||||
!
|
|
||||||
|
|
||||||
rm "$real_path/$progname"
|
|
||||||
run -127 "$progname"
|
|
||||||
assert_failure
|
|
||||||
assert_line 0 "pyenv: shimmed_program: command not found"
|
|
||||||
}
|
|
||||||
@ -27,3 +27,39 @@ load test_helper
|
|||||||
assert_line "irb"
|
assert_line "irb"
|
||||||
assert_line "python"
|
assert_line "python"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "shims linked from elsewhere are chained, other programs at the same paths are unaffected (integration)" {
|
||||||
|
bats_require_minimum_version 1.5.0
|
||||||
|
progname=shimmed_program
|
||||||
|
called_progname=another_program
|
||||||
|
create_alt_executable_in_version "custom" "$progname" <<!
|
||||||
|
echo "called from \$0"
|
||||||
|
pyenv-exec "$called_progname"
|
||||||
|
!
|
||||||
|
pyenv-rehash
|
||||||
|
PATH="$(path_without "$progname" "$called_progname")"
|
||||||
|
for disguised_shim_path in "$BATS_TEST_TMPDIR/"{weird-location,even/weirder/location}; do
|
||||||
|
mkdir -p "$disguised_shim_path"
|
||||||
|
ln -s "${PYENV_ROOT}/shims/$progname" "$disguised_shim_path/$progname"
|
||||||
|
PATH="$PATH:$disguised_shim_path"
|
||||||
|
done
|
||||||
|
create_executable "$disguised_shim_path" "$called_progname" <<!
|
||||||
|
echo "convoluted call success!"
|
||||||
|
!
|
||||||
|
real_path="$BATS_TEST_TMPDIR/real-location"
|
||||||
|
mkdir -p "$real_path"
|
||||||
|
ln -s "${PYENV_ROOT}/versions/custom/bin/$progname" "$real_path/$progname"
|
||||||
|
PATH="$PATH:$real_path"
|
||||||
|
|
||||||
|
run "$progname"
|
||||||
|
assert_success
|
||||||
|
assert_output <<!
|
||||||
|
called from $real_path/$progname
|
||||||
|
convoluted call success!
|
||||||
|
!
|
||||||
|
|
||||||
|
rm "$real_path/$progname"
|
||||||
|
run -127 "$progname"
|
||||||
|
assert_failure
|
||||||
|
assert_line 0 "pyenv: shimmed_program: command not found"
|
||||||
|
}
|
||||||
|
|||||||
@ -223,3 +223,8 @@ create_hook() {
|
|||||||
cat > "${PYENV_HOOK_PATH}/$1/$2"
|
cat > "${PYENV_HOOK_PATH}/$1/$2"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skip_if_nonposix_security() {
|
||||||
|
true "${1:?}" "${2:?}"
|
||||||
|
test "$@" && skip "UNIX permission bits are being overridden" || true
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user