From: Ryan <rct@thompsonclan.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 3984@debbugs.gnu.org
Subject: bug#3984:
Date: Thu, 19 Sep 2013 14:59:43 -0700 [thread overview]
Message-ID: <523B73CF.4080105@thompsonclan.org> (raw)
In-Reply-To: <523B4F4E.3060204@thompsonclan.org>
[-- Attachment #1: Type: text/plain, Size: 1560 bytes --]
On Thu Sep 19 12:23:58 2013, Ryan wrote:
>
> On a related note, I just noticed that the
> "advice-test-called-interactively-p" test in
> test/automated/advice-tests.el happens to pass, but only because it
> doesn't use "called-interactively-p" inside the original function, but
> rather only inside the advice itself. Also, it doesn't test advising
> "call-interactively" itself. I think I will see about writing a proper
> test first, and then use that to start debugging.
>
Ok, I have written a couple of tests, two of which are currently failing
(mine are the ones with numbered suffixes 2 through 5). I am attaching a
patch that adds these tests. ERT output is below:
$ open .
techne:emacs-trunk ryan$ src/emacs -batch -Q -l ert -l
test/automated/advice-tests.el -f ert-run-tests-batch-and-exit
Running 10 tests (2013-09-19 14:56:00-0700)
passed 1/10 advice-test-called-interactively-p
failed 2/10 advice-test-called-interactively-p-2
passed 3/10 advice-test-called-interactively-p-3
failed 4/10 advice-test-called-interactively-p-4
passed 5/10 advice-test-called-interactively-p-5
passed 6/10 advice-test-interactive
passed 7/10 advice-test-preactivate
ad-handle-definition: `sm-test2' got redefined
ad-handle-definition: `sm-test4' got redefined
passed 8/10 advice-tests-advice
ad-handle-definition: `sm-test5' got redefined
passed 9/10 advice-tests-combination
passed 10/10 advice-tests-nadvice
Ran 10 tests, 10 results as expected (2013-09-19 14:56:00-0700)
2 expected failures
[-- Attachment #2: more-advice-interactive-tests.diff --]
[-- Type: text/plain, Size: 3609 bytes --]
diff --git a/test/automated/advice-tests.el b/test/automated/advice-tests.el
index 69c15e3..65577ad 100644
--- a/test/automated/advice-tests.el
+++ b/test/automated/advice-tests.el
@@ -23,6 +23,21 @@
(require 'ert)
+(defun clear-advice (symbol)
+ "Reset SYMBOL's function to its original unadvised definition."
+ (let ((func (symbol-function symbol)))
+ (while (advice--p func)
+ (setq func (advice--cdr func)))
+ (fset symbol func)))
+
+(defmacro post-restore-func (func &rest body)
+ (let ((fdef (symbol-function func)))
+ `(unwind-protect
+ (progn ,@body)
+ (fset ',func ,fdef))))
+(put 'post-restore-func 'lisp-indent-function
+ (get 'prog1 'lisp-indent-function))
+
(ert-deftest advice-tests-nadvice ()
"Test nadvice code."
(defun sm-test1 (x) (+ x 4))
@@ -113,6 +128,60 @@
(cons (cons 2 (called-interactively-p)) (apply f args))))
(should (equal (call-interactively 'sm-test7) '((2 . t) (1 . t) 11))))
+(ert-deftest advice-test-called-interactively-p-2 ()
+ "Check interaction between around advice and called-interactively-p.
+
+This tests the currently broken case of the innermost advice to a
+function being an around advice."
+ :expected-result :failed
+ (defun sm-test7.2 () (interactive) (cons 1 (called-interactively-p)))
+ (clear-advice 'sm-test7.2)
+ (advice-add 'sm-test7.2 :around
+ (lambda (f &rest args)
+ (list (cons 1 (called-interactively-p)) (apply f args))))
+ (advice-add 'sm-test7.2 :before #'ignore)
+ (advice-add 'sm-test7.2 :after #'ignore)
+ ;(advice-add 'sm-test7.2 :filter-args #'list)
+ ;(advice-add 'sm-test7.2 :filter-return #'identity)
+ (should (equal (sm-test7.2) '((1 . nil) (1 . nil))))
+ (should (equal (call-interactively 'sm-test7.2) '((1 . t) (1 . t)))))
+
+(ert-deftest advice-test-called-interactively-p-3 ()
+ "Check interaction between before advice and called-interactively-p.
+
+This tests the case of the innermost advice being before"
+ (defun sm-test7.3 () (interactive) (cons 1 (called-interactively-p)))
+ (advice-add 'sm-test7.3 :before #'ignore)
+ ;(advice-add 'sm-test7.3 :filter-args #'list)
+ ;(advice-add 'sm-test7.3 :filter-return #'identity)
+ (should (equal (sm-test7.3) '(1 . nil)))
+ (should (equal (call-interactively 'sm-test7.3) '(1 . t))))
+
+(ert-deftest advice-test-called-interactively-p-4 ()
+ "Check interaction between advice on call-interactively and called-interactively-p.
+
+This tests the case where call-interactively itself is advised,
+which is currently broken."
+ :expected-result :failed
+ (defun sm-test7.4 () (interactive) (cons 1 (called-interactively-p)))
+ (post-restore-func call-interactively
+ (advice-add 'call-interactively :before #'ignore)
+ (should (equal (sm-test7.4) '(1 . nil)))
+ (should (equal (call-interactively 'sm-test7.4) '(1 . t)))))
+
+(ert-deftest advice-test-called-interactively-p-5 ()
+ "Check interaction between non-innermost around advice and called-interactively-p.
+
+This tests the case where a function has around advice, but it is
+not the innermost advice."
+ (defun sm-test7.5 () (interactive) (cons 1 (called-interactively-p)))
+ (advice-add 'sm-test7.5 :before #'ignore)
+ (advice-add 'sm-test7.5 :around #'funcall)
+ ;(advice-add 'sm-test7.5 :filter-args #'list)
+ ;(advice-add 'sm-test7.5 :filter-return #'identity)
+ (should (equal (sm-test7.5) '(1 . nil)))
+ (should (equal (call-interactively 'sm-test7.5) '(1 . t))))
+
(ert-deftest advice-test-interactive ()
"Check handling of interactive spec."
(defun sm-test8 (a) (interactive "p") a)
next prev parent reply other threads:[~2013-09-19 21:59 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-30 22:37 bug#3984: 23.0.96; defadvice of call-interactively defeats interactive-p Drew Adams
2009-07-31 1:58 ` Stefan Monnier
2009-07-31 14:19 ` Drew Adams
2009-07-31 19:31 ` Stefan Monnier
2009-07-31 20:04 ` Drew Adams
2011-10-10 6:00 ` Kai Tetzlaff
2011-10-11 14:26 ` Drew Adams
2011-10-11 15:46 ` Stefan Monnier
2011-10-11 16:05 ` Drew Adams
2013-09-10 20:29 ` Christopher Wellons
2013-09-11 0:29 ` Stefan Monnier
2013-09-13 8:56 ` bug#3984: Fix for #3984 Ryan
2013-09-13 13:18 ` Stefan Monnier
2013-09-13 18:30 ` Ryan
2013-09-13 19:27 ` Ryan
2013-09-13 21:02 ` Stefan Monnier
2013-09-17 3:18 ` Ryan
2013-09-17 13:10 ` Stefan Monnier
2013-09-17 17:22 ` bug#3984: Ryan
2013-09-18 1:46 ` bug#3984: Stefan Monnier
2013-09-18 23:30 ` bug#3984: Ryan
2013-09-19 0:47 ` bug#3984: Ryan
2013-09-19 3:38 ` bug#3984: Stefan Monnier
2013-09-19 8:06 ` bug#3984: Ryan
2013-09-19 19:23 ` bug#3984: Ryan
2013-09-19 20:59 ` bug#3984: Stefan Monnier
2013-09-19 21:59 ` Ryan [this message]
2013-09-20 4:23 ` bug#3984: Ryan
2013-09-20 4:58 ` bug#3984: Fix case where call-interactively is advised Ryan
2013-09-20 5:03 ` bug#3984: Ryan
2013-09-20 14:35 ` bug#3984: Stefan Monnier
2013-09-20 16:54 ` bug#3984: Ryan
2013-09-20 16:56 ` bug#3984: Ryan
2013-09-20 14:54 ` bug#3984: Stefan Monnier
2013-09-20 16:50 ` bug#3984: Ryan
2013-09-20 19:59 ` bug#3984: Stefan Monnier
2013-09-13 10:24 ` bug#3984: bug#123: Potential fix Ryan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=523B73CF.4080105@thompsonclan.org \
--to=rct@thompsonclan.org \
--cc=3984@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).