Skip to content

Commit

Permalink
Add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
a4z committed May 6, 2024
1 parent 1e707d0 commit 158c211
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cmake/default_coverage.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
include_guard(GLOBAL)

option(COVERAGE "Enable coverage reporting" OFF)

add_library(_DefaultCoverage INTERFACE)

Expand All @@ -19,6 +22,23 @@ if (COVERAGE)
$<$<CXX_COMPILER_ID:AppleClang>: --coverage>
)

set(COVERAGE_BRANCHES "--rc branch_coverage=1")
set(COVERAGE_WARNINGS "--ignore-errors gcov")
set(GENHTML_WARNINGS "")
if(APPLE)
set(COVERAGE_WARNINGS "--ignore-errors gcov --ignore-errors inconsistent --ignore-errors unused --ignore-errors range --ignore-errors empty,empty")
set(GENHTML_WARNINGS "--ignore-errors inconsistent")
endif()
separate_arguments(COVERAGE_BRANCHES)
separate_arguments(COVERAGE_WARNINGS)
separate_arguments(GENHTML_WARNINGS)
add_custom_target(coverage
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage
COMMAND lcov --directory . --capture --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info ${COVERAGE_WARNINGS} ${COVERAGE_BRANCHES}
COMMAND lcov --remove ${CMAKE_BINARY_DIR}/coverage/coverage.info '/usr/*' '*/tests/*' '*/_deps/*' '${CMAKE_SOURCE_DIR}/external/*' --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info.cleaned ${COVERAGE_WARNINGS} ${COVERAGE_BRANCHES}
COMMAND genhtml --branch-coverage ${CMAKE_BINARY_DIR}/coverage/coverage.info.cleaned --output-directory ${CMAKE_BINARY_DIR}/coverage ${GENHTML_WARNINGS} ${COVERAGE_BRANCHES}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif(COVERAGE)

add_library(default::coverage ALIAS _DefaultCoverage)
add_library(default::coverage ALIAS _DefaultCoverage)
2 changes: 1 addition & 1 deletion cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FetchContent_MakeAvailable(doctest)
add_library(doctest_main STATIC ${PROJECT_SOURCE_DIR}/tests/test_main.cpp)

set(TEST_FRAMEWORK doctest::doctest)
set(THIS_PROJECT_LIBS astr)
set(THIS_PROJECT_LIBS astr default::flags)

target_link_libraries(doctest_main PUBLIC ${TEST_FRAMEWORK})

Expand Down

0 comments on commit 158c211

Please sign in to comment.