permalink

0

Convert MavensMate Code Coverage Report to CSV

Occasionally I feel the need to get an overview of the current code coverage of a Salesforce org. I usually just stored that report on disk and then ran this Perl one-liner to convert the report to a CSV file:

perl -ne “if (m/-\s(.*?\.(cls|trigger))\:/) { print qq[$1,]; } if (m/-\scoverage\:.*?\((\d*?)\/(\d*?)\)/) { print qq[ $1, $2\n] }” < “Apex Code Coverage.yaml”

But with advancing age, my memory is not the best anymore and I simply can’t remember these few characters by heart. So I decided to write a Python script to do the same task:

import re
import sys

classname = re.compile(r"-\s(.*?\.(cls|trigger))\:")
coverage = re.compile(r"-\scoverage\:.*?\((\d*?)\/(\d*?)\)")

for line in sys.stdin:
    line = line.rstrip()

    match = classname.search(line)
    if match:
        print ("{0}, ".format(match.group(1)), end="")

    match = coverage.search(line)
    if match:
        print ("{0}, {1}".format(match.group(1), match.group(2)))

It’s written for Python 3 but can be easily adapted to earlier versions by modifying the print statements accordingly. Input is taken from stdin, the result is written to stdout.

Leave a Reply

Required fields are marked *.