2

I am trying to get the "Run Tests with Coverage" button working as expected for a C++ project based on CMake. When I hit it, the tests are executed properly, but then it shows the info that the coverage info files could not be found.

I have a small C++ project that consists of a library, an application and tests (based on Google Test) for the library. In the root directory I have a CMakeLists, that is then using add_subdirectory on those 3. In the tests sub project I configured the gcc with target_compile_options() and target_link_options() to also utilize --coverage. The tests are added via ctest, by using gest_discover_tests(test_app). In the VSCode Editor I can easily build the whole project via CMake Extension and I can also execute the tests with the Microsoft Testing. It then executes all tests and show, if they passed or failed and how long they took. At the top is also another button "Run Tests with coverage" and I would like to see my test coverage. When I press this button all tests are executed, but then it shows the message "No coverage info files for CMake Project <project_root_path>. The *.gcda files are generated, but they are below the CMakeFiles directory like build/tests/CMakeFiles/test_app.dir/.

I assume, that the Testing Extension is not looking within the CMakeFiles directory? As far I as I could figure out, it should be searching in the build directory recursively - but I can not validate this. My goal is to hit that button (yes that button) and to have the extension find the coverage info files, so that I can see my coverage information. Is there any way to configure a search path? Or to hook after test execution and before scanning for the coverage info files? Or any other ideas how to get that work?

+ project_root
  + CMakeLists.txt
  + library
    + CMakeLists.txt
    + util.cpp
  + tests
    + CMakeLists.txt
    + main.cpp
    + test_component.cpp
  + application
    + CMakeLists.txt
    + main.cpp

Above is the project structure shown. And below is the CMakeLists.txt for the tests.

cmake_minimum_required(VERSION 3.22)
project(my-tests)

include_directories(${CMAKE_SOURCE_DIR}/library/include)

add_executable(
    test_app
    
    main.cpp

    test_component.cpp
)

target_link_libraries(
    test_app

    # Link with Google Test
        gtest
        gtest_main
        pthread
)

target_compile_options(
    test_app

    PRIVATE
        --coverage
)

target_link_options(
    test_app

    PRIVATE
        --coverage
)

include(GoogleTest)
gtest_discover_tests(test_app)

And last, but not least the output, which is indicating that the coverage information were not found.

No coverage info files for CMake project /home/myuser/Projects/organization/demo-project. No coverage data will be analyzed for this project.

1 Answer 1

0

VS Code is looking for a coverage information file.

Add something like this to the .vscode/settings.json:

    "cmake.coverageInfoFiles": [
        "${workspaceFolder}/build/Test/coverage.info"
    ],  

That file needs to be generated by lcov or gcovr, e.g. with

gcovr --lcov ./build/Test/coverage.info
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.