]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/coverage2el.py
code coverage: replace figleaf with coverage.py, should work on py2.6 now.
[tahoe-lafs/tahoe-lafs.git] / misc / coverage2el.py
1
2 from coverage import coverage, summary
3
4 class ElispReporter(summary.SummaryReporter):
5     def report(self):
6         self.find_code_units(None, ["/System", "/Library", "/usr/lib",
7                                     "support/lib", "src/allmydata/test"])
8
9         out = open(".coverage.el", "w")
10         out.write("""
11 ;; This is an elisp-readable form of the figleaf coverage data. It defines a
12 ;; single top-level hash table in which the key is an asolute pathname, and
13 ;; the value is a three-element list. The first element of this list is a
14 ;; list of line numbers that represent actual code statements. The second is
15 ;; a list of line numbers for lines which got used during the unit test. The
16 ;; third is a list of line numbers for code lines that were not covered
17 ;; (since 'code' and 'covered' start as sets, this last list is equal to
18 ;; 'code - covered').
19
20     """)
21         out.write("(let ((results (make-hash-table :test 'equal)))\n")
22         for cu in self.code_units:
23             f = cu.filename
24             (fn, executable, missing, mf) = self.coverage.analysis(cu)
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
37 def main():
38     c = coverage()
39     c.load()
40     ElispReporter(c).report()
41
42 if __name__ == '__main__':
43     main()
44
45