mirror of
https://github.com/pyenv/pyenv.git
synced 2026-09-10 07:36:16 -04:00
tests: add file names to TAP output
by using a customized formatter
This commit is contained in:
parent
14830b18bf
commit
57f1df294b
12
Makefile
12
Makefile
|
|
@ -62,7 +62,8 @@ $(TEST_PYTHON_BUILD_DOCKER_TARGETS): $(TEST_PYTHON_BUILD_DOCKER_PREFIX)-% : $(TE
|
|||
$${CI+-e CI="$${CI}"} \
|
||||
$(INTERACTIVE) \
|
||||
$(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)
|
||||
$(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}"} \
|
||||
$(INTERACTIVE) \
|
||||
$(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
|
||||
.PHONY: $(TEST_BATS_IMAGE_PREFIX)
|
||||
|
|
@ -120,10 +122,12 @@ test-unit: bats
|
|||
PATH="./bats/bin:$$PATH" test/run
|
||||
|
||||
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
|
||||
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)
|
||||
bats-$(TEST_BATS_VERSION):
|
||||
|
|
|
|||
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
|
||||
2
test/run
2
test/run
|
|
@ -6,4 +6,4 @@ if [ -n "$PYENV_NATIVE_EXT" ]; then
|
|||
make -C src
|
||||
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}
|
||||
|
|
|
|||
Loading…
Reference in a new issue