1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#!/usr/bin/env bash
# From https://unix.stackexchange.com/a/432145
# Return the maximum of one or more integer arguments
max() {
local max number
max="$1"
for number in "${@:2}"; do
if ((number > max)); then
max="$number"
fi
done
printf '%d\n' "$max"
}
echo '----- ulimits -----'
ulimit -a
echo '-------------------'
echo
# Don't use errexit, so coverage report is still generated when tests fail
set -o pipefail
NOCOVERAGE="${NOCOVERAGE:-}"
NOCOVERAGE_ERASE="${NOCOVERAGE_ERASE:-$NOCOVERAGE}"
NOCOVERAGE_REPORT="${NOCOVERAGE_REPORT:-$NOCOVERAGE}"
if [ ! "$NOCOVERAGE_ERASE" ]; then
coverage erase
fi
# First run overwites coverage output.
[ "$SKIP_MITOGEN" ] || {
if [ ! "$NOCOVERAGE" ]; then
coverage run -a -m unittest discover \
--start-directory "tests" \
--pattern '*_test.py' \
"$@"
else
python -m unittest discover \
--start-directory "tests" \
--pattern '*_test.py' \
"$@"
fi
MITOGEN_TEST_STATUS=$?
}
# Second run appends. This is since 'discover' treats subdirs as packages and
# the 'ansible' subdir shadows the real Ansible package when it contains
# __init__.py, so hack around it by just running again with 'ansible' as the
# start directory. Alternative seems to be renaming tests/ansible/ and making a
# mess of Git history.
[ "$SKIP_ANSIBLE" ] || {
export PYTHONPATH=`pwd`/tests:$PYTHONPATH
if [ ! "$NOCOVERAGE" ]; then
coverage run -a -m unittest discover \
--start-directory "tests/ansible" \
--pattern '*_test.py' \
"$@"
else
python -m unittest discover \
--start-directory "tests/ansible" \
--pattern '*_test.py' \
"$@"
fi
ANSIBLE_TEST_STATUS=$?
}
if [ ! "$NOCOVERAGE_REPORT" ]; then
coverage html
echo "coverage report is at file://$(pwd)/htmlcov/index.html"
fi
# Exit with a non-zero status if any test run did so
exit "$(max $MITOGEN_TEST_STATUS $ANSIBLE_TEST_STATUS)"
|