Skip to content

Commit

Permalink
Add lcov test coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
Eggbertx committed Mar 4, 2024
1 parent fce9a36 commit d99becf
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ project(oc8-test VERSION 0.1.0 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-fprofile-arcs -ftest-coverage)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")

include(CTest)
include(CTestCoverageCollectGCOV)
Expand All @@ -15,7 +18,8 @@ FetchContent_Declare(

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCMAKE_TEST")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCMAKE_TEST -fprofile-arcs -ftest-coverage")
set(OBJECT_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/oc8-test.dir/src)
FetchContent_MakeAvailable(googletest)

enable_testing()
Expand All @@ -28,7 +32,22 @@ add_executable(oc8-test
src/tests/chip8_test.cc
)

target_link_libraries(oc8-test GTest::gtest_main)
add_custom_target(lcov
COMMAND rm -rf lcov
COMMAND mkdir lcov
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

add_custom_command(TARGET lcov
COMMAND lcov -d ${OBJECT_DIR} -c -o ${CMAKE_BINARY_DIR}/lcov/coverage.info -rc lcov_branch_coverage=1 --ignore-errors mismatch
COMMAND lcov -r ${CMAKE_BINARY_DIR}/lcov/coverage.info "/usr/include/*" "${CMAKE_BINARY_DIR}/_deps/*" -o ${CMAKE_BINARY_DIR}/lcov/coverage.info --ignore-errors unused
COMMAND genhtml ${CMAKE_BINARY_DIR}/lcov/coverage.info --branch-coverage --output-directory ${CMAKE_BINARY_DIR}/lcov/html
)

add_test(oc8-test ${CMAKE_CURRENT_BINARY_DIR}/oc8-test)

target_link_libraries(oc8-test GTest::gtest_main -fprofile-arcs)

include(GoogleTest)
gtest_discover_tests(oc8-test)

0 comments on commit d99becf

Please sign in to comment.