Commit 27e336af authored by Michael Hanselmann's avatar Michael Hanselmann

Add make target to generate unittest coverage report

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent a9105b24
......@@ -41,6 +41,7 @@
# doc
/doc/api
/doc/build
/doc/coverage
/doc/html
/doc/install-quick.rst
/doc/news.rst
......
......@@ -54,7 +54,7 @@ MAINTAINERCLEANFILES = \
doc/news.rst
maintainer-clean-local:
rm -rf doc/api doc/html
rm -rf doc/api doc/html doc/coverage
CLEANFILES = \
autotools/replace_vars.sed \
......@@ -245,6 +245,7 @@ EXTRA_DIST = \
autotools/check-python-code \
autotools/check-man \
autotools/docbook-wrapper \
autotools/gen-coverage \
$(RUN_IN_TEMPDIR) \
daemons/daemon-util.in \
daemons/ganeti-cleaner.in \
......@@ -340,9 +341,12 @@ nodist_TESTS =
TESTS = $(dist_TESTS) $(nodist_TESTS)
TESTS_ENVIRONMENT = \
PYTHONPATH=. TOP_SRCDIR=$(abs_top_srcdir) \
$(RUN_IN_TEMPDIR) $(PYTHON)
# Environment for all tests
PLAIN_TESTS_ENVIRONMENT = \
PYTHONPATH=. TOP_SRCDIR=$(abs_top_srcdir) PYTHON=$(PYTHON) $(RUN_IN_TEMPDIR)
# Environment for tests run by automake
TESTS_ENVIRONMENT = $(PLAIN_TESTS_ENVIRONMENT) $(PYTHON)
all_python_code = \
$(dist_sbin_SCRIPTS) \
......@@ -535,4 +539,13 @@ TAGS: $(BUILT_SOURCES)
-path 'daemons/ganeti-*' -o -path 'tools/*' | \
etags -
.PHONY: coverage
coverage: $(BUILT_SOURCES) $(TESTS)
set -e; \
mkdir -p doc/coverage; \
COVERAGE_FILE=$(CURDIR)/doc/coverage/data \
TEXT_COVERAGE=$(CURDIR)/doc/coverage/report.txt \
HTML_COVERAGE=$(CURDIR)/doc/coverage \
$(PLAIN_TESTS_ENVIRONMENT) $(abs_top_srcdir)/autotools/gen-coverage $(TESTS)
# vim: set noet :
#!/bin/bash
#
# Copyright (C) 2010 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
set -e
: ${COVERAGE:=coverage}
: ${PYTHON:=python}
: ${COVERAGE_FILE:?}
: ${TEXT_COVERAGE:?}
omit=$($PYTHON -c 'import sys;
print " ".join(["--omit=%s/" % i for i in
set([sys.prefix, sys.exec_prefix])])')
$COVERAGE erase
for script; do
$COVERAGE run --branch --append $script
done
echo "Writing text report to $TEXT_COVERAGE ..." >&2
$COVERAGE report $omit | tee "$TEXT_COVERAGE"
if [[ -n "$HTML_COVERAGE" ]]; then
echo "Generating HTML report in $HTML_COVERAGE ..." >&2
$COVERAGE html $omit -d "$HTML_COVERAGE"
fi
......@@ -15,6 +15,9 @@ Most dependencies from :doc:`install-quick`, plus:
(tested with version 0.6.1)
- `graphviz <http://www.graphviz.org/>`_
To generate unittest coverage reports (``make coverage``), `coverage
<http://pypi.python.org/pypi/coverage>`_ needs to be installed.
Configuring for development
---------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment