LCov option processing for removing multiple patterns

2.4k views Asked by At

I need to create a set of regex patterns to be used within the --remove option of the lcov command, in order to remove some pointless entries in the coverage file.

Reading the manpage of lcov it seems the list of patterns shall be handed to it as a space-separated single-quoted strings (as in 'patte*n1' 'pa*ter*2' 'p*3' and so on).

I was able to write a small bash script which generates exactly the list I need, in the form required by the command. If I issue

export LIST=$( ./myscript.sh )

and then, do a echo $LIST, I get the list I expect to

'path/file1' 'path/file2' 'path/file3'

(the regex patterns list is comprised of the ending part of some patterns to be removed from the analysis).

The problem arises when I pass this list to the command:

lcov --remove coverage_report.info '/usr/*' $( echo $LIST ) --output-file coverage_report.info.cleaned

in order to remove both /usr/* and the files from my list, but it does not work as expected: no path from my path list is actually removed. I tried different forms of it:

echo $LIST | xargs -i  lcov --remove coverage_report.info  {} --output-file coverage_report.info.cleaned

If I take the output of echo $LIST and copy/paste it directly on the command line, the command actually works and removes all the path I'd like to get rid of. My impression is that I'm not aware of all inner aspects of some commands' options processing and the order of evaluation of nested commands.

Thanks in advance to any people willing to help!

2

There are 2 answers

2
Blazor On BEST ANSWER

Ok,

I finally got it done by issuing

echo $LIST | xargs lcov --output-file coverage_report.info.cleaned --remove coverage_report.info

I switched to the echo ... | xargs way of doing things in order to force the evaluation order of the commands, but the -i way of doing that was not appropriate. I had the idea that the -i switch purpose was to replace the output of the previous command in every place of the current one by means of the {} token, but apparently it has some more consequences on the output processing.

0
Yusuf Gören On

With lcov 1.12 and bash 4.3.46(1), the suggestion above did not work for me. The list needed to be expanded as follows:

echo ${LIST[@]} | xargs lcov -o coverage_report.info.cleaned -r coverage_report.info

Moreover, my list was a list of double-quoted strings, e.g.

LIST=( '"path/file1"' '"path/file2"' '"path/file3"' )