I have lately turned my interest towards C and Objective-C, looking into iPhone application development.
So I my continued quest to get my tools box for this defined I am monitoring some interesting mailing lists to pick up stuff as it appears.
The other day somebody write to the official Apple Xcode list inquiring about using gcov and generating HTML data. My brain started spinning, I felt like I had read something about this on CPAN.
I have been a long time fan of Devel::Cover, having worked as a Perl programmer for many years, so I was happy to see that this particular tool might scratch this itch.
So I threw together your normal example helloworld.c
I skimmed a tutorial on gcov to see how it would normally work.
Compile with options of using gcov:
% gcc -fprofile-arcs -ftest-coverage helloworld.c
Run the executable produced:
Turned to gcov2perl and followed the manual here (changed it to reflect my own example):
Creates a single gcov file in our case:
% gcov helloworld.c
Transform data to Devel::Cover’s format:
% gcov2perl helloworld.c.gcov
Create the report:
Open the report in your browser:
% open cover_db/coverage.html
And by clicking the filename you get this report:
The helloworld.c example is very simple, but it proves a point – that it actually works.
I am only scratching the surface of what can be done and I have not fallen into any pitfalls – everything worked fine and looks good, but I am sure it can become more difficult.
Have fun covering your C code and presenting in using a very nice Perl tool.