mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 01:08:35 +00:00
test: add code coverage report (#3312)
This commit is contained in:
@@ -140,12 +140,17 @@ add_subdirectory(src)
|
||||
CU_RUN_HOOK("AFTER_SRC_LOAD")
|
||||
|
||||
if( UNIT_TESTS )
|
||||
# we use this to get code coverage
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
|
||||
message("Unit tests code coverage: enabling -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
# we use these flags to get code coverage
|
||||
set(UNIT_TEST_CXX_FLAGS "-fprofile-arcs -ftest-coverage -fno-inline")
|
||||
|
||||
# enable additional flags for GCC.
|
||||
if ( CMAKE_CXX_COMPILER_ID MATCHES GNU )
|
||||
set(UNIT_TEST_CXX_FLAGS "${UNIT_TEST_CXX_FLAGS} -fno-inline-small-functions -fno-default-inline")
|
||||
endif()
|
||||
|
||||
message("Unit tests code coverage: enabling ${UNIT_TEST_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UNIT_TEST_CXX_FLAGS}")
|
||||
|
||||
include(src/cmake/googletest.cmake)
|
||||
fetch_googletest(
|
||||
${PROJECT_SOURCE_DIR}/src/cmake
|
||||
@@ -154,4 +159,16 @@ if( UNIT_TESTS )
|
||||
|
||||
enable_testing()
|
||||
add_subdirectory(src/test)
|
||||
|
||||
add_custom_target(coverage DEPENDS coverage_command)
|
||||
|
||||
add_custom_command(OUTPUT coverage_command
|
||||
# Run unit tests.
|
||||
COMMAND ctest
|
||||
# Run the graphical front-end for code coverage.
|
||||
COMMAND lcov --directory src --capture --output-file coverage.info
|
||||
COMMAND lcov --remove coverage.info '/usr/*' '${CMAKE_BINARY_DIR}/googletest/*' '${CMAKE_CURRENT_SOURCE_DIR}/src/test/*' --output-file coverage.info
|
||||
COMMAND genhtml -o ${CMAKE_CURRENT_SOURCE_DIR}/coverage-report coverage.info
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user