[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

testcover: setf-method and treatment of `defcustom'

From: Stefan Merten
Subject: testcover: setf-method and treatment of `defcustom'
Date: Mon, 10 Sep 2012 09:11:42 +0200


I just found the `testcover' package in Emacs 23.1.1 (the source in
Emacs 24 changed only very slightly). I tried it with my tests for
rst.el and after a lot of investigation got it to work with my `ert'
based test suite.

I had to solve two problems. When I ran my ert tests some of them fail

        No setf-method known for testcover-after

I looked into this and found `defsetf' in `cl-macs'. `testcover-after'
is a function which has only some side effect. I think

  (defsetf testcover-after (idx val) (store)
    (list 'progn
          (list 'testcover-after idx val)
          (list 'setf val store)))

does the right thing. At least the error messages described above
vanish for me.

AFAICS the only thing which can go wrong with this setf-method seems
to be the double evaluation of `val' - although I don't know whether
this really is evaluated twice in this context. Too much macro...

I still had another error left, however.

         Value of form marked with `1value' does vary: ...

It took me some time to discover that for some reason `testcover'
treats `defcustom' like `defconst'. This is of course lethal for a
test which changes a customizable variable temporarily - e.g. by `let'
- to test a certain functionality.

For now I defined

  (defun rst-defcustom-testcover ()
    "Remove all customized variables from `testcover-module-constants'.
  This seems to be a bug in `testcover': `defcustom' variables are
  considered constants.  Revert it with this function after each `defcustom'."
    (when (boundp 'testcover-module-constants)
      (setq testcover-module-constants
            (delq nil
                   (lambda (sym)
                     (if (not (plist-member (symbol-plist sym) 'standard-value))

and put a call to this function after every `defcustom'. This helps
but IMHO is of selected ugliness.

I'd rather suggest this patch (against Emacs 24 sources):

  --- ../emacs/trunk/lisp/emacs-lisp/testcover.el       2012-04-20 
19:50:27.000000000 +0200
  +++ /home/stefan/tmp/testcover.el     2012-09-10 08:58:01.000000000 +0200
  @@ -297,7 +297,7 @@
          (push (cadr form) testcover-module-1value-functions))
         (when (eq val 'maybe)
          (push (cadr form) testcover-module-potentially-1value-functions)))
  -     ((memq fun '(defconst defcustom))
  +     ((eq fun 'defconst)
         ;;Define this symbol as 1-valued
         (push (cadr form) testcover-module-constants)
         (testcover-reinstrument-list (cddr form)))

In addition it would be certainly helpful to integrate the `defsetf'
form above somehow in `testcover'. However, I have no idea how to do
this in a good way.



Attachment: pgpFXgwzMfBUN.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]