Skip to content

Commit

Permalink
Code coverage reports with covimerage (#1586)
Browse files Browse the repository at this point in the history
* Code coverage reports with covimerage

https://github.com/Vimjas/covimerage

* Small improvements based on blueyed's feedback
  • Loading branch information
arp242 authored Dec 7, 2017
1 parent 539cec6 commit 6366c6e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
plugins = covimerage
data_file = .coverage.covimerage
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
doc/tags
.DS_Store
/doc/tags
/.coverage.covimerage
/coverage.xml
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ notifications:
email: false
matrix:
include:
- env: SCRIPT=test VIM_VERSION=vim-7.4
- env: SCRIPT=test VIM_VERSION=vim-8.0
- env: SCRIPT=test VIM_VERSION=nvim
- env: SCRIPT="test -c" VIM_VERSION=vim-7.4
- env: SCRIPT="test -c" VIM_VERSION=vim-8.0
- env: SCRIPT="test -c" VIM_VERSION=nvim
- env: SCRIPT=lint VIM_VERSION=vim-8.0
install:
- ./scripts/install-vim $VIM_VERSION
- pip install --user vim-vint
- pip install --user vim-vint covimerage codecov
script:
- ./scripts/$SCRIPT $VIM_VERSION
27 changes: 22 additions & 5 deletions scripts/run-vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ set -euC
vimgodir=$(cd -P "$(dirname "$0")/.." > /dev/null && pwd)
cd "$vimgodir"

coverage=0
while getopts "c" option; do
case "$option" in
c) coverage=1; ;;
esac
done
shift $((OPTIND - 1))

if [ -z "${1:-}" ]; then
echo "unknown version: '${1:-}'"
echo "First argument must be 'vim-7.4', 'vim-8.0', or 'nvim'."
Expand All @@ -23,11 +31,20 @@ if [ ! -f "$dir/bin/vim" ]; then
exit 1
fi

$dir/bin/vim --noplugin -u NONE -N \
+"set shm+=WAFI rtp=$dir/share/vim/vimgo packpath=$dir/share/vim/vimgo,$vimgodir" \
+'filetype plugin indent on' \
+'packloadall!' \
"$@"
if [ $coverage -eq 1 ]; then
covimerage -q run --report-file /tmp/vim-go-test/cov-profile.txt --append \
$dir/bin/vim --noplugin -u NONE -N \
+"set shm+=WAFI rtp=$dir/share/vim/vimgo packpath=$dir/share/vim/vimgo,$vimgodir" \
+'filetype plugin indent on' \
+'packloadall!' \
"$@"
else
$dir/bin/vim --noplugin -u NONE -N \
+"set shm+=WAFI rtp=$dir/share/vim/vimgo packpath=$dir/share/vim/vimgo,$vimgodir" \
+'filetype plugin indent on' \
+'packloadall!' \
"$@"
fi


# vim:ts=2:sts=2:sw=2:et
23 changes: 18 additions & 5 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ vimgodir=$(cd -P "$(dirname "$0")/.." > /dev/null && pwd)
cd "$vimgodir"

_usage() {
echo "Usage: ${0##*/} [-v] [-r file] vim_version"
echo "Usage: ${0##*/} [-hvc] [-r file] vim_version"
echo
echo "Options:"
echo " -h Show this help"
echo " -v Enable verbose output"
echo " -r Run only the tests from this file"
echo " -c Generate and submit code coverage reports"
echo
}

verbose=0
run=""
while getopts "hvr:" option; do
coverage=""
while getopts "hvcr:" option; do
case "$option" in
h) _usage; exit 0 ;;
v) verbose=1; ;;
r) run=$OPTARG ;;
c) coverage="-c" ;;
*)
echo "error: unknown option '$option'"
_usage
Expand Down Expand Up @@ -54,14 +57,16 @@ fi
### Run tests.
##############
# Clean stale log file.
[ -f '/tmp/vim-go-test/test.log' ] && rm '/tmp/vim-go-test/test.log'
[ -f '/tmp/vim-go-test/FAILED' ] && rm '/tmp/vim-go-test/FAILED'
[ -f '/tmp/vim-go-test/test.log' ] && rm '/tmp/vim-go-test/test.log'
[ -f '/tmp/vim-go-test/FAILED' ] && rm '/tmp/vim-go-test/FAILED'
[ -f '/tmp/vim-go-test/cov-profile.txt' ] && rm '/tmp/vim-go-test/cov-profile.txt'
[ -f '/tmp/vim-go-test/cov-report.txt' ] && rm '/tmp/vim-go-test/cov-report.txt'

# Run the actual tests.
find "$vimgodir" -name '*_test.vim' | while read test_file; do
[ -n "$run" -a "$(basename "$test_file")" != "$run" ] && continue

"$vimgodir/scripts/run-vim" $vim -e \
"$vimgodir/scripts/run-vim" $coverage $vim -e \
+"silent e $test_file" \
+"let g:test_verbose=$verbose" \
-S ./scripts/runtest.vim || (
Expand All @@ -85,4 +90,12 @@ if [ -f "/tmp/vim-go-test/FAILED" ]; then
fi
echo 2>&1 "All tests PASSED"

# Submit coverage reports
if [ -n "$coverage" ]; then
coverage xml --omit '*_test.vim'
codecov -X search gcov pycov -f coverage.xml --required \
--flags "$(echo "$vim" | sed -s 's/[-.]//g')"
rm coverage.xml
fi

# vim:ts=2:sts=2:sw=2:et

0 comments on commit 6366c6e

Please sign in to comment.