From b823dd4ed4d69db1ba8a24172dabf250e6b16c4f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 6 Feb 2016 15:23:28 +0100 Subject: [PATCH] Add code coverage support This uses coveralls.io and integrates the collection of coverage information with Travis. Signed-off-by: Uli Schlachter --- .luacov | 26 ++++++++++++++++++++++++++ .travis.yml | 8 +++++++- CMakeLists.txt | 8 ++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .luacov diff --git a/.luacov b/.luacov new file mode 100644 index 00000000..b236077e --- /dev/null +++ b/.luacov @@ -0,0 +1,26 @@ +-- Configuration file for LuaCov + +-- This variable is set externally +local build = os.getenv("BUILD_DIRECTORY") or error("$BUILD_DIRECTORY not set") +local lib_dir = build .. "lib/" + +local function escape_pattern(str) + return string.gsub(str, "%W", "%%%1") +end + +return { + statsfile = build .. "luacov.stats.out", + + include = { + escape_pattern(lib_dir) .. ".+", + }, + + -- configuration for luacov-coveralls reporter + coveralls = { + pathcorrect = { + { escape_pattern(lib_dir), "lib/"}, + }, + }, +} + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/.travis.yml b/.travis.yml index f973840b..01d5c1e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ env: matrix: # Note: luarocks does not work with Lua 5.0. - LUA=5.1 LGIVER= LUANAME=lua5.1 - - LUA=5.2 LGIVER= LUANAME=lua5.2 BUILD_APIDOC=true + - LUA=5.2 LGIVER= LUANAME=lua5.2 BUILD_APIDOC=true DO_COVERAGE=true - LUA=5.2 LGIVER=0.7.1 LUANAME=lua5.2 # luajit: requires --lua-suffix=jit-2.0.0-beta9 in Ubuntu precise. # Later versions seem to provide a `luajit` symlink, so `jit` would be enough. @@ -73,6 +73,9 @@ install: - travis_retry sudo luarocks install ldoc - travis_retry sudo luarocks install lua-discount + # Instal luacov-coveralls for code coverage testing. + - if [ "$DO_COVERAGE" = "true" ]; then sudo luarocks install luacov-coveralls; fi + # Determine custom version. - export AWESOME_VERSION="${TRAVIS_BRANCH}-g$(git rev-parse --short HEAD)" - 'if [ "$TRAVIS_PULL_REQUEST" != false ]; then AWESOME_VERSION="${AWESOME_VERSION}-PR${TRAVIS_PULL_REQUEST}"; fi' @@ -80,7 +83,10 @@ install: script: - export CMAKE_ARGS="-DLUA_LIBRARY=${LUALIBRARY} -DLUA_INCLUDE_DIR=${LUAINCLUDE} -D OVERRIDE_VERSION=$AWESOME_VERSION" - make && sudo env PATH=$PATH make install && awesome --version && make check + - if [ "$DO_COVERAGE" = "true" ]; then make check-coverage; fi after_success: # Push updated API docs for relevant branches, e.g. non-PRs builds on master. - if [ "$BUILD_APIDOC" = "true" ]; then build-utils/travis-apidoc.sh; fi + # Push code coverage information + - if [ "$DO_COVERAGE" = "true" ]; then BUILD_DIRECTORY="$(pwd)/$(readlink build)/" luacov-coveralls --verbose --merge; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index a1fad875..80f9d5dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -368,6 +368,14 @@ if(BUSTED_EXECUTABLE) WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMENT "Running unit tests" VERBATIM) + add_custom_target(check-coverage + "BUILD_DIRECTORY=${CMAKE_BINARY_DIR}/" + ${BUSTED_EXECUTABLE} "--helper=${CMAKE_SOURCE_DIR}/spec/preload.lua" + "--lpath=${CMAKE_BINARY_DIR}/lib/?.lua;${CMAKE_BINARY_DIR}/lib/?/init.lua;spec/?.lua" + "--coverage" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running unit tests under LuaCov" + VERBATIM) endif() add_custom_target(check-integration "${CMAKE_SOURCE_DIR}/tests/run.sh"