let run-tests run optional code coverage tests.

to enable, set env var TEST_COVERAGE to non-empty string. run-tests will
print report after running.

after coverage run, file tests/.coverage will contain coverage data. use
tests/coverage.py to get more info, like annotated source code.
This commit is contained in:
Vadim Gelfer 2006-04-13 17:11:04 -07:00
parent 846e9696ac
commit 82f373878f
2 changed files with 30 additions and 1 deletions

View File

@ -8,6 +8,7 @@ syntax: glob
*.pyc
*.swp
*.prof
tests/.coverage*
tests/*.err
build
dist

View File

@ -1,4 +1,9 @@
#!/bin/sh -e
#
# environment variables:
#
# TEST_COVERAGE - set non-empty if you want to print test coverage report
# COVERAGE_STDLIB - set non-empty to report coverage of standard library
LANG="C"; export LANG
LC_CTYPE="C"; export LC_CTYPE
@ -64,7 +69,19 @@ else
fi
cd "$TESTDIR"
BINDIR="$INST/bin"
BINDIR="$INST/bin"; export BINDIR
if [ -n "$TEST_COVERAGE" ]; then
COVERAGE_FILE="$TESTDIR/.coverage"; export COVERAGE_FILE
rm -f "$COVERAGE_FILE"
mv "$BINDIR/hg" "$BINDIR/hg.py"
{
echo '#!/bin/sh'
echo "exec \"${PYTHON-python}\" \"$TESTDIR/coverage.py\"" \
"-x \"$BINDIR/hg.py\" \"\$@\""
} > "$BINDIR/hg"
chmod 700 "$BINDIR/hg"
fi
PATH="$BINDIR:$PATH"; export PATH
if [ -n "$PYTHON" ]; then
{
@ -153,6 +170,17 @@ done
echo
echo "Ran $tests tests, $failed failed."
if [ -n "$TEST_COVERAGE" ]; then
unset PYTHONPATH
$ECHO_N "$BINDIR,$TESTDIR,$HGTMP/test-," > "$HGTMP/omit"
if [ -z "$COVERAGE_STDLIB" ]; then
"${PYTHON-python}" -c 'import sys; print ",".join(sys.path)' \
>> "$HGTMP/omit"
fi
cd "$PYTHONDIR"
"${PYTHON-python}" "$TESTDIR/coverage.py" -r --omit="`cat \"$HGTMP/omit\"`"
fi
if [ $failed -gt 0 ] ; then
exit 1
fi