source: trunk/misc/coding_tools/coverage2el.py

Last change on this file was 5ddbf288, checked in by Brian Warner <warner@…>, at 2014-09-09T16:47:13Z

coverage2el.py: update to current coverage-3.7.1 API

  • Property mode set to 100644
File size: 1.8 KB
Line 
1from coverage import coverage, summary, misc
2
3class ElispReporter(summary.SummaryReporter):
4    def report(self, morfs=None):
5        self.find_code_units(morfs)
6        out = open(".coverage.el", "w")
7        out.write("""
8;; This is an elisp-readable form of the coverage data. It defines a
9;; single top-level hash table in which the key is an asolute pathname, and
10;; the value is a three-element list. The first element of this list is a
11;; list of line numbers that represent actual code statements. The second is
12;; a list of line numbers for lines which got used during the unit test. The
13;; third is a list of line numbers for code lines that were not covered
14;; (since 'code' and 'covered' start as sets, this last list is equal to
15;; 'code - covered').
16
17    """)
18        out.write("(let ((results (make-hash-table :test 'equal)))\n")
19        for cu in self.code_units:
20            f = cu.filename
21            try:
22                (fn, executable, missing, mf) = self.coverage.analysis(cu)
23            except misc.NoSource:
24                continue
25            code_linenumbers = executable
26            uncovered_code = missing
27            covered_linenumbers = sorted(set(executable) - set(missing))
28            out.write(" (puthash \"%s\" '((%s) (%s) (%s)) results)\n"
29                      % (f,
30                         " ".join([str(ln) for ln in sorted(code_linenumbers)]),
31                         " ".join([str(ln) for ln in sorted(covered_linenumbers)]),
32                         " ".join([str(ln) for ln in sorted(uncovered_code)]),
33                         ))
34        out.write(" results)\n")
35        out.close()
36
37def main():
38    c = coverage() # defaults to data_file=.coverage
39    c.load()
40    c._harvest_data()
41    c.config.from_args(include="src/*")
42    ElispReporter(c, c.config).report()
43
44if __name__ == '__main__':
45    main()
46
47
Note: See TracBrowser for help on using the repository browser.