views:

149

answers:

3

I am trying to write a small tool to support some of code coverage tests we are running in my company.

Here's my requirement for the tool -

Input - List of files (.cpp and .h) which have been modified (as a part of a checked-in changelist)

Output - All the functions which were added or modified in the source (as a result of checking-in the change).

Any idea how I can go about doing this? Basically, it boils down to what lines changed and what is the function associated with the changed lines...

More info - Source Control: Perforce Platform: Windows

+2  A: 

This sounds tricky. And I'm not sure what you'd do with the info about the changed functions in the source. You don't want to limit your code coverage to those functions: it could be that a changed function affected the coverage of an unchanged function.

Perhaps the best thing to do is simply run all your tests on each check-in, or once an hour if anything has changed. Then you could skip the complex tool creation, and have better results anyway.

Ned Batchelder
A: 

Thanks for your answer Ned.

I agree with you that you don't want to limit your code coverage to just the modified functions. But unfortunately those are the requirements :) And I am not in a position to influence the requirements.

Any ideas?

A: 

Since all the files are checked into Perforce, you could do a batch diff (p4 diff2) of the changed files with the previous revision. p4 diff2 also takes a branch spec which might be a more convenient method.

When a diff is found, you will need to write a script to extract the method name of the changed line. The algorithm might be "Search backwards in the file until you find a method signature for your syntax".

To be clever, determine the class name based on the file name or a list of your classes generated by another script. This list of class names can be helpful in determining the method signature. As you know, the class name is follow by :: and the method name.

I judge this algorithm to be easy to make 95+% accurate and hard to make 100% accurate for arbitrary input.

This script should exclude duplicates to generate a unique list.

The resulting list is the list you request in your question.

james creasy