Code

t/coverage.sh: Reset files not part of the tarball.
[sysdb.git] / t / coverage.sh
1 #! /bin/bash
2 #
3 # SysDB -- t/coverage.sh
4 #
5 # Create a test coverage report for the System DataBase.
7 set -e
9 if ! which lcov || ! which genhtml; then
10         echo "lcov is required in order to generate a test coverage report" >&2
11         exit 1
12 fi
14 cd $( dirname "$0" )/..
16 if test -e t/coverage; then
17         echo "t/coverage exists already; please remove manually" >&2
18         exit 1
19 fi
21 V=$( grep '^PACKAGE_VERSION' Makefile | cut -d' ' -f3 )
22 if test -z "$V"; then
23         echo "Unable to determine package version" >&2
24         exit 1
25 fi
27 make dist
29 tmpdir=$( mktemp -d -t )
30 trap "rm -rf $tmpdir" EXIT
32 srcdir=$( pwd )
34 cd $tmpdir
35 tar --strip-components=1 -zxf "$srcdir"/sysdb-$V.tar.gz
36 if test -d "$srcdir"/.git/; then
37         # copy Git database for version-gen.sh
38         cp -a "$srcdir"/.git .
40         # reset all files which are not part of the tarball
41         # (e.g. .gitignore, .travis.yml which would else cause a "dirty" version)
42         git reset --hard
43 fi
45 ./configure --enable-gcov --disable-shared CFLAGS="-O0 -g"
46 make
48 V1=$( grep '^PACKAGE_VERSION' Makefile | cut -d' ' -f3 )
49 if test -z "$V1"; then
50         # this should not happen
51         V1="$V"
52 fi
54 lcov --base-directory src --directory src --zerocount
55 make test
56 lcov --base-directory src --directory src --no-external \
57         --capture -o sysdb_coverage.info
59 genhtml -o "$srcdir"/t/coverage \
60         -t "SysDB $V1 test coverage" --num-spaces=4 --legend \
61         sysdb_coverage.info