From: Brian Warner Date: Tue, 2 Jan 2007 06:48:42 +0000 (-0700) Subject: add some experimental emacs test-coverage-annotation tools, still in development X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~412 X-Git-Url: https://git.rkrishnan.org/architecture.txt?a=commitdiff_plain;h=e68118736c64f259cbd02dc3e952a38f5186c685;p=tahoe-lafs%2Ftahoe-lafs.git add some experimental emacs test-coverage-annotation tools, still in development --- diff --git a/.darcs-boringfile b/.darcs-boringfile index 6f5979c1..52b297e6 100644 --- a/.darcs-boringfile +++ b/.darcs-boringfile @@ -49,3 +49,5 @@ ^\.figleaf$ ^coverage-html($|/) ^twisted/plugins/dropin\.cache$ +^\.figleaf\.el$ + diff --git a/misc/figleaf.el b/misc/figleaf.el new file mode 100644 index 00000000..a5fbb12b --- /dev/null +++ b/misc/figleaf.el @@ -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") + ) + ) +))) diff --git a/misc/figleaf2el.py b/misc/figleaf2el.py new file mode 100644 index 00000000..77db435b --- /dev/null +++ b/misc/figleaf2el.py @@ -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() + +