2010-08-04 07:11:31 +00:00
|
|
|
from coverage import coverage, summary, misc
|
2010-01-28 17:39:04 +00:00
|
|
|
|
|
|
|
class ElispReporter(summary.SummaryReporter):
|
2014-09-09 00:27:20 +00:00
|
|
|
def report(self, morfs=None):
|
|
|
|
self.find_code_units(morfs)
|
2010-01-28 17:39:04 +00:00
|
|
|
out = open(".coverage.el", "w")
|
|
|
|
out.write("""
|
2014-09-08 21:49:23 +00:00
|
|
|
;; This is an elisp-readable form of the coverage data. It defines a
|
2010-01-28 17:39:04 +00:00
|
|
|
;; 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
|
2010-08-04 07:11:31 +00:00
|
|
|
try:
|
|
|
|
(fn, executable, missing, mf) = self.coverage.analysis(cu)
|
|
|
|
except misc.NoSource:
|
|
|
|
continue
|
2010-01-28 17:39:04 +00:00
|
|
|
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():
|
2014-09-09 00:27:20 +00:00
|
|
|
c = coverage() # defaults to data_file=.coverage
|
2010-01-28 17:39:04 +00:00
|
|
|
c.load()
|
2014-09-09 00:27:20 +00:00
|
|
|
c._harvest_data()
|
|
|
|
c.config.from_args(include="src/*")
|
|
|
|
ElispReporter(c, c.config).report()
|
2010-01-28 17:39:04 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|
|
|
|
|