1 ;;; advice-tests.el --- Test suite for the new advice thingy.
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 (defvar advice-tests--data
25 '(((defun sm-test1 (x) (+ x
4))
27 ((advice-add 'sm-test1
:around
(lambda (f y
) (* (funcall f y
) 5)))
29 ((defun sm-test1 (x) (+ x
14))
31 ((null (get 'sm-test1
'defalias-fset-function
)) nil
)
32 ((advice-remove 'sm-test1
(lambda (f y
) (* (funcall f y
) 5)))
34 ((null (get 'sm-test1
'defalias-fset-function
)) t
)
36 ((defun sm-test2 (x) (+ x
4))
38 ((defadvice sm-test2
(around sm-test activate
)
39 ad-do-it
(setq ad-return-value
(* ad-return-value
5)))
41 ((ad-deactivate 'sm-test2
)
43 ((ad-activate 'sm-test2
)
45 ((defun sm-test2 (x) (+ x
14))
47 ((null (get 'sm-test2
'defalias-fset-function
)) nil
)
48 ((ad-remove-advice 'sm-test2
'around
'sm-test
)
50 ((ad-activate 'sm-test2
)
52 ((null (get 'sm-test2
'defalias-fset-function
)) t
)
54 ((advice-add 'sm-test3
:around
55 (lambda (f &rest args
) `(toto ,(apply f args
)))
56 '((name . wrap-with-toto
)))
57 (defmacro sm-test3
(x) `(call-test3 ,x
))
58 (macroexpand '(sm-test3 56)) (toto (call-test3 56)))
60 ((defadvice sm-test4
(around wrap-with-toto activate
)
61 ad-do-it
(setq ad-return-value
`(toto ,ad-return-value
)))
62 (defmacro sm-test4
(x) `(call-test4 ,x
))
63 (macroexpand '(sm-test4 56)) (toto (call-test4 56)))
64 ((defmacro sm-test4
(x) `(call-testq ,x
))
65 (macroexpand '(sm-test4 56)) (toto (call-testq 56)))
67 ;; Combining old style and new style advices.
68 ((defun sm-test5 (x) (+ x
4))
70 ((advice-add 'sm-test5
:around
(lambda (f y
) (* (funcall f y
) 5)))
72 ((defadvice sm-test5
(around test activate
)
73 ad-do-it
(setq ad-return-value
(+ ad-return-value
0.1)))
75 ((ad-deactivate 'sm-test5
)
77 ((ad-activate 'sm-test5
)
79 ((defun sm-test5 (x) (+ x
14))
81 ((advice-remove 'sm-test5
(lambda (f y
) (* (funcall f y
) 5)))
84 ;; This used to signal an error (bug#12858).
85 ((autoload 'sm-test6
"foo")
86 (defadvice sm-test6
(around test activate
)
92 (ert-deftest advice-tests
()
95 (dolist (test advice-tests--data
)
96 (let ((res (eval `(progn ,@(butlast test
)))))
97 (should (equal (car (last test
)) res
))))))
100 ;; no-byte-compile: t
103 ;;; advice-tests.el ends here.