Add coverage support to cpp tests

This commit is contained in:
2022-12-03 19:16:42 +01:00
parent e99852c5d5
commit 5cce895177
5 changed files with 17 additions and 14 deletions

1
.gitignore vendored
View File

@@ -132,3 +132,4 @@ cfimdlp.cpp
**/.idea/*
cmake-build-debug
cmake-build-debug/**
**/lcoverage/**

View File

@@ -10,6 +10,9 @@ clean: ## Clean up
test:
cd fimdlp/testcpp && ./test
coverage:
cd fimdlp/testcpp && ./cover
lint: ## Lint and static-check
black fimdlp
flake8 fimdlp

View File

@@ -3,20 +3,10 @@ project(FImdlp)
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
include(FetchContent)
include_directories(
/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/build/_deps/googletest-src
/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/build/_deps/googletest-src/googletest
/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/build/_deps/googletest-src/googletest/include
/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/build/_deps/googletest-src/googletest/src
/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/build/_deps/googletest-src/googletest/test/
/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/build/_deps/googletest-src/googlemock
/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/build/_deps/googletest-src/googlemock/include
/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/build/_deps/googletest-src/googlemock/test
/Library/Frameworks/Python.framework/Versions/Current/
)
#include_directories(/Users/rmontanana/Code/FImdlp/fimdlp/testcpp/googletest-release-1.12.1/googletest/include /Users/rmontanana/Code/FImdlp/fimdlp/testcpp/googletest-release-1.12.1/googletest)
include_directories(${GTEST_INCLUDE_DIRS})
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
@@ -31,8 +21,13 @@ add_executable(Metrics_unittest ../Metrics.cpp Metrics_unittest.cc)
add_executable(FImdlp_unittest ../CPPFImdlp.cpp ../Metrics.cpp FImdlp_unittest.cc)
target_link_libraries(Metrics_unittest GTest::gtest_main)
target_link_libraries(FImdlp_unittest GTest::gtest_main)
target_compile_options(Metrics_unittest PRIVATE --coverage)
target_compile_options(FImdlp_unittest PRIVATE --coverage)
target_link_options(Metrics_unittest PRIVATE --coverage)
target_link_options(FImdlp_unittest PRIVATE --coverage)
# -fprofile-arcs -ftest-coverage
include(GoogleTest)
gtest_discover_tests(Metrics_unittest)
gtest_discover_tests(FImdlp_unittest)

4
fimdlp/testcpp/cover Executable file
View File

@@ -0,0 +1,4 @@
rm -fr lcoverage/*
lcov --capture --directory ./ --output-file lcoverage/main_coverage.info
genhtml lcoverage/main_coverage.info --output-directory lcoverage
open lcoverage/index.html