mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-23 21:08:22 +00:00
add some experimental emacs test-coverage-annotation tools, still in development
This commit is contained in:
parent
e600571f82
commit
e68118736c
@ -49,3 +49,5 @@
|
|||||||
^\.figleaf$
|
^\.figleaf$
|
||||||
^coverage-html($|/)
|
^coverage-html($|/)
|
||||||
^twisted/plugins/dropin\.cache$
|
^twisted/plugins/dropin\.cache$
|
||||||
|
^\.figleaf\.el$
|
||||||
|
|
||||||
|
68
misc/figleaf.el
Normal file
68
misc/figleaf.el
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
;(require 'gnus-start)
|
||||||
|
|
||||||
|
; (defun gnus-load (file)
|
||||||
|
; "Load FILE, but in such a way that read errors can be reported."
|
||||||
|
; (with-temp-buffer
|
||||||
|
; (insert-file-contents file)
|
||||||
|
; (while (not (eobp))
|
||||||
|
; (condition-case type
|
||||||
|
; (let ((form (read (current-buffer))))
|
||||||
|
; (eval form))
|
||||||
|
; (error
|
||||||
|
; (unless (eq (car type) 'end-of-file)
|
||||||
|
; (let ((error (format "Error in %s line %d" file
|
||||||
|
; (count-lines (point-min) (point)))))
|
||||||
|
; (ding)
|
||||||
|
; (unless (gnus-yes-or-no-p (concat error "; continue? "))
|
||||||
|
; (error "%s" error)))))))))
|
||||||
|
|
||||||
|
(defvar figleaf-annotation-file ".figleaf.el")
|
||||||
|
(defvar figleaf-annotations nil)
|
||||||
|
|
||||||
|
(defun load-figleaf-annotations ()
|
||||||
|
(let ((coverage
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents figleaf-annotation-file)
|
||||||
|
(let ((form (read (current-buffer))))
|
||||||
|
(eval form)))))
|
||||||
|
(setq figleaf-annotations coverage)
|
||||||
|
coverage
|
||||||
|
))
|
||||||
|
|
||||||
|
(defun figleaf-unannotate ()
|
||||||
|
(interactive)
|
||||||
|
(save-excursion
|
||||||
|
(dolist (ov (overlays-in (point-min) (point-max)))
|
||||||
|
(delete-overlay ov))
|
||||||
|
))
|
||||||
|
|
||||||
|
(defun figleaf-annotate (filename)
|
||||||
|
(interactive)
|
||||||
|
(let* ((allcoverage (load-figleaf-annotations))
|
||||||
|
(thiscoverage (gethash filename allcoverage))
|
||||||
|
(covered-lines (car thiscoverage))
|
||||||
|
(code-lines (car (cdr thiscoverage)))
|
||||||
|
)
|
||||||
|
(save-excursion
|
||||||
|
(dolist (ov (overlays-in (point-min) (point-max)))
|
||||||
|
(delete-overlay ov))
|
||||||
|
(dolist (covered-line covered-lines)
|
||||||
|
(goto-line covered-line)
|
||||||
|
;;(add-text-properties (point) (line-end-position) '(face bold) )
|
||||||
|
(overlay-put (make-overlay (point) (line-end-position))
|
||||||
|
;'before-string "C"
|
||||||
|
;'face '(background-color . "green")
|
||||||
|
'face '(:background "dark green")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(dolist (code-line code-lines)
|
||||||
|
(goto-line code-line)
|
||||||
|
(overlay-put (make-overlay (point) (line-end-position))
|
||||||
|
;'before-string "D"
|
||||||
|
;'face '(:background "blue")
|
||||||
|
;'face '(:underline "blue")
|
||||||
|
'face '(:box "blue")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)))
|
73
misc/figleaf2el.py
Normal file
73
misc/figleaf2el.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#! /usr/bin/python
|
||||||
|
|
||||||
|
import os, sys, pickle
|
||||||
|
|
||||||
|
def longest_common_prefix(elements):
|
||||||
|
if not elements:
|
||||||
|
return ""
|
||||||
|
prefix = elements[0]
|
||||||
|
for e in elements:
|
||||||
|
prefix = longest_common_prefix_2(prefix, e)
|
||||||
|
return prefix
|
||||||
|
def longest_common_prefix_2(a, b):
|
||||||
|
maxlen = min(len(a), len(b))
|
||||||
|
for i in range(maxlen, 0, -1):
|
||||||
|
if a[:i] == b[:i]:
|
||||||
|
return a[:i]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def write_el(r2):
|
||||||
|
filenames = sorted(r2.keys())
|
||||||
|
out = open(".figleaf.el", "w")
|
||||||
|
out.write("(setq figleaf-results '(\n")
|
||||||
|
for f in filenames:
|
||||||
|
linenumbers = r2[f]
|
||||||
|
out.write(' ("%s" (%s))\n' % (f, " ".join([str(ln)
|
||||||
|
for ln in linenumbers])))
|
||||||
|
out.write(" ))\n")
|
||||||
|
out.close()
|
||||||
|
|
||||||
|
def write_el(r2, source):
|
||||||
|
filenames = sorted(r2.keys())
|
||||||
|
out = open(".figleaf.el", "w")
|
||||||
|
out.write("(let ((results (make-hash-table :test 'equal)))\n")
|
||||||
|
for f in filenames:
|
||||||
|
covered_linenumbers = r2[f]
|
||||||
|
code_linenumbers = source[f]
|
||||||
|
out.write(" (puthash \"%s\" '((%s) (%s)) results)\n"
|
||||||
|
% (f,
|
||||||
|
" ".join([str(ln) for ln in sorted(covered_linenumbers)]),
|
||||||
|
" ".join([str(ln) for ln in sorted(code_linenumbers)]),
|
||||||
|
))
|
||||||
|
out.write(" results)\n")
|
||||||
|
out.close()
|
||||||
|
|
||||||
|
import figleaf
|
||||||
|
def examine_source(filename):
|
||||||
|
f = open(filename, "r")
|
||||||
|
lines = figleaf.get_lines(f)
|
||||||
|
f.close()
|
||||||
|
return lines
|
||||||
|
|
||||||
|
def main():
|
||||||
|
results = pickle.load(open(sys.argv[1], "rb"))
|
||||||
|
import_prefix = os.path.abspath(sys.argv[2])
|
||||||
|
if not import_prefix.endswith("/"):
|
||||||
|
import_prefix = import_prefix + "/"
|
||||||
|
plen = len(import_prefix)
|
||||||
|
|
||||||
|
r2 = {}
|
||||||
|
source = {}
|
||||||
|
filenames = sorted(results.keys())
|
||||||
|
here = os.getcwd()
|
||||||
|
for f in filenames:
|
||||||
|
if f.startswith(import_prefix):
|
||||||
|
short = f[plen:]
|
||||||
|
r2[short] = results[f]
|
||||||
|
source[short] = examine_source(f)
|
||||||
|
write_el(r2, source)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user