all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* testcover: setf-method and treatment of `defcustom'
@ 2012-09-10  7:11 Stefan Merten
  2012-09-11  3:40 ` Stefan Monnier
  2012-09-12 19:32 ` Stefan Merten
  0 siblings, 2 replies; 8+ messages in thread
From: Stefan Merten @ 2012-09-10  7:11 UTC (permalink / raw
  To: emacs-devel; +Cc: Jonathan Yavner

[-- Attachment #1: Type: text/plain, Size: 2697 bytes --]

Hi!

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
with

	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
		  (mapcar
		   (lambda (sym)
		     (if (not (plist-member (symbol-plist sym) 'standard-value))
			 sym))
		   testcover-module-constants)))))

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.


						Grüße

						Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 307 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-09-18 21:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-10  7:11 testcover: setf-method and treatment of `defcustom' Stefan Merten
2012-09-11  3:40 ` Stefan Monnier
2012-09-12 20:38   ` Stefan Merten
2012-09-13 13:09     ` Stefan Monnier
2012-09-13 20:45       ` Stefan Merten
2012-09-16  9:06   ` Stefan Merten
2012-09-18 21:37     ` Stefan Monnier
2012-09-12 19:32 ` Stefan Merten

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.