Make testing within Docker containers easier (#56)

Make testing within Docker containers easier
This commit is contained in:
Adam Spiers 2019-06-28 20:46:15 +01:00 committed by GitHub
commit d991dfbbf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 6 deletions

View file

@ -22,11 +22,12 @@
. /usr/local/perlbrew/etc/bashrc
# Standard safety protocol
set -euf -o pipefail
set -ef -o pipefail
IFS=$'\n\t'
for p_version in $(perlbrew list | sed 's/ //g'); do
perlbrew use $p_version
test_perl_version () {
perl_version="$1"
perlbrew use $perl_version
echo $(perl --version)
@ -40,6 +41,33 @@ for p_version in $(perlbrew list | sed 's/ //g'); do
make distcheck
perl Build.PL && ./Build build && cover -test
./Build distcheck
done
}
make distclean
if [[ -n "$LIST_PERL_VERSIONS" ]]; then
echo "Listing Perl versions available from perlbrew ..."
perlbrew list
elif [[ -z "$PERL_VERSION" ]]; then
echo "Testing all versions ..."
for perl_version in $(perlbrew list | sed 's/ //g'); do
test_perl_version $perl_version
done
make distclean
else
echo "Testing with Perl $PERL_VERSION"
# Test a specific version requested via $PERL_VERSION environment
# variable. Make sure set -e doesn't cause us to bail on failure
# before we start an interactive shell.
test_perl_version $PERL_VERSION || :
# N.B. Don't distclean since we probably want to debug this Perl
# version interactively.
cat <<EOF
To run a specific test, type something like:
perl -Ilib -Ibin -It t/cli_options.t
Code can be edited on the host and will immediately take effect inside
this container.
EOF
bash
fi

View file

@ -2,7 +2,36 @@
# Test Stow across multiple Perl versions, by executing the
# Docker image built via build-docker.sh.
#
# Usage: ./test-docker.sh [list | PERL_VERSION]
#
# If the first argument is 'list', list available Perl versions.
# If the first argument is a Perl version, test just that version interactively.
# If no arguments are given test all available Perl versions non-interactively.
version=$( tools/get-version )
docker run --rm -it -v $(pwd):$(pwd) -w $(pwd) stowtest:$version
if [ -z "$1" ]; then
# Normal non-interactive run
docker run --rm -it \
-v $(pwd):$(pwd) \
-w $(pwd) \
stowtest:$version
elif [ "$1" == list ]; then
# List available Perl versions
docker run --rm -it \
-v $(pwd):$(pwd) \
-v $(pwd)/docker/run-stow-tests.sh:/run-stow-tests.sh \
-w $(pwd) \
-e LIST_PERL_VERSIONS=1 \
stowtest:$version
else
# Interactive run for testing / debugging a particular version
perl_version="$1"
docker run --rm -it \
-v $(pwd):$(pwd) \
-v $(pwd)/docker/run-stow-tests.sh:/run-stow-tests.sh \
-w $(pwd) \
-e PERL_VERSION=$perl_version \
stowtest:$version
fi