]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
add some experimental emacs test-coverage-annotation tools, still in development
authorBrian Warner <warner@lothar.com>
Tue, 2 Jan 2007 06:48:42 +0000 (23:48 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 2 Jan 2007 06:48:42 +0000 (23:48 -0700)
.darcs-boringfile
misc/figleaf.el [new file with mode: 0644]
misc/figleaf2el.py [new file with mode: 0644]

index 6f5979c1dfb21ff54acb72beac26e7d6dd50f0e5..52b297e6a744c96d4ecd8aa0731d448dde03a8b5 100644 (file)
@@ -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 (file)
index 0000000..a5fbb12
--- /dev/null
@@ -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 (file)
index 0000000..77db435
--- /dev/null
@@ -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()
+
+