@@ -10,9 +10,8 @@ usage: ${0##*/} [-h] [-b PATTERN] [-c] [-j JOBS] [-n] [-u PATTERN]
1010optional arguments:
1111 -h show this help message and exit
1212 -b PATTERN Only execute black box tests matching PATTERN
13- -c Create HTML coverage report
13+ -c TYPE Create coverage report (html, xml)
1414 -j JOBS Run JOBS tests in parallel (requires GNU parallel)
15- -n Do not record coverage even if python3-coverage is found.
1615 -u PATTERN Only execute unit tests matching PATTERN
1716EOF
1817}
@@ -83,7 +82,6 @@ cd "${0%/*}/.."
8382COVERAGE=
8483FAILED=0
8584RUN_TEST_DIRS=( )
86- GEN_HTML=0
8785RUN_JOBS=
8886unset RUN_UNITTEST_PAT
8987unset RUN_BLACKBOX_PAT
@@ -98,31 +96,8 @@ if [[ $(python3 --version) = "Python 3.9.7" ]] ; then
9896 PYTHONWARNINGS+=" ,ignore::DeprecationWarning"
9997fi
10098
101- # check if python coverage is installed
102- if type -fp coverage3 > /dev/null; then
103- COVERAGE=coverage3
104- elif type -fp python3-coverage > /dev/null; then
105- COVERAGE=python3-coverage
106- fi
107-
108- if [[ -n $COVERAGE ]] ; then
109- # make sure coverage is installed in the current environment
110- if python3 -c " import coverage" 2> /dev/null; then
111- RUN_PYTHON3=" $COVERAGE run --source $PWD /pym --parallel-mode"
112- # The multiprocessing module is incompatible with coverage.py. Enable
113- # the hack in pym/bob/utils.py to still get some data.
114- export ENABLE_COVERAGE_HACK=1
115- else
116- RUN_PYTHON3=python3
117- COVERAGE=
118- echo " coverage3 is installed but not in the current environment" >&2
119- fi
120- else
121- RUN_PYTHON3=python3
122- fi
123-
12499# option processing
125- while getopts " :hb:cj:nu :" opt; do
100+ while getopts " :hb:c:j:u :" opt; do
126101 case $opt in
127102 h)
128103 usage
@@ -132,7 +107,15 @@ while getopts ":hb:cj:nu:" opt; do
132107 RUN_BLACKBOX_PAT=" $OPTARG "
133108 ;;
134109 c)
135- GEN_HTML=1
110+ case " $OPTARG " in
111+ html|xml)
112+ COVERAGE=" $OPTARG "
113+ ;;
114+ * )
115+ echo " Invalid coverage format" >&2
116+ exit 1
117+ ;;
118+ esac
136119 ;;
137120 j)
138121 RUN_JOBS=" $OPTARG "
@@ -151,6 +134,34 @@ while getopts ":hb:cj:nu:" opt; do
151134 esac
152135done
153136
137+ # check if python coverage is installed if coverage is required
138+ if [[ -z $COVERAGE ]] ; then
139+ :
140+ elif type -fp coverage3 > /dev/null; then
141+ RUN_COVERAGE=coverage3
142+ elif type -fp python3-coverage > /dev/null; then
143+ RUN_COVERAGE=python3-coverage
144+ else
145+ echo " Coverage requeted but coverage3 is not installed" >&2
146+ echo " Try 'python3 -m pip install coverage'..." >&2
147+ exit 1
148+ fi
149+
150+ if [[ -n $RUN_COVERAGE ]] ; then
151+ # make sure coverage is installed in the current environment
152+ if python3 -c " import coverage" 2> /dev/null; then
153+ RUN_PYTHON3=" $RUN_COVERAGE run --source $PWD /pym --parallel-mode"
154+ # The multiprocessing module is incompatible with coverage.py. Enable
155+ # the hack in pym/bob/utils.py to still get some data.
156+ export ENABLE_COVERAGE_HACK=1
157+ else
158+ echo " coverage3 is installed but not usable!" >&2
159+ exit 1
160+ fi
161+ else
162+ RUN_PYTHON3=python3
163+ fi
164+
154165# execute everything if nothing was specified
155166if [[ -z ${RUN_UNITTEST_PAT+isset} && -z ${RUN_BLACKBOX_PAT+isset} ]] ; then
156167 RUN_BLACKBOX_PAT=' *'
230241popd > /dev/null
231242
232243# collect coverage
233- if [[ -n $COVERAGE ]]; then
234- $COVERAGE combine $( find test/ -type f -name ' .coverage.*' \
235- -printf ' %h\n' | sort -u)
236- if [[ $GEN_HTML -eq 1 ]] ; then
237- $COVERAGE html
238- fi
244+ if [[ -n $RUN_COVERAGE ]]; then
245+ $RUN_COVERAGE combine $( find test/ -type f -name ' .coverage.*' \
246+ -printf ' %h\n' | sort -u)
247+ $RUN_COVERAGE $COVERAGE
239248fi
240249
241250if [[ $FAILED -gt 127 ]] ; then
0 commit comments