tests: add coverage support.

And our current score is 19% functions coverage for Elementary.
This commit is contained in:
Cedric BAIL 2015-01-16 16:39:37 +01:00
parent f15d380f00
commit c11cc5f47d
5 changed files with 88 additions and 9 deletions

View File

@ -11,6 +11,8 @@
*.lo
*.o
*.la
*.gcda
*.gcno
.libs
.deps
.*.swp
@ -57,3 +59,4 @@ tags
/config/mobile/*.src
/config/standard/*.src
Session.vim
/coverage/

View File

@ -54,9 +54,6 @@ po/Rules-quot
endif
EXTRA_DIST = \
README \
AUTHORS \
@ -125,3 +122,34 @@ doc:
screenshots: all
@echo "entering src/examples/"
$(MAKE) -C src/examples screenshots
if ELEMENTARY_ENABLE_COVERAGE
lcov-reset:
@rm -rf $(top_builddir)/coverage
@find $(top_builddir) -name "*.gcda" -delete
@lcov --zerocounters --directory $(top_builddir)
lcov-report:
@mkdir $(top_builddir)/coverage
lcov --capture --compat-libtool --no-external --output-file $(top_builddir)/coverage/coverage.info --directory $(top_builddir) --base-directory $(top_srcdir)/src/lib/
lcov --remove $(top_builddir)/coverage/coverage.info '*.h' --output-file $(top_builddir)/coverage/coverage.cleaned.info
lcov --remove $(top_builddir)/coverage/coverage.cleaned.info '*/elm_test_*' --output-file $(top_builddir)/coverage/coverage.cleaned2.info
lcov --remove $(top_builddir)/coverage/coverage.cleaned2.info '*/elm_suite.c' --output-file $(top_builddir)/coverage/coverage.cleaned3.info
lcov --remove $(top_builddir)/coverage/coverage.cleaned3.info '*NONE*' --output-file $(top_builddir)/coverage/coverage.cleaned4.info
genhtml --branch-coverage -t "$(PACKAGE_STRING)" -o $(top_builddir)/coverage/html $(top_builddir)/coverage/coverage.cleaned4.info
@echo "Coverage Report at $(top_builddir)/coverage/html"
endif
if ELEMENTARY_ENABLE_TESTS
lcov-check:
if ELEMENTARY_ENABLE_COVERAGE
@$(MAKE) $(AM_MAKEFLAGS) lcov-reset
endif
@$(MAKE) $(AM_MAKEFLAGS) check
if ELEMENTARY_ENABLE_COVERAGE
@$(MAKE) $(AM_MAKEFLAGS) lcov-report
endif
endif

View File

@ -39,10 +39,32 @@ AC_ARG_ENABLE([cxx-bindings],
# Tests
AC_ARG_WITH([tests],
[AS_HELP_STRING([--with-tests=none|regular],
[choose elementary testing method: regular or none.(coverage will be supported)@<:@default=none@:>@])],
[AS_HELP_STRING([--with-tests=none|regular|coverate],
[choose elementary testing method: regular, coverage or none @<:@default=none@:>@])],
[build_tests=${withval}],
[build_tests=none])
[build_tests=auto])
want_coverage="no"
want_tests="no"
case "${build_tests}" in
auto)
if test "${build_profile}" = "dev"; then
want_tests="yes"
fi
;;
regular)
want_tests="yes"
;;
coverage)
want_tests="yes"
want_coverage="yes"
;;
no*)
;;
*)
AC_MSG_ERROR([Unknown build tests option: --with-tests=${build_tests}])
;;
esac
# Elementary base dir
@ -336,10 +358,28 @@ ELEMENTARY_PC_LIBS="${ELEMENTARY_PC_LIBS} ${requirement_elm_libs}"
AC_SUBST([requirement_elm_pc])
# check unit testing library
if test "${build_tests}" = "regular"; then
if test "${want_tests}" = "yes"; then
PKG_CHECK_MODULES([CHECK], [check >= 0.9.5])
fi
AM_CONDITIONAL([ENABLE_ELEMENTARY_TESTS], [test "${build_tests}" = "regular"])
AM_CONDITIONAL([ELEMENTARY_ENABLE_TESTS], [test "${want_tests}" = "yes"])
# lcov
if test "${want_coverage}" = "yes" ; then
AC_CHECK_PROG([have_lcov], [lcov], [yes], [no])
if test "x${have_lcov}" = "xyes" ; then
ELEMENTARY_CFLAGS="${ELEMENTARY_CFLAGS} -fprofile-arcs -ftest-coverage"
ELEMENTARY_LIBS="${ELEMENTARY_LIBS} -lgcov"
if test "x${prefer_assert}" = "xno"; then
ELEMENTARY_CFLAGS="${ELEMENTARY_CFLAGS} -DNDEBUG"
else
ELEMENTARY_CFLAGS="${ELEMENTARY_CFLAGS} -g -O0 -DDEBUG"
fi
else
AC_MSG_ERROR([lcov is not found])
fi
fi
AM_CONDITIONAL([ELEMENTARY_ENABLE_COVERAGE], [test "${want_coverage}" = "yes"])
### Checks for header files

View File

@ -9,6 +9,6 @@ endif
SUBDIRS += examples
if ENABLE_ELEMENTARY_TESTS
if ELEMENTARY_ENABLE_TESTS
SUBDIRS += tests
endif

View File

@ -171,6 +171,14 @@ elementary_quicklaunch_LDADD = $(top_builddir)/src/lib/libelementary.la \
elementary_quicklaunch_LDFLAGS =
if BUILD_RUN
elementary_run_CPPFLAGS = -I$(top_srcdir) \
-I$(top_srcdir)/src/lib \
-I$(top_builddir)/src/lib \
-I$(top_srcdir)/src/bin \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\"
elementary_run_SOURCES = run.c
elementary_run_LDADD =
elementary_run_LDFLAGS =