mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-15 09:47:20 +00:00
Make use of the `ert-with-function-mocked' macro
* test/lisp/calendar/icalendar-tests.el (icalendar--create-uid): * test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9781): Use `ert-with-function-mocked' instead of implementing the fragile `unwind-protect' logic openly.
This commit is contained in:
parent
a77c6799c1
commit
d57ca9f851
@ -32,6 +32,7 @@
|
||||
;;; Code:
|
||||
|
||||
(require 'ert)
|
||||
(require 'ert-x)
|
||||
(require 'icalendar)
|
||||
|
||||
;; ======================================================================
|
||||
@ -58,23 +59,16 @@
|
||||
(ert-deftest icalendar--create-uid ()
|
||||
"Test for `icalendar--create-uid'."
|
||||
(let* ((icalendar-uid-format "xxx-%t-%c-%h-%u-%s")
|
||||
t-ct
|
||||
(icalendar--uid-count 77)
|
||||
(entry-full "30.06.1964 07:01 blahblah")
|
||||
(hash (format "%d" (abs (sxhash entry-full))))
|
||||
(contents "DTSTART:19640630T070100\nblahblah")
|
||||
(username (or user-login-name "UNKNOWN_USER"))
|
||||
)
|
||||
(fset 't-ct (symbol-function 'current-time))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(fset 'current-time (lambda () '(1 2 3)))
|
||||
(should (= 77 icalendar--uid-count))
|
||||
(should (string= (concat "xxx-123-77-" hash "-" username "-19640630")
|
||||
(icalendar--create-uid entry-full contents)))
|
||||
(should (= 78 icalendar--uid-count)))
|
||||
;; restore 'current-time
|
||||
(fset 'current-time (symbol-function 't-ct)))
|
||||
(username (or user-login-name "UNKNOWN_USER")))
|
||||
(ert-with-function-mocked current-time (lambda () '(1 2 3))
|
||||
(should (= 77 icalendar--uid-count))
|
||||
(should (string= (concat "xxx-123-77-" hash "-" username "-19640630")
|
||||
(icalendar--create-uid entry-full contents)))
|
||||
(should (= 78 icalendar--uid-count)))
|
||||
(setq contents "blahblah")
|
||||
(setq icalendar-uid-format "yyy%syyy")
|
||||
(should (string= (concat "yyyDTSTARTyyy")
|
||||
|
@ -25,6 +25,7 @@
|
||||
;;; Code:
|
||||
|
||||
(require 'ert)
|
||||
(require 'ert-x)
|
||||
(require 'vc-bzr)
|
||||
(require 'vc-dir)
|
||||
|
||||
@ -101,12 +102,8 @@
|
||||
(while (vc-dir-busy)
|
||||
(sit-for 0.1))
|
||||
(vc-dir-mark-all-files t)
|
||||
(let ((f (symbol-function 'y-or-n-p)))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(fset 'y-or-n-p (lambda (prompt) t))
|
||||
(vc-next-action nil))
|
||||
(fset 'y-or-n-p f)))
|
||||
(ert-with-function-mocked y-or-n-p (lambda (_) t)
|
||||
(vc-next-action nil))
|
||||
(should (get-buffer "*vc-log*")))
|
||||
(delete-directory homedir t))))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user