简体   繁体   中英

CMake/CTest Code coverage check

I can run a coverage check using cmake following this wiki page. This is very simple and a setting a dashboard I can have a nice view of code coverage on my browser (latter part). But I don't want to ctest everytime just to check the progress of a single file. In fact, I want to check code coverage locally for a subdirectoy rather than enitre library with thirdparty code.

So, how can we check the code coverage for a subdirectory. Of course, I had a written a test in cmakelists.txt using add_test(....).

I will try to explain a little bit without any code.

Class A {   
public:    
    A() {}

....     
so many methods ..
....

protected:
    ~A() {} 
}; //end class A

Next I've written a test:

//testA
int main()
{
    A *a = new A();

    a->method1();

    a->method2();
    ...
}

Now in CMakeLists.txt, I have:

add_test(testA ...)

So when I run ctest it will run all test including TestA . Of course, I can use ctest -R "TestA" .

Now coming back to the question, how can I check coverage of class A only. without running all test or just running only testA ?

I have created a cmake script that generates coverage data meant to be used for the http://coveralls.io/ service (free for open source projects).

The script allows you to specify exactly what files you want to gather the code coverage from (compared to most scripts that lets you exclude files). So you could file(GLOB the files you're interested in or specify them manually. This script can also be modified to simply run lcov and generate local html reports instead.

https://github.com/JoakimSoderberg/coveralls-cmake https://github.com/JoakimSoderberg/coveralls-cmake-example

If http://coveralls.io/ doesn't interest you, here's another script that uses lcov to simply generate local html reports:

https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM