Skip to content

Commit

Permalink
Problem: Coverage with coveralls not working
Browse files Browse the repository at this point in the history
Solution: Enable coveralls for one linux build target and fix coveralls
configuration.
  • Loading branch information
kurdybacha committed Jun 3, 2018
1 parent 3c14d37 commit 9a7a857
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
21 changes: 16 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ matrix:
# GCC on Linux
##########################################################

# Coverage, GCC 7, draft enabled, latest libzmq (default)
- os: linux
before_install:
- pip install --user cpp-coveralls
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" ENABLE_DRAFTS=ON COVERAGE=ON
after_success:
- coveralls -r . -E ".*external.*" -E ".*CMakeFiles.*" -E ".*tests/" -E ".*demo/" -E ".*libzmq.*/" -b cppzmq-build --gcov-options '\-lp'

# GCC default, draft disabled, older libzmq with pkg-config
- os: linux
env: ZMQ_VERSION=4.2.0 BUILD_TYPE=pkgconfig
Expand Down Expand Up @@ -51,6 +66,7 @@ matrix:
- g++-7
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" ENABLE_DRAFTS=ON

# - env: BUILD_TYPE=cmake DO_CLANG_FORMAT_CHECK=1 CLANG_FORMAT=/usr/local/clang-5.0.0/bin/clang-format
# os: linux
# addons:
Expand All @@ -60,14 +76,9 @@ matrix:
# packages:
# - clang-5.0

before_install:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then pip install --user cpp-coveralls; fi

# Build and check this project
script:
- eval "${MATRIX_EVAL}"
- cmake --version
- ./ci_build.sh

after_success:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then coveralls --root . -E ".*external.*" -E ".*CMakeFiles.*" -E ".*tests/" -E ".*demo/" -E ".*libzmq/"; fi
4 changes: 3 additions & 1 deletion ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
BUILD_TYPE=${BUILD_TYPE:-cmake}
ZMQ_VERSION=${ZMQ_VERSION:-4.2.5}
ENABLE_DRAFTS=${ENABLE_DRAFTS:-OFF}
COVERAGE=${COVERAGE:-OFF}
LIBZMQ=${PWD}/libzmq-build
CPPZMQ=${PWD}/cppzmq-build
# Travis machines have 2 cores
Expand Down Expand Up @@ -37,7 +38,8 @@ libzmq_install() {
cppzmq_build() {
pushd .
CMAKE_PREFIX_PATH=${LIBZMQ} \
cmake -H. -B${CPPZMQ} -DENABLE_DRAFTS=${ENABLE_DRAFTS}
cmake -H. -B${CPPZMQ} -DENABLE_DRAFTS=${ENABLE_DRAFTS} \
-DCOVERAGE=${COVERAGE}
cmake --build ${CPPZMQ} -- -j${JOBS}
popd
}
Expand Down
16 changes: 9 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})

# we use this to get code coverage
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif()

include(cmake/googletest.cmake)
fetch_googletest(
${PROJECT_SOURCE_DIR}/cmake
Expand All @@ -32,10 +27,17 @@ add_executable(

target_link_libraries(
unit_tests
gtest_main
cppzmq
PRIVATE gtest_main
PRIVATE cppzmq
)

OPTION (COVERAGE "Enable gcda file generation needed by lcov" OFF)

if (COVERAGE)
target_compile_options(unit_tests PRIVATE --coverage)
target_link_libraries(unit_tests PRIVATE --coverage)
endif()

add_test(
NAME
unit
Expand Down

0 comments on commit 9a7a857

Please sign in to comment.