Skip to content

Commit 579bee5

Browse files
authored
feat(codecov): open code coverage for unit test (apache#215)
* feat(codecov): open code coverage for unit test * feat(codecov): open code coverage for unit test
1 parent a3c3577 commit 579bee5

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ before_script:
2323
- cd ..
2424

2525
script:
26-
- ./build.sh test noVerbose
26+
- ./build.sh test codecov noVerbose
2727

28+
after_success:
29+
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
2830

2931

3032
matrix:

CMakeLists.txt

+18-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,24 @@ if(NOT APPLE)
191191
list(APPEND deplibs rt)
192192
endif()
193193
list(APPEND deplibs z)
194-
194+
# Code Coverage Configuration
195+
add_library(coverage_config INTERFACE)
196+
197+
option(CODE_COVERAGE "Enable coverage reporting" OFF)
198+
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
199+
# Add required flags (GCC & LLVM/Clang)
200+
target_compile_options(coverage_config INTERFACE
201+
-O0 # no optimization
202+
-g # generate debug info
203+
--coverage # sets all required flags
204+
)
205+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
206+
target_link_options(coverage_config INTERFACE --coverage)
207+
else()
208+
target_link_libraries(coverage_config INTERFACE --coverage)
209+
endif()
210+
list(APPEND deplibs coverage_config)
211+
endif(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
195212
# add include dir for bsd (posix uses /usr/include/)
196213
set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH}:/usr/local/include")
197214
ENDIF()

build.sh

+19-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ need_build_libevent=1
4141
need_build_boost=1
4242
test=0
4343
verbose=1
44+
codecov=0
4445
cpu_num=4
4546

4647
pasres_arguments(){
@@ -59,6 +60,9 @@ pasres_arguments(){
5960
noVerbose)
6061
verbose=0
6162
;;
63+
codecov)
64+
codecov=1
65+
;;
6266
test)
6367
test=1
6468
esac
@@ -90,6 +94,16 @@ PrintParams()
9094
else
9195
echo "need build boost lib"
9296
fi
97+
if [ $test -eq 1 ]
98+
then
99+
echo "build unit tests"
100+
else
101+
echo "without build unit tests"
102+
fi
103+
if [ $codecov -eq 1 ]
104+
then
105+
echo "run unit tests with code coverage"
106+
fi
93107
if [ $verbose -eq 0 ]
94108
then
95109
echo "no need print detail logs"
@@ -305,7 +319,11 @@ BuildRocketMQClient()
305319
if [ $test -eq 0 ];then
306320
cmake ..
307321
else
308-
cmake .. -DRUN_UNIT_TEST=ON
322+
if [ $codecov -eq 1 ];then
323+
cmake .. -DRUN_UNIT_TEST=ON -DCODE_COVERAGE=ON
324+
else
325+
cmake .. -DRUN_UNIT_TEST=ON
326+
fi
309327
fi
310328
if [ $verbose -eq 0 ];
311329
then

test/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ include_directories(${Gmock_INCLUDE_DIR}/internal)
4242
set(Gtest_LIBRARY_DIRS ${CMAKE_SOURCE_DIR}/bin/lib)
4343
set(Gtest_LIBRARIES ${Gtest_LIBRARY_DIRS}/libgtest_main.a;${Gtest_LIBRARY_DIRS}/libgtest.a)
4444
set(Gmock_LIBRARIES ${Gtest_LIBRARY_DIRS}/libgmock_main.a;${Gtest_LIBRARY_DIRS}/libgmock.a)
45-
message(status "** Gmock_LIBRARIES: ${Gmock_LIBRARIES}")
45+
message(STATUS "** Gmock_LIBRARIES: ${Gmock_LIBRARIES}")
4646

4747
link_directories(${Boost_LIBRARY_DIRS})
4848
link_directories(${LIBEVENT_LIBRARY})
4949
link_directories(${JSONCPP_LIBRARY})
5050

5151
set(ROCKETMQ_LIBRARIES ${CMAKE_SOURCE_DIR}/bin/librocketmq.a)
52-
message(status "ROCKETMQ_LIBRARIES ${ROCKETMQ_LIBRARIES}")
52+
message(STATUS "** ROCKETMQ_LIBRARIES ${ROCKETMQ_LIBRARIES}")
5353

5454
set(CMAKE_BUILD_TYPE "Debug")
5555

0 commit comments

Comments
 (0)