2018-11-06 13:47:09 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-07-04 17:38:34 +00:00
|
|
|
|
2019-02-09 14:33:26 +00:00
|
|
|
# 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"
|
|
|
|
}
|
|
|
|
|
2018-07-04 17:38:34 +00:00
|
|
|
echo '----- ulimits -----'
|
|
|
|
ulimit -a
|
|
|
|
echo '-------------------'
|
|
|
|
echo
|
|
|
|
|
2019-02-09 14:33:26 +00:00
|
|
|
# Don't use errexit, so coverage report is still generated when tests fail
|
2018-04-01 01:11:37 +00:00
|
|
|
set -o pipefail
|
2018-04-01 00:42:31 +00:00
|
|
|
|
2019-02-09 19:49:01 +00:00
|
|
|
NOCOVERAGE="${NOCOVERAGE:-}"
|
|
|
|
NOCOVERAGE_ERASE="${NOCOVERAGE_ERASE:-$NOCOVERAGE}"
|
|
|
|
NOCOVERAGE_REPORT="${NOCOVERAGE_REPORT:-$NOCOVERAGE}"
|
|
|
|
|
2019-01-23 12:44:08 +00:00
|
|
|
if [ ! "$UNIT2" ]; then
|
|
|
|
UNIT2="$(which unit2)"
|
|
|
|
fi
|
2018-04-01 00:42:31 +00:00
|
|
|
|
2019-02-09 19:49:01 +00:00
|
|
|
if [ ! "$NOCOVERAGE_ERASE" ]; then
|
|
|
|
coverage erase
|
|
|
|
fi
|
2018-10-02 19:42:24 +00:00
|
|
|
|
|
|
|
# First run overwites coverage output.
|
|
|
|
[ "$SKIP_MITOGEN" ] || {
|
2019-01-23 12:44:08 +00:00
|
|
|
if [ ! "$NOCOVERAGE" ]; then
|
2019-02-09 19:49:01 +00:00
|
|
|
coverage run -a "${UNIT2}" discover \
|
2019-01-23 12:44:08 +00:00
|
|
|
--start-directory "tests" \
|
|
|
|
--pattern '*_test.py' \
|
|
|
|
"$@"
|
|
|
|
else
|
|
|
|
"${UNIT2}" discover \
|
|
|
|
--start-directory "tests" \
|
|
|
|
--pattern '*_test.py' \
|
|
|
|
"$@"
|
|
|
|
fi
|
2019-02-09 14:33:26 +00:00
|
|
|
MITOGEN_TEST_STATUS=$?
|
2018-10-02 19:42:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
2019-01-23 12:44:08 +00:00
|
|
|
if [ ! "$NOCOVERAGE" ]; then
|
|
|
|
coverage run -a "${UNIT2}" discover \
|
|
|
|
--start-directory "tests/ansible" \
|
|
|
|
--pattern '*_test.py' \
|
|
|
|
"$@"
|
|
|
|
else
|
2019-02-09 19:47:06 +00:00
|
|
|
"${UNIT2}" discover \
|
2019-01-23 12:44:08 +00:00
|
|
|
--start-directory "tests/ansible" \
|
|
|
|
--pattern '*_test.py' \
|
|
|
|
"$@"
|
|
|
|
fi
|
2019-02-09 14:33:26 +00:00
|
|
|
ANSIBLE_TEST_STATUS=$?
|
2018-10-02 19:42:24 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 19:49:01 +00:00
|
|
|
if [ ! "$NOCOVERAGE_REPORT" ]; then
|
|
|
|
coverage html
|
|
|
|
echo "coverage report is at file://$(pwd)/htmlcov/index.html"
|
|
|
|
fi
|
2019-02-09 14:33:26 +00:00
|
|
|
|
|
|
|
# Exit with a non-zero status if any test run did so
|
|
|
|
exit "$(max $MITOGEN_TEST_STATUS $ANSIBLE_TEST_STATUS)"
|