tahoe-lafs/misc/coding_tools/coverage2el.py
Brian Warner 1f0e2574cc update Makefile and coverage2el.py to coverage-3.4
It might still work with coverage-3.3 if you run with COVERAGE_OMIT=""
2010-11-25 12:38:32 -08:00

59 lines
2.3 KiB
Python

import os.path
from coverage import coverage, summary, misc
class ElispReporter(summary.SummaryReporter):
def report(self):
try:
# coverage-3.4 has both omit= and include= . include= is applied
# first, then omit= removes items from what's left. These are
# tested with fnmatch, against fully-qualified filenames.
self.find_code_units(None,
omit=[os.path.abspath("src/allmydata/test/*")],
include=[os.path.abspath("src/allmydata/*")])
except TypeError:
# coverage-3.3 only had omit=
self.find_code_units(None, ["/System", "/Library", "/usr/lib",
"support/lib", "src/allmydata/test"])
out = open(".coverage.el", "w")
out.write("""
;; This is an elisp-readable form of the figleaf coverage data. It defines a
;; single top-level hash table in which the key is an asolute pathname, and
;; the value is a three-element list. The first element of this list is a
;; list of line numbers that represent actual code statements. The second is
;; a list of line numbers for lines which got used during the unit test. The
;; third is a list of line numbers for code lines that were not covered
;; (since 'code' and 'covered' start as sets, this last list is equal to
;; 'code - covered').
""")
out.write("(let ((results (make-hash-table :test 'equal)))\n")
for cu in self.code_units:
f = cu.filename
try:
(fn, executable, missing, mf) = self.coverage.analysis(cu)
except misc.NoSource:
continue
code_linenumbers = executable
uncovered_code = missing
covered_linenumbers = sorted(set(executable) - set(missing))
out.write(" (puthash \"%s\" '((%s) (%s) (%s)) results)\n"
% (f,
" ".join([str(ln) for ln in sorted(code_linenumbers)]),
" ".join([str(ln) for ln in sorted(covered_linenumbers)]),
" ".join([str(ln) for ln in sorted(uncovered_code)]),
))
out.write(" results)\n")
out.close()
def main():
c = coverage()
c.load()
ElispReporter(c).report()
if __name__ == '__main__':
main()