Skip to content
Browse files

Rename function prefix

  • Loading branch information...
1 parent d8a391a commit be6d2a5978cd559550141b2f8b6fc15f8a3c6537 @uk-ar committed Oct 10, 2012
Showing with 108 additions and 108 deletions.
  1. +39 −39 el-spy.el
  2. +69 −69 test/el-spy-test.el
View
78 el-spy.el
@@ -1,92 +1,92 @@
(require 'advice)
(require 'cl)
-;;for should in el-spec:make-args-keylist
+;;for should in el-spy:make-args-keylist
(require 'ert)
-(defun el-spec:setup-mock (funcsym)
- (el-spec:put-args funcsym nil)
+(defun el-spy:setup-mock (funcsym)
+ (el-spy:put-args funcsym nil)
(when (fboundp funcsym)
- (put funcsym 'el-spec:original-func (symbol-function funcsym))))
+ (put funcsym 'el-spy:original-func (symbol-function funcsym))))
-(defun el-spec:get-original-func (symbol)
- (get symbol 'el-spec:original-func))
+(defun el-spy:get-original-func (symbol)
+ (get symbol 'el-spy:original-func))
-(defun el-spec:teardown-mock (funcsym)
- (el-spec:put-args funcsym nil)
- (let ((func (el-spec:get-original-func funcsym)))
+(defun el-spy:teardown-mock (funcsym)
+ (el-spy:put-args funcsym nil)
+ (let ((func (el-spy:get-original-func funcsym)))
(if func
(ad-safe-fset funcsym func)
(fmakunbound funcsym))))
(defmacro with-mock2 (&rest body)
(declare (indent 0) (debug t))
`(progn
- (let ((el-spec:original-func nil))
+ (let ((el-spy:original-func nil))
(unwind-protect
(progn ,@body)
- (mapc #'el-spec:teardown-mock el-spec:original-func)
+ (mapc #'el-spy:teardown-mock el-spy:original-func)
))))
-(defun el-spec:get-args (symbol)
- (get symbol 'el-spec:args))
-(defalias 'el-spec:args-for-call 'el-spec:get-args)
+(defun el-spy:get-args (symbol)
+ (get symbol 'el-spy:args))
+(defalias 'el-spy:args-for-call 'el-spy:get-args)
-(defun el-spec:put-args (symbol args)
- (put symbol 'el-spec:args args))
+(defun el-spy:put-args (symbol args)
+ (put symbol 'el-spy:args args))
-(defun el-spec:append-args (symbol arglist)
- (el-spec:put-args
+(defun el-spy:append-args (symbol arglist)
+ (el-spy:put-args
symbol
- (append (get symbol 'el-spec:args) arglist)))
+ (append (get symbol 'el-spy:args) arglist)))
-(defun el-spec:not-called (symbol)
- (eq (length (el-spec:get-args symbol)) 0))
+(defun el-spy:not-called (symbol)
+ (eq (length (el-spy:get-args symbol)) 0))
-(defun el-spec:called-count (symbol)
- (length (el-spec:get-args symbol)))
+(defun el-spy:called-count (symbol)
+ (length (el-spy:get-args symbol)))
-(defvar el-spec:func-name nil)
+(defvar el-spy:func-name nil)
(defmacro defmock (symbol arglist &rest body)
(declare (indent defun) (debug t))
`(progn
- (unless (boundp 'el-spec:original-func)
+ (unless (boundp 'el-spy:original-func)
(error "not in with-mock"))
- (push ',symbol el-spec:original-func)
- (el-spec:setup-mock ',symbol)
+ (push ',symbol el-spy:original-func)
+ (el-spy:setup-mock ',symbol)
(ad-safe-fset
',symbol
(lambda ,arglist
- (setq el-spec:func-name ',symbol)
- (el-spec:append-args ',symbol (list (mapcar 'symbol-value ',arglist)))
+ (setq el-spy:func-name ',symbol)
+ (el-spy:append-args ',symbol (list (mapcar 'symbol-value ',arglist)))
;; Even if body include interactive, it works well.
;; Undocumented behavior?
,@body)
)))
-(defun el-spec:make-returns-keylist (list default)
+(defun el-spy:make-returns-keylist (list default)
(append
(let ((i 0))
(mapcar (lambda (elem) (list (incf i) elem)) list))
`((t ,default))))
-(defun el-spec:make-args-keylist (arg list default)
- (el-spec:make-returns-keylist
+(defun el-spy:make-args-keylist (arg list default)
+ (el-spy:make-returns-keylist
(mapcar (lambda (elem) (list 'should `(equal ,arg ,elem))) list) 6)
)
-(defmacro el-spec:returns (list default)
- `(case (el-spec:called-count el-spec:func-name)
- ,@(el-spec:make-returns-keylist list default)))
+(defmacro el-spy:returns (list default)
+ `(case (el-spy:called-count el-spy:func-name)
+ ,@(el-spy:make-returns-keylist list default)))
-(defmacro el-spec:args (symbol list default)
- `(case (el-spec:called-count el-spec:func-name)
- ,@(el-spec:make-args-keylist symbol list default)))
+(defmacro el-spy:args (symbol list default)
+ `(case (el-spy:called-count el-spy:func-name)
+ ,@(el-spy:make-args-keylist symbol list default)))
;; el-mock limitation
;; (with-mock
;; (mock (test1) :times 0)
;; (call-interactively 'test1);; error
;; )
-(provide 'test-double)
+(provide 'el-spy)
View
138 test/el-spy-test.el
@@ -1,7 +1,7 @@
(require 'ert)
-(require 'test-double)
+(require 'el-spy)
-;; test for test-double
+;; test for el-spy
(defun test1 (a b) 'test1-original)
(defun test2 (a b) 'test2-original)
@@ -10,39 +10,39 @@
(ert-deftest simple ();; spy
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b) 'test1-mock)
(should (eq (test1 1 2) 'test1-mock))
- (should (eq (el-spec:called-count 'test1) 1))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
+ (should (eq (el-spy:called-count 'test1) 1))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
(should (eq (test1 3 4) 'test1-mock))
- (should (eq (el-spec:called-count 'test1) 2))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
+ (should (eq (el-spy:called-count 'test1) 2))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
)
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
(ert-deftest proxy ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b)
- (funcall (el-spec:get-original-func 'test1) a b))
+ (funcall (el-spy:get-original-func 'test1) a b))
(should (eq (test1 1 2) 'test1-original))
- (should (eq (el-spec:called-count 'test1) 1))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
+ (should (eq (el-spy:called-count 'test1) 1))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
(should (eq (test1 3 4) 'test1-original))
- (should (eq (el-spec:called-count 'test1) 2))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
+ (should (eq (el-spy:called-count 'test1) 2))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
)
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
(ert-deftest advice1 ()
@@ -57,19 +57,19 @@
(defmock test1 (a b) 'test1-mock)
(should (eq (test1 1 2) 'test1-mock))
- (should (eq (el-spec:called-count 'test1) 1))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
+ (should (eq (el-spy:called-count 'test1) 1))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
(should (eq (test1 3 4) 'test1-mock))
- (should (eq (el-spec:called-count 'test1) 2))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
+ (should (eq (el-spy:called-count 'test1) 2))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
)
(should (eq (test1 1 2) 'test1-advice))
)
(ad-disable-advice 'test1 'around 'test1-ad)
(ad-activate 'test1)
(should (eq (test1 3 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
)
@@ -85,22 +85,22 @@
(defmock test1 (a b) 'test1-mock)
(should (eq (test1 1 2) 'test1-mock))
- (should (eq (el-spec:called-count 'test1) 1))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
+ (should (eq (el-spy:called-count 'test1) 1))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
(ad-disable-advice 'test1 'around 'test1-ad)
;; (ad-activate 'test1);limitation of ad-safe-fset?
(should (eq (test1 3 4) 'test1-mock))
- (should (eq (el-spec:called-count 'test1) 2))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
+ (should (eq (el-spy:called-count 'test1) 2))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
)
(should (eq (test1 1 2) 'test1-advice))
)
(ad-disable-advice 'test1 'around 'test1-ad)
(ad-activate 'test1)
(should (eq (test1 3 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
)
@@ -113,28 +113,28 @@
(defmock test1 (a b) 'test1-mock)
(should (eq (test1 1 2) 'test1-mock))
- (should (eq (el-spec:called-count 'test1) 1))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
+ (should (eq (el-spy:called-count 'test1) 1))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
;; (ad-enable-advice 'test1 'around 'test1-ad)
;; (ad-activate 'test1);fails in 2nd time
;; ;; adviced
;; (should (eq (test1 3 4) 'test1-advice))
;; ;; not record
- ;; (should (eq (el-spec:called-count 'test1) 1))
- ;; (should (equal (el-spec:get-args 'test1) '((1 2))))
+ ;; (should (eq (el-spy:called-count 'test1) 1))
+ ;; (should (equal (el-spy:get-args 'test1) '((1 2))))
)
(ad-disable-advice 'test1 'around 'test1-ad)
(ad-activate 'test1)
)
(should (eq (test1 3 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
))
(ert-deftest interactive ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b)
(interactive)
@@ -147,105 +147,105 @@
(should (eq (test1 1 2) 'test1-mock))
(should (eq (test2 3 4) 'test2-mock))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
- (should (equal (el-spec:get-args 'test2) '((3 4))))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
+ (should (equal (el-spy:get-args 'test2) '((3 4))))
(should (eq (test1 3 4) 'test1-mock))
(should (eq (test2 5 6) 'test2-mock))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
- (should (equal (el-spec:get-args 'test2) '((3 4) (5 6))))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
+ (should (equal (el-spy:get-args 'test2) '((3 4) (5 6))))
)
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
(ert-deftest assert-fail1 ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(should-error
(with-mock2
(defmock test1 (a b) 'test1-mock)
(should (eq (test1 1 3) 'test1-mock))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
(should (eq (test1 3 4) 'test1-mock))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
)
:type 'ert-test-failed)
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
(ert-deftest assert-fail2 ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(should-error
(with-mock2
(defmock test1 (a b) 'test1-mock)
(should (eq (test1 1 2) 'test1-mock))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
(should (eq (test1 3 3) 'test1-mock))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
)
:type 'ert-test-failed)
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
(ert-deftest wrong-arg-error ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(should-error
(with-mock2
(defmock test1 (a b) 'test1-mock)
(should (eq (test1 1 2) 'test1-mock))
- (should (equal (el-spec:get-args 'test1) '((1 2))))
+ (should (equal (el-spy:get-args 'test1) '((1 2))))
(should (eq (test1 3 4) 'test1-mock))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
(test1 2 3 4)
)
:type 'wrong-number-of-arguments)
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
(ert-deftest get-func-name ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b)
- el-spec:func-name)
+ el-spy:func-name)
(should (eq (test1 3 4) 'test1)))
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
)
(ert-deftest precheck-args ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b)
(should (eq a 1)))
(should (eq (test1 1 2) t))
(should-error (test1 3 4) :type 'ert-test-failed)
- (should (eq (el-spec:called-count 'test1) 2))
- (should (equal (el-spec:get-args 'test1) '((1 2) (3 4))))
+ (should (eq (el-spy:called-count 'test1) 2))
+ (should (equal (el-spy:get-args 'test1) '((1 2) (3 4))))
)
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil)))
+ (should (equal (el-spy:get-args 'test1) nil)))
(ert-deftest sequensial-return1 ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b)
- (case (el-spec:called-count el-spec:func-name)
+ (case (el-spy:called-count el-spy:func-name)
(1 "a")
(2 "b")
(t "c")))
@@ -254,52 +254,52 @@
(should (equal (test1 1 2) "c"))
(should (equal (test1 1 2) "c")))
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil)))
+ (should (equal (el-spy:get-args 'test1) nil)))
(ert-deftest test-make-args-keylist ()
- (should (equal (el-spec:make-args-keylist 'x '(3 4) 6)
+ (should (equal (el-spy:make-args-keylist 'x '(3 4) 6)
'((1 (should (equal x 3))) (2 (should (equal x 4))) (t 6)))))
(ert-deftest test-make-returns-keylist ()
- (should (equal (el-spec:make-returns-keylist '(4 5) 6)
+ (should (equal (el-spy:make-returns-keylist '(4 5) 6)
'((1 4) (2 5) (t 6)))))
(ert-deftest sequensial-args ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b)
- (el-spec:args a (1 3 5) "c")
+ (el-spy:args a (1 3 5) "c")
)
(should (test1 1 2))
(should (test1 3 2))
(should-error (test1 6 2) :type 'ert-test-failed)
)
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil)))
+ (should (equal (el-spy:get-args 'test1) nil)))
(ert-deftest sequensial-return2 ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b)
- (el-spec:returns ("a" "b") "c"))
+ (el-spy:returns ("a" "b") "c"))
(should (equal (test1 1 2) "a"))
(should (equal (test1 1 2) "b"))
(should (equal (test1 1 2) "c"))
(should (equal (test1 1 2) "c")))
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil)))
+ (should (equal (el-spy:get-args 'test1) nil)))
(ert-deftest sequensial-return-not-over ()
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil))
+ (should (equal (el-spy:get-args 'test1) nil))
(with-mock2
(defmock test1 (a b)
- (el-spec:returns ("a" "b") (should nil)))
+ (el-spy:returns ("a" "b") (should nil)))
(should (equal (test1 1 2) "a"))
(should (equal (test1 1 2) "b"))
(should-error (test1 1 2) :type 'ert-test-failed))
(should (eq (test1 1 2) 'test1-original))
- (should (equal (el-spec:get-args 'test1) nil)))
+ (should (equal (el-spy:get-args 'test1) nil)))

0 comments on commit be6d2a5

Please sign in to comment.
Something went wrong with that request. Please try again.