aboutsummaryrefslogtreecommitdiffstats
path: root/test/automated
diff options
context:
space:
mode:
authorStefan Monnier2014-05-10 16:07:01 -0400
committerStefan Monnier2014-05-10 16:07:01 -0400
commit5d03fb436fcfb1fe704cc7a66dec7bd2d21d49f1 (patch)
tree7884824b46c957bc5bfce46066e756d4ae4992db /test/automated
parent4a5c71d7c275b93238c629601526a87eca08e6fd (diff)
downloademacs-5d03fb436fcfb1fe704cc7a66dec7bd2d21d49f1.tar.gz
emacs-5d03fb436fcfb1fe704cc7a66dec7bd2d21d49f1.zip
* lisp/emacs-lisp/nadvice.el: Support adding a given function multiple times.
(advice--member-p): If name is given, only compare the name. (advice--remove-function): Don't stop at the first match. (advice--normalize-place): New function. (add-function, remove-function): Use it. (advice--add-function): Pass the name, if any, to advice--remove-function.
Diffstat (limited to 'test/automated')
-rw-r--r--test/automated/advice-tests.el23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/automated/advice-tests.el b/test/automated/advice-tests.el
index f755e8defef..e0c3b40487e 100644
--- a/test/automated/advice-tests.el
+++ b/test/automated/advice-tests.el
@@ -179,6 +179,29 @@ function being an around advice."
179 (interactive "P") nil) 179 (interactive "P") nil)
180 (should (equal (interactive-form 'sm-test9) '(interactive "P")))) 180 (should (equal (interactive-form 'sm-test9) '(interactive "P"))))
181 181
182(ert-deftest advice-test-multiples ()
183 (let ((sm-test10 (lambda (a) (+ a 10)))
184 (sm-advice (lambda (x) (if (consp x) (list (* 5 (car x))) (* 4 x)))))
185 (should (equal (funcall sm-test10 5) 15))
186 (add-function :filter-args (var sm-test10) sm-advice)
187 (should (equal (funcall sm-test10 5) 35))
188 (add-function :filter-return (var sm-test10) sm-advice)
189 (should (equal (funcall sm-test10 5) 60))
190 ;; Make sure we can add multiple times the same function, under the
191 ;; condition that they have different `name' properties.
192 (add-function :filter-args (var sm-test10) sm-advice '((name . "args")))
193 (should (equal (funcall sm-test10 5) 140))
194 (remove-function (var sm-test10) "args")
195 (should (equal (funcall sm-test10 5) 60))
196 (add-function :filter-args (var sm-test10) sm-advice '((name . "args")))
197 (add-function :filter-return (var sm-test10) sm-advice '((name . "ret")))
198 (should (equal (funcall sm-test10 5) 560))
199 ;; Make sure that if we specify to remove a function that was added
200 ;; multiple times, they are all removed, rather than removing only some
201 ;; arbitrary subset of them.
202 (remove-function (var sm-test10) sm-advice)
203 (should (equal (funcall sm-test10 5) 15))))
204
182;; Local Variables: 205;; Local Variables:
183;; no-byte-compile: t 206;; no-byte-compile: t
184;; End: 207;; End: