Merge lp:~jpakkane/unity-lens-shopping/coverage into lp:unity-lens-shopping

Proposed by Jussi Pakkanen
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 39
Merged at revision: 38
Proposed branch: lp:~jpakkane/unity-lens-shopping/coverage
Merge into: lp:unity-lens-shopping
Diff against target: 254 lines (+173/-2)
6 files modified
Makefile.am (+1/-0)
Makefile.am.coverage (+48/-0)
configure.ac (+14/-0)
m4/gcov.m4 (+86/-0)
src/Makefile.am (+3/-0)
tests/unit/Makefile.am (+21/-2)
To merge this branch: bzr merge lp:~jpakkane/unity-lens-shopping/coverage
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+148688@code.launchpad.net

Commit message

Added coverage support and targets.

Description of the change

Added coverage support and targets.

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Could you also update test_markup_cleaner_SOURCES in tests/unit/Makefile.am to include all vala files from src/ (except for config.vala and main.vala)? That way coverage report will be more accurate, as for now it's based on the only class that is unit-tested, and this results in unrealistic 100% function coverage...).

Apart from that it works fine.

review: Needs Fixing
39. By Jussi Pakkanen

Added all source files to list so Coverage percentages get printed properly. Also added some flags to make it work.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

I had to add config.vala to the list as well, because otherwise it would not compile.

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good now, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2012-10-01 15:42:22 +0000
3+++ Makefile.am 2013-02-19 08:57:20 +0000
4@@ -39,3 +39,4 @@
5 CLEANFILES = \
6 $(lens_DATA)
7
8+include $(top_srcdir)/Makefile.am.coverage
9
10=== added file 'Makefile.am.coverage'
11--- Makefile.am.coverage 1970-01-01 00:00:00 +0000
12+++ Makefile.am.coverage 2013-02-19 08:57:20 +0000
13@@ -0,0 +1,48 @@
14+
15+# Coverage targets
16+
17+.PHONY: clean-gcno clean-gcda \
18+ coverage-html generate-coverage-html clean-coverage-html \
19+ coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr
20+
21+clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr
22+
23+if HAVE_GCOV
24+
25+clean-gcno:
26+ @echo Removing old coverage instrumentation
27+ -find -name '*.gcno' -print | xargs -r rm
28+
29+clean-gcda:
30+ @echo Removing old coverage results
31+ -find -name '*.gcda' -print | xargs -r rm
32+
33+coverage-html: clean-gcda
34+ -$(MAKE) $(AM_MAKEFLAGS) -k check
35+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html
36+
37+generate-coverage-html:
38+ @echo Collecting coverage data
39+ $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool
40+ LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
41+
42+clean-coverage-html: clean-gcda
43+ -$(LCOV) --directory $(top_builddir) -z
44+ -rm -rf coverage.info coveragereport
45+
46+if HAVE_GCOVR
47+
48+coverage-gcovr: clean-gcda
49+ -$(MAKE) $(AM_MAKEFLAGS) -k check
50+ $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr
51+
52+generate-coverage-gcovr:
53+ @echo Generating coverage GCOVR report
54+ $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml
55+
56+clean-coverage-gcovr: clean-gcda
57+ -rm -rf $(top_builddir)/coverage.xml
58+
59+endif # HAVE_GCOVR
60+
61+endif # HAVE_GCOV
62
63=== modified file 'configure.ac'
64--- configure.ac 2012-10-17 14:47:27 +0000
65+++ configure.ac 2013-02-19 08:57:20 +0000
66@@ -51,6 +51,17 @@
67 INTLTOOL_LENS_RULE='%.lens: %.lens.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< [$]@'
68 AC_SUBST(INTLTOOL_LENS_RULE)
69
70+###########################
71+# gcov coverage reporting
72+###########################
73+m4_include([m4/gcov.m4])
74+AC_TDD_GCOV
75+AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes])
76+AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes])
77+AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes])
78+AC_SUBST(COVERAGE_CFLAGS)
79+AC_SUBST(COVERAGE_LDFLAGS)
80+
81 #####################################################
82 # Check for module and library dependancies
83 #####################################################
84@@ -143,4 +154,7 @@
85 Extra ValaFlags : ${CPPFLAGS} $MAINTAINER_VALAFLAGS
86
87 Lenses Directory: ${LENSESDIR}
88+
89+ Testing
90+ Coverage reporting : ${use_gcov}
91 ])
92
93=== added directory 'm4'
94=== added file 'm4/gcov.m4'
95--- m4/gcov.m4 1970-01-01 00:00:00 +0000
96+++ m4/gcov.m4 2013-02-19 08:57:20 +0000
97@@ -0,0 +1,86 @@
98+# Checks for existence of coverage tools:
99+# * gcov
100+# * lcov
101+# * genhtml
102+# * gcovr
103+#
104+# Sets ac_cv_check_gcov to yes if tooling is present
105+# and reports the executables to the variables LCOV, GCOVR and GENHTML.
106+AC_DEFUN([AC_TDD_GCOV],
107+[
108+ AC_ARG_ENABLE(gcov,
109+ AS_HELP_STRING([--enable-gcov],
110+ [enable coverage testing with gcov]),
111+ [use_gcov=$enableval], [use_gcov=no])
112+
113+ if test "x$use_gcov" = "xyes"; then
114+ # we need gcc:
115+ if test "$GCC" != "yes"; then
116+ AC_MSG_ERROR([GCC is required for --enable-gcov])
117+ fi
118+
119+ # Check if ccache is being used
120+ AC_CHECK_PROG(SHTOOL, shtool, shtool)
121+ case `$SHTOOL path $CC` in
122+ *ccache*[)] gcc_ccache=yes;;
123+ *[)] gcc_ccache=no;;
124+ esac
125+
126+ if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
127+ AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
128+ fi
129+
130+ lcov_version_list="1.6 1.7 1.8 1.9"
131+ AC_CHECK_PROG(LCOV, lcov, lcov)
132+ AC_CHECK_PROG(GENHTML, genhtml, genhtml)
133+
134+ if test "$LCOV"; then
135+ AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [
136+ glib_cv_lcov_version=invalid
137+ lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'`
138+ for lcov_check_version in $lcov_version_list; do
139+ if test "$lcov_version" = "$lcov_check_version"; then
140+ glib_cv_lcov_version="$lcov_check_version (ok)"
141+ fi
142+ done
143+ ])
144+ else
145+ lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list"
146+ AC_MSG_ERROR([$lcov_msg])
147+ fi
148+
149+ case $glib_cv_lcov_version in
150+ ""|invalid[)]
151+ lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)."
152+ AC_MSG_ERROR([$lcov_msg])
153+ LCOV="exit 0;"
154+ ;;
155+ esac
156+
157+ if test -z "$GENHTML"; then
158+ AC_MSG_ERROR([Could not find genhtml from the lcov package])
159+ fi
160+
161+ ac_cv_check_gcov=yes
162+ ac_cv_check_lcov=yes
163+
164+ # Remove all optimization flags from CFLAGS
165+ changequote({,})
166+ CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
167+ changequote([,])
168+
169+ # Add the special gcc flags
170+ COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
171+ COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage"
172+ COVERAGE_LDFLAGS="-lgcov"
173+
174+ # Check availability of gcovr
175+ AC_CHECK_PROG(GCOVR, gcovr, gcovr)
176+ if test -z "$GCOVR"; then
177+ ac_cv_check_gcovr=no
178+ else
179+ ac_cv_check_gcovr=yes
180+ fi
181+
182+fi
183+]) # AC_TDD_GCOV
184
185=== modified file 'src/Makefile.am'
186--- src/Makefile.am 2012-11-08 22:11:14 +0000
187+++ src/Makefile.am 2013-02-19 08:57:20 +0000
188@@ -17,6 +17,7 @@
189 $(LENS_DAEMON_CFLAGS) \
190 $(MAINTAINER_CFLAGS) \
191 -I$(srcdir) \
192+ $(COVERAGE_CFLAGS) \
193 $(NULL)
194
195 unity_shopping_daemon_VALAFLAGS = \
196@@ -37,6 +38,8 @@
197 $(MAINTAINER_VALAFLAGS) \
198 $(NULL)
199
200+unity_shopping_daemon_LDFLAGS = $(COVERAGE_LDFLAGS)
201+
202 unity_shopping_daemon_LDADD = \
203 $(LENS_DAEMON_LIBS) \
204 $(NULL)
205
206=== modified file 'tests/unit/Makefile.am'
207--- tests/unit/Makefile.am 2012-10-01 11:47:49 +0000
208+++ tests/unit/Makefile.am 2013-02-19 08:57:20 +0000
209@@ -1,24 +1,43 @@
210 check_PROGRAMS = test-markup-cleaner
211 TESTS = $(check_PROGRAMS)
212
213+
214+
215 test_markup_cleaner_SOURCES = \
216 test-markup-cleaner.vala \
217- $(top_srcdir)/src/markup-cleaner.vala
218+ $(top_srcdir)/src/config.vala \
219+ $(top_srcdir)/src/categories.vala \
220+ $(top_srcdir)/src/daemon.vala \
221+ $(top_srcdir)/src/markup-cleaner.vala \
222+ $(top_srcdir)/src/scope.vala \
223+ $(top_srcdir)/src/u1ms-preview.vala \
224 $(NULL)
225
226 test_markup_cleaner_CPPFLAGS = \
227 -w \
228 $(LENS_DAEMON_CFLAGS) \
229 -I$(srcdir) \
230+ $(COVERAGE_CFLAGS) \
231+ -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
232 $(NULL)
233
234+test_markup_cleaner_LDFLAGS = $(COVERAGE_LDFLAGS)
235+
236 AM_VALAFLAGS = \
237 -C \
238 --vapidir $(top_srcdir)/vapi \
239 --pkg glib-2.0 \
240 --pkg gio-2.0 \
241 --pkg gio-unix-2.0 \
242- --target-glib=2.26 \
243+ --target-glib=2.26 \
244+ --pkg dee-1.0 \
245+ --pkg unity \
246+ --pkg unity-extras \
247+ --pkg json-glib-1.0 \
248+ --pkg libsoup-2.4 \
249+ --pkg libsoup-gnome-2.4 \
250+ --vapidir $(top_srcdir)/src \
251+ --vapidir $(top_srcdir)/vapi \
252 $(NULL)
253
254 test_markup_cleaner_LDADD = \

Subscribers

People subscribed via source and target branches

to all changes: