A poor man C/C++ linter and code coverage (gtests)
C/C++ Linter:
Cppcheck
apt-get install cppcheck
cppcheck –enable=all /your_cpp_source_dir
Test Code coverage : gcov/lcov
g++ -o main –fprofile-arcs -ftest-coverage main_test.cpp -L /usr/lib -I/usr/include
./main
gcov main_test.cpp
lcov –coverage –directory . –output-file main_coverage.info
genhtml main_coverage.info –output-directory out
https://medium.com/@naveen.maltesh/generating-code-coverage-report-using-gnu-gcov-lcov-ee54a4de3f11
https://dr-kino.github.io/2019/12/22/test-coverage-using-gtest-gcov-and-lcov/
CMake and code coverage
for: https://github.com/pyarmak/cmake-gtest-coverage-example
if (CMAKE_BUILD_TYPE MATCHES Debug)
if (CodeCoverage MATCHES ON)
include(CodeCoverage)
setup_target_for_coverage(${PROJECT_NAME}_coverage poptests coverage)
setup_target_for_coverage_cobertura(test_coverage ctest coverage)
endif()
endif()
Or for https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
if (CMAKE_BUILD_TYPE MATCHES Debug)
if (CodeCoverage MATCHES ON)
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
setup_target_for_coverage_lcov(
NAME test_coverage
EXECUTABLE ctest # for test aded by cmake’s add_test
EXCLUDE “${PROJECT_SOURCE_DIR}/src/dir1/*” “/path/to/my/src/dir2/*”)
endif()
endif()
Then: mkdir -p test_coverage cd test_coverage cmake .. -DMAKE_BUILD_TYPE=Debug -DCodeCoverage=ON make test_coverage It should genreate lcov html coverage files
Other Docs: