Add code coverage support. (#378)

This commit is contained in:
Arthur Sonzogni
2022-04-17 15:47:20 +02:00
committed by GitHub
parent b2896aba49
commit 764c24ef40
26 changed files with 206 additions and 96 deletions

View File

@@ -2,12 +2,19 @@ if (NOT WIN32)
FetchContent_Declare(googlebenchmark
GIT_REPOSITORY "https://github.com/google/benchmark"
GIT_TAG 62937f91b5c763a8e119d0c20c67b87bde8eff1c
GIT_PROGRESS TRUE
)
FetchContent_GetProperties(googlebenchmark)
set (BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "")
set (BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "")
if(NOT googlebenchmark_POPULATED)
FetchContent_Populate(googlebenchmark)
add_subdirectory(${googlebenchmark_SOURCE_DIR} ${googlebenchmark_BINARY_DIR} EXCLUDE_FROM_ALL)
add_subdirectory(
${googlebenchmark_SOURCE_DIR}
${googlebenchmark_BINARY_DIR}
EXCLUDE_FROM_ALL
)
endif()
add_executable(ftxui_benchmark

View File

@@ -0,0 +1,8 @@
function(ftxui_check_coverage library)
if (FTXUI_ENABLE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
target_compile_options(${library} INTERFACE --coverage -O0 -g)
target_link_libraries(${library} INTERFACE --coverage)
endif()
endif()
endfunction()

View File

@@ -1,17 +1,25 @@
enable_testing()
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
option(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
option(FETCHCONTENT_QUIET FALSE)
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY "https://github.com/google/googletest"
GIT_TAG 23ef29555ef4789f555f1ba8c51b4c52975f0907
GIT_PROGRESS TRUE
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
set(BUILD_GMOCK OFF CACHE INTERNAL "")
set(INSTALL_GTEST OFF CACHE INTERNAL "")
set(gtest_force_shared_crt ON CACHE INTERNAL "")
add_subdirectory(
${googletest_SOURCE_DIR}
${googletest_BINARY_DIR}
EXCLUDE_FROM_ALL
)
endif()
add_executable(tests
@@ -38,16 +46,17 @@ add_executable(tests
target_link_libraries(tests
PRIVATE component
PRIVATE gtest
PRIVATE gmock
PRIVATE gtest_main
)
target_include_directories(tests
PRIVATE src
)
ftxui_set_options(tests)
if (NOT MSVC)
include(cmake/ftxui_benchmark.cmake)
endif()
include(GoogleTest)
gtest_discover_tests(tests)
include(cmake/ftxui_benchmark.cmake)
if (FTXUI_BUILD_TESTS_FUZZER)
include(cmake/ftxui_fuzzer.cmake)