Mercurial > hg
changeset 2068:4a49daa3a40c
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.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Thu, 13 Apr 2006 17:11:04 -0700 |
parents | 3094becfd8e8 |
children | 15ec724ba351 |
files | .hgignore tests/run-tests |
diffstat | 2 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Thu Apr 13 17:06:57 2006 -0700 +++ b/.hgignore Thu Apr 13 17:11:04 2006 -0700 @@ -8,6 +8,7 @@ *.pyc *.swp *.prof +tests/.coverage* tests/*.err build dist
--- a/tests/run-tests Thu Apr 13 17:06:57 2006 -0700 +++ b/tests/run-tests Thu Apr 13 17:11:04 2006 -0700 @@ -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 @@ 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 @@ 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