1#!/bin/sh 2 3prog=$(basename $0) 4 5# Expect to be run from the parent lit directory. 6if [ ! -f setup.py ] || [ ! -d lit ]; then 7 printf 1>&2 "%s: expected to be run from base lit directory\n" "$prog" 8 exit 1 9fi 10 11# Parse command line arguments. 12if [ "$1" = "--generate-html" ]; then 13 GENERATE_HTML=1 14 shift 15fi 16 17# If invoked with no arguments, run all the tests. 18if [ $# = "0" ]; then 19 set -- "tests" 20fi 21 22# Check that the active python has been modified to enable coverage in its 23# sitecustomize. 24if ! python -c \ 25 'import sitecustomize, sys; sys.exit("coverage" not in dir(sitecustomize))' \ 26 >/dev/null 2>&1; then 27 printf 1>&2 "error: active python does not appear to enable coverage in its 'sitecustomize.py'\n" 28 exit 1 29fi 30 31# First, remove any existing coverage data files. 32rm -f tests/.coverage 33find tests -name .coverage.\* -exec rm {} \; 34 35# Next, run the tests. 36lit -sv --param check-coverage=1 "$@" 37 38# Next, move all the data files from subdirectories up. 39find tests/* -name .coverage.\* -exec mv {} tests \; 40 41# Combine all the data files. 42(cd tests && python -m coverage combine) 43 44# Finally, generate the report. 45(cd tests && python -m coverage report) 46 47# Generate the HTML report, if requested. 48if [ ! -z "$GENERATE_HTML" ]; then 49 (cd tests && python -m coverage html) 50fi 51