Enable code coverage using the `coverage` package. The top-level stg script tests for the 'COVERAGE_PROCESS_START' environment variable to enable code coverage mode.
Coverage is configured to generate separate .coverage files for each stg process. This strategy allows aggregate coverage to be collected from running the entire test suite. A new 'make coverage' directive is added that invokes the test suite with coverage enabled and collects the per-process .coverage files into a single top-level .coverage file. An html report is generated. The test system is modified so that the generated .coverage files are excluded via the .git/info/exclude file. This required several tests to append to the exclude file instead of overwriting it. Signed-off-by: Peter Grayson <[email protected]> --- .coveragerc | 5 +++++ .gitignore | 2 ++ Makefile | 10 +++++++++- stg | 4 ++++ t/t0002-status.sh | 2 +- t/t3100-reset.sh | 2 +- t/t3101-reset-hard.sh | 2 +- t/t3102-undo.sh | 2 +- t/t3103-undo-hard.sh | 2 +- t/t3104-redo.sh | 2 +- t/t3105-undo-external-mod.sh | 2 +- t/t3200-non-ascii-filenames.sh | 2 +- t/test-lib.sh | 1 + 13 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..2680522b --- /dev/null +++ b/.coveragerc @@ -0,0 +1,5 @@ +[run] +source = stgit +branch = True +parallel = True +data_file = .coverage diff --git a/.gitignore b/.gitignore index 70fabe34..e0fc0816 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ snapshot.sh stgit-completion.bash ChangeLog .tox +htmlcov/ +.coverage diff --git a/Makefile b/Makefile index b05f9f3b..c5c0d513 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,14 @@ test_patches: stg goto $$patch && $(MAKE) test || break; \ done +coverage: + $(PYTHON) -m coverage run setup.py build + COVERAGE_PROCESS_START=$(PWD)/.coveragerc $(MAKE) -C t all + $(PYTHON) -m coverage combine $$(find . -name '.coverage.*') + $(PYTHON) -m coverage html --title="stgit coverage" + $(PYTHON) -m coverage report + @echo "HTML coverage report: file://$(PWD)/htmlcov/index.html" + clean: for dir in Documentation t; do \ $(MAKE) -C $$dir clean; \ @@ -47,4 +55,4 @@ TAGS: ctags -e -R stgit/* .PHONY: all install doc install-doc install-html test test_patches \ - clean tags TAGS + coverage clean tags TAGS diff --git a/stg b/stg index 5f0487af..9cbaed2a 100755 --- a/stg +++ b/stg @@ -39,4 +39,8 @@ if bin == 'bin' and prefix != sys.prefix: from stgit.main import main if __name__ == '__main__': + if os.environ.get('COVERAGE_PROCESS_START'): + import coverage + coverage.process_startup() + main() diff --git a/t/t0002-status.sh b/t/t0002-status.sh index 619d5f4e..433b2d6f 100755 --- a/t/t0002-status.sh +++ b/t/t0002-status.sh @@ -11,7 +11,7 @@ Test that "stg status" works.' stg init # Ignore our own output files. -cat > .git/info/exclude <<EOF +cat >> .git/info/exclude <<EOF /expected.txt /output.txt EOF diff --git a/t/t3100-reset.sh b/t/t3100-reset.sh index 61f303df..cbd4a11d 100755 --- a/t/t3100-reset.sh +++ b/t/t3100-reset.sh @@ -5,7 +5,7 @@ test_description='Simple test cases for "stg reset"' . ./test-lib.sh # Ignore our own output files. -cat > .git/info/exclude <<EOF +cat >> .git/info/exclude <<EOF /expected.txt EOF diff --git a/t/t3101-reset-hard.sh b/t/t3101-reset-hard.sh index 85b5f46a..b279a934 100755 --- a/t/t3101-reset-hard.sh +++ b/t/t3101-reset-hard.sh @@ -5,7 +5,7 @@ test_description='Simple test cases for "stg reset"' . ./test-lib.sh # Ignore our own output files. -cat > .git/info/exclude <<EOF +cat >> .git/info/exclude <<EOF /expected.txt /actual.txt EOF diff --git a/t/t3102-undo.sh b/t/t3102-undo.sh index 010a63dc..c86e2e08 100755 --- a/t/t3102-undo.sh +++ b/t/t3102-undo.sh @@ -5,7 +5,7 @@ test_description='Simple test cases for "stg undo"' . ./test-lib.sh # Ignore our own output files. -cat > .git/info/exclude <<EOF +cat >> .git/info/exclude <<EOF /expected.txt EOF diff --git a/t/t3103-undo-hard.sh b/t/t3103-undo-hard.sh index f91b8c17..a758eab4 100755 --- a/t/t3103-undo-hard.sh +++ b/t/t3103-undo-hard.sh @@ -5,7 +5,7 @@ test_description='Simple test cases for "stg undo"' . ./test-lib.sh # Ignore our own output files. -cat > .git/info/exclude <<EOF +cat >> .git/info/exclude <<EOF /expected.txt /actual.txt EOF diff --git a/t/t3104-redo.sh b/t/t3104-redo.sh index 3d3c617f..ced6c4e2 100755 --- a/t/t3104-redo.sh +++ b/t/t3104-redo.sh @@ -5,7 +5,7 @@ test_description='Simple test cases for "stg redo"' . ./test-lib.sh # Ignore our own output files. -cat > .git/info/exclude <<EOF +cat >> .git/info/exclude <<EOF /expected.txt EOF diff --git a/t/t3105-undo-external-mod.sh b/t/t3105-undo-external-mod.sh index 19801676..880dcd58 100755 --- a/t/t3105-undo-external-mod.sh +++ b/t/t3105-undo-external-mod.sh @@ -5,7 +5,7 @@ test_description='Undo external modifications of the stack' . ./test-lib.sh # Ignore our own output files. -cat > .git/info/exclude <<EOF +cat >> .git/info/exclude <<EOF /expected.txt /head?.txt EOF diff --git a/t/t3200-non-ascii-filenames.sh b/t/t3200-non-ascii-filenames.sh index 748892a0..82bd6e97 100755 --- a/t/t3200-non-ascii-filenames.sh +++ b/t/t3200-non-ascii-filenames.sh @@ -4,7 +4,7 @@ test_description='Handle files with non-ASCII characters in their names' . ./test-lib.sh # Ignore our own output files. -cat > .git/info/exclude <<EOF +cat >> .git/info/exclude <<EOF /expected.txt /output.txt EOF diff --git a/t/test-lib.sh b/t/test-lib.sh index 1f5a90d4..57cd131f 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -339,6 +339,7 @@ test_create_repo () { git commit-tree $(git write-tree) >.git/refs/heads/master 2>&4 || \ error "cannot run git commit" mv .git/hooks .git/hooks-disabled + echo ".coverage.*" >> .git/info/exclude cd "$owd" } -- 2.12.0 _______________________________________________ stgit-users mailing list [email protected] https://mail.gna.org/listinfo/stgit-users
