This is an automated email from the ASF dual-hosted git repository.
dinglei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
The following commit(s) were added to refs/heads/master by this push:
new 579bee5 feat(codecov): open code coverage for unit test (#215)
579bee5 is described below
commit 579bee5a29a5703169505b8ba8d362be3a16d16c
Author: dinglei <[email protected]>
AuthorDate: Mon Jan 6 20:46:29 2020 +0800
feat(codecov): open code coverage for unit test (#215)
* feat(codecov): open code coverage for unit test
* feat(codecov): open code coverage for unit test
---
.travis.yml | 4 +++-
CMakeLists.txt | 19 ++++++++++++++++++-
build.sh | 20 +++++++++++++++++++-
test/CMakeLists.txt | 4 ++--
4 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 0af462f..2acbc0b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -23,8 +23,10 @@ before_script:
- cd ..
script:
- - ./build.sh test noVerbose
+ - ./build.sh test codecov noVerbose
+after_success:
+ - bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect
coverage reports"
matrix:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ad30cb3..235feb3 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -191,7 +191,24 @@ if(NOT APPLE)
list(APPEND deplibs rt)
endif()
list(APPEND deplibs z)
-
+# Code Coverage Configuration
+add_library(coverage_config INTERFACE)
+
+option(CODE_COVERAGE "Enable coverage reporting" OFF)
+if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+ # Add required flags (GCC & LLVM/Clang)
+ target_compile_options(coverage_config INTERFACE
+ -O0 # no optimization
+ -g # generate debug info
+ --coverage # sets all required flags
+ )
+ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
+ target_link_options(coverage_config INTERFACE --coverage)
+ else()
+ target_link_libraries(coverage_config INTERFACE --coverage)
+ endif()
+ list(APPEND deplibs coverage_config)
+endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# add include dir for bsd (posix uses /usr/include/)
set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH}:/usr/local/include")
ENDIF()
diff --git a/build.sh b/build.sh
index 9e91d55..03e8f1c 100755
--- a/build.sh
+++ b/build.sh
@@ -41,6 +41,7 @@ need_build_libevent=1
need_build_boost=1
test=0
verbose=1
+codecov=0
cpu_num=4
pasres_arguments(){
@@ -59,6 +60,9 @@ pasres_arguments(){
noVerbose)
verbose=0
;;
+ codecov)
+ codecov=1
+ ;;
test)
test=1
esac
@@ -90,6 +94,16 @@ PrintParams()
else
echo "need build boost lib"
fi
+ if [ $test -eq 1 ]
+ then
+ echo "build unit tests"
+ else
+ echo "without build unit tests"
+ fi
+ if [ $codecov -eq 1 ]
+ then
+ echo "run unit tests with code coverage"
+ fi
if [ $verbose -eq 0 ]
then
echo "no need print detail logs"
@@ -305,7 +319,11 @@ BuildRocketMQClient()
if [ $test -eq 0 ];then
cmake ..
else
- cmake .. -DRUN_UNIT_TEST=ON
+ if [ $codecov -eq 1 ];then
+ cmake .. -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=ON
+ else
+ cmake .. -DRUN_UNIT_TEST=ON
+ fi
fi
if [ $verbose -eq 0 ];
then
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index ed0e658..ebe2ad7 100755
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -42,14 +42,14 @@ include_directories(${Gmock_INCLUDE_DIR}/internal)
set(Gtest_LIBRARY_DIRS ${CMAKE_SOURCE_DIR}/bin/lib)
set(Gtest_LIBRARIES
${Gtest_LIBRARY_DIRS}/libgtest_main.a;${Gtest_LIBRARY_DIRS}/libgtest.a)
set(Gmock_LIBRARIES
${Gtest_LIBRARY_DIRS}/libgmock_main.a;${Gtest_LIBRARY_DIRS}/libgmock.a)
-message(status "** Gmock_LIBRARIES: ${Gmock_LIBRARIES}")
+message(STATUS "** Gmock_LIBRARIES: ${Gmock_LIBRARIES}")
link_directories(${Boost_LIBRARY_DIRS})
link_directories(${LIBEVENT_LIBRARY})
link_directories(${JSONCPP_LIBRARY})
set(ROCKETMQ_LIBRARIES ${CMAKE_SOURCE_DIR}/bin/librocketmq.a)
-message(status "ROCKETMQ_LIBRARIES ${ROCKETMQ_LIBRARIES}")
+message(STATUS "** ROCKETMQ_LIBRARIES ${ROCKETMQ_LIBRARIES}")
set(CMAKE_BUILD_TYPE "Debug")