]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/testcover.el
Update copyright year to 2016
[gnu-emacs] / lisp / emacs-lisp / testcover.el
index 08f757819f22f86dff1dfafbdcf8f8759dca0337..a0c0d85fb2981095819dad6daafe70aec197b369 100644 (file)
@@ -1,6 +1,6 @@
-;;;; testcover.el -- Visual code-coverage tool
+;;;; testcover.el -- Visual code-coverage tool  -*- lexical-binding:t -*-
 
-;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2016 Free Software Foundation, Inc.
 
 ;; Author: Jonathan Yavner <jyavner@member.fsf.org>
 ;; Maintainer: Jonathan Yavner <jyavner@member.fsf.org>
@@ -28,7 +28,7 @@
 ;; * Use `testcover-mark-all' to add overlay "splotches" to the Lisp file's
 ;;   buffer to show where coverage is lacking.  Normally, a red splotch
 ;;   indicates the form was never evaluated; a brown splotch means it always
-;;   evaluted to the same value.
+;;   evaluated to the same value.
 ;; * Use `testcover-next-mark' (bind it to a key!) to jump to the next spot
 ;;   that has a splotch.
 
@@ -100,14 +100,14 @@ current global map.  The macro `lambda' is self-evaluating, hence always
 returns the same value (the function it defines may return varying values
 when called)."
   :group 'testcover
-  :type 'hook)
+  :type '(repeat symbol))
 
 (defcustom testcover-noreturn-functions
   '(error noreturn throw signal)
   "Subset of `testcover-1value-functions' -- these never return.  We mark
 them as having returned nil just before calling them."
   :group 'testcover
