You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mitogen/run_tests

75 lines
1.9 KiB
Bash

#!/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
if [ ! "$UNIT2" ]; then
UNIT2="$(which unit2)"
fi
[ "$NOCOVERAGE" ] || coverage erase
# First run overwites coverage output.
[ "$SKIP_MITOGEN" ] || {
if [ ! "$NOCOVERAGE" ]; then
coverage run "${UNIT2}" discover \
--start-directory "tests" \
--pattern '*_test.py' \
"$@"
else
"${UNIT2}" 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 "${UNIT2}" discover \
--start-directory "tests/ansible" \
--pattern '*_test.py' \
"$@"
else
coverage run -a "${UNIT2}" discover \
--start-directory "tests/ansible" \
--pattern '*_test.py' \
"$@"
fi
ANSIBLE_TEST_STATUS=$?
}
[ "$NOCOVERAGE" ] || coverage html
[ "$NOCOVERAGE" ] || echo coverage report is at "file://$(pwd)/htmlcov/index.html"
# Exit with a non-zero status if any test run did so
exit "$(max $MITOGEN_TEST_STATUS $ANSIBLE_TEST_STATUS)"