]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/coding_tools/coverage2el.py
coverage tools: ignore errors, display lines-uncovered in elisp mode. Fix Makefile...
[tahoe-lafs/tahoe-lafs.git] / misc / coding_tools / coverage2el.py
1
2 from coverage import coverage, summary, misc
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             try:
25                 (fn, executable, missing, mf) = self.coverage.analysis(cu)
26             except misc.NoSource:
27                 continue
28             code_linenumbers = executable
29             uncovered_code = missing
30             covered_linenumbers = sorted(set(executable) - set(missing))
31             out.write(" (puthash \"%s\" '((%s) (%s) (%s)) results)\n"
32                       % (f,
33                          " ".join([str(ln) for ln in sorted(code_linenumbers)]),
34                          " ".join([str(ln) for ln in sorted(covered_linenumbers)]),
35                          " ".join([str(ln) for ln in sorted(uncovered_code)]),
36                          ))
37         out.write(" results)\n")
38         out.close()
39
40 def main():
41     c = coverage()
42     c.load()
43     ElispReporter(c).report()
44
45 if __name__ == '__main__':
46     main()
47
48