-  :type 'hook)
+  :type '(repeat symbol))
 
 (defcustom testcover-compose-functions
   '(+ - * / = append length list make-keymap make-sparse-keymap
@@ -118,7 +118,7 @@ calls to one of the `testcover-1value-functions', so if that's true then no
 brown splotch is shown for these.  This list is quite incomplete!  Most
 side-effect-free functions should be here."
   :group 'testcover
-  :type 'hook)
+  :type '(repeat symbol))
 
 (defcustom testcover-progn-functions
   '(define-key fset function goto-char mapc overlay-put progn
@@ -132,7 +132,7 @@ brown splotch is shown for these if the last argument is a constant or a
 call to one of the `testcover-1value-functions'.  This list is probably
 incomplete!"
   :group 'testcover
-  :type 'hook)
+  :type '(repeat symbol))
 
 (defcustom testcover-prog1-functions
   '(prog1 unwind-protect)
@@ -140,13 +140,14 @@ incomplete!"
 brown splotch is shown for these if the first argument is a constant or a
 call to one of the `testcover-1value-functions'."
   :group 'testcover
-  :type 'hook)
+  :type '(repeat symbol))
 
 (defcustom testcover-potentially-1value-functions
   '(add-hook and beep or remove-hook unless when)
   "Functions that are potentially 1-valued.  No brown splotch if actually
 1-valued, no error if actually multi-valued."
-  :group 'testcover)
+  :group 'testcover
+  :type '(repeat symbol))
 
 (defface testcover-nohits
   '((t (:background "DeepPink2")))
@@ -190,8 +191,9 @@ problems with type-ahead or post-command-hook, etc.  If BYTE-COMPILE is
 non-nil, byte-compiles each function after instrumenting."
   (interactive "fStart covering file: ")
   (let ((buf                (find-file filename))
-       (load-read-function 'testcover-read)
-       (edebug-all-defs t))
+       (load-read-function load-read-function))
+    (add-function :around load-read-function
+                  #'testcover--read)
     (setq edebug-form-data                       nil
          testcover-module-constants             nil
          testcover-module-1value-functions nil)
@@ -206,22 +208,26 @@ non-nil, byte-compiles each function after instrumenting."
 (defun testcover-this-defun ()
   "Start coverage on function under point."
   (interactive)
-  (let* ((edebug-all-defs t)
-        (x (symbol-function (eval-defun nil))))
+  (let ((x (let ((edebug-all-defs t))
+             (symbol-function (eval-defun nil)))))
     (testcover-reinstrument x)
     x))
 
-(defun testcover-read (&optional stream)
+(defun testcover--read (orig &optional stream)
   "Read a form using edebug, changing edebug callbacks to testcover callbacks."
-  (let ((x (edebug-read stream)))
-    (testcover-reinstrument x)
-    x))
+  (or stream (setq stream standard-input))
+  (if (eq stream (current-buffer))
+      (let ((x (let ((edebug-all-defs t))
+                 (edebug-read-and-maybe-wrap-form))))
+        (testcover-reinstrument x)
+        x)
+    (funcall (or orig #'read) stream)))
 
 (defun testcover-reinstrument (form)
   "Reinstruments FORM to use testcover instead of edebug.  This
 function modifies the list that FORM points to.  Result is nil if
-FORM should return multiple vlues, t if should always return same
-value, 'maybe if either is acceptable."
+FORM should return multiple values, t if should always return same
+value, `maybe' if either is acceptable."
   (let ((fun (car-safe form))
        id val)
     (cond
@@ -270,9 +276,9 @@ value, 'maybe if either is acceptable."
       (setq id (nth 2 form))
       (setcdr form (nthcdr 2 form))
       (setq val (testcover-reinstrument (nth 2 form)))
-      (if (eq val t)
-         (setcar form 'testcover-1value)
-       (setcar form 'testcover-after))
+      (setcar form (if (eq val t)
+                       'testcover-1value
+                     'testcover-after))
       (when val
        ;;1-valued or potentially 1-valued
        (aset testcover-vector id '1value))
@@ -359,9 +365,9 @@ value, 'maybe if either is acceptable."
                                              ,(nth 3 (cadr form))))
        t)
        (t
-       (if (eq (car (cadr form)) 'edebug-after)
-           (setq id (car (nth 3 (cadr form))))
-         (setq id (car (cadr form))))
+       (setq id (car (if (eq (car (cadr form)) 'edebug-after)
+                          (nth 3 (cadr form))
+                        (cadr form))))
        (let ((testcover-1value-functions
               (cons id testcover-1value-functions)))
          (testcover-reinstrument (cadr form))))))
@@ -379,9 +385,9 @@ value, 'maybe if either is acceptable."
                                   ,(nth 3 (cadr form))))
        'maybe)
        (t
-       (if (eq (car (cadr form)) 'edebug-after)
-           (setq id (car (nth 3 (cadr form))))
-         (setq id (car (cadr form))))
+       (setq id (car (if (eq (car (cadr form)) 'edebug-after)
+                          (nth 3 (cadr form))
+                        (cadr form))))
        (let ((testcover-noreturn-functions
               (cons id testcover-noreturn-functions)))
          (testcover-reinstrument (cadr form))))))
@@ -430,7 +436,7 @@ FUN should be `testcover-reinstrument' for compositional functions,
   "Turn off instrumentation of all macros and functions in FILENAME."
   (interactive "fStop covering file: ")
   (let ((buf (find-file-noselect filename)))
-    (eval-buffer buf t)))
+    (eval-buffer buf)))
 
 
 ;;;=========================================================================
@@ -447,6 +453,12 @@ binding `testcover-vector' to the code-coverage vector for TESTCOVER-SYM
 (defun testcover-after (idx val)
   "Internal function for coverage testing.  Returns VAL after installing it in
 `testcover-vector' at offset IDX."
+  (declare (gv-expander (lambda (do)
+                          (gv-letplace (getter setter) val
+                            (funcall do getter
+                                     (lambda (store)
+                                       `(progn (testcover-after ,idx ,getter)
+                                               ,(funcall setter store))))))))
   (cond
    ((eq (aref testcover-vector idx) 'unknown)
     (aset testcover-vector idx val))
@@ -488,7 +500,7 @@ eliminated by adding more test cases."
         (len      (length points))
         (changed (buffer-modified-p))
         (coverage (get def 'edebug-coverage))
-        ov j item)
+        ov j)
     (or (and def-mark points coverage)
        (error "Missing edebug data for function %s" def))
     (when (> len 0)
@@ -509,7 +521,7 @@ eliminated by adding more test cases."
       (set-buffer-modified-p changed))))
 
 (defun testcover-mark-all (&optional buffer)
-  "Mark all forms in BUFFER that did not get completley tested during
+  "Mark all forms in BUFFER that did not get completely tested during
 coverage tests.  This function creates many overlays."
   (interactive "bMark forms in buffer: ")
   (if buffer