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