summaryrefslogtreecommitdiff
path: root/test/lisp/use-package
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/use-package')
-rw-r--r--test/lisp/use-package/use-package-chords-tests.el161
-rw-r--r--test/lisp/use-package/use-package-tests.el68
2 files changed, 195 insertions, 34 deletions
diff --git a/test/lisp/use-package/use-package-chords-tests.el b/test/lisp/use-package/use-package-chords-tests.el
new file mode 100644
index 00000000000..3c3dc4b4fe0
--- /dev/null
+++ b/test/lisp/use-package/use-package-chords-tests.el
@@ -0,0 +1,161 @@
+;;; use-package-chords-tests.el --- Tests for use-package-chords.el -*- lexical-binding: t; -*-
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3, or (at
+;; your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;;
+
+
+;;; Code:
+
+(require 'use-package)
+(require 'use-package-tests)
+(require 'use-package-chords)
+
+(defmacro match-expansion (form &rest value)
+ `(should (pcase (expand-minimally ,form)
+ ,@(mapcar #'(lambda (x) (list x t)) value))))
+
+(defun use-package-test-normalize-chord (&rest args)
+ (apply #'use-package-normalize-binder 'foo :chords args))
+
+(ert-deftest use-package-test-normalize/:chords-1 ()
+ (should (equal (use-package-test-normalize-chord
+ '(("C-a" . alpha)))
+ '(("C-a" . alpha)))))
+
+(ert-deftest use-package-test-normalize/:chords-2 ()
+ (should (equal (use-package-test-normalize-chord
+ '(("C-a" . alpha)
+ :map foo-map
+ ("C-b" . beta)))
+ '(("C-a" . alpha)
+ :map foo-map
+ ("C-b" . beta)))))
+
+(ert-deftest use-package-test-normalize/:chords-3 ()
+ (should (equal (use-package-test-normalize-chord
+ '(:map foo-map
+ ("C-a" . alpha)
+ ("C-b" . beta)))
+ '(:map foo-map
+ ("C-a" . alpha)
+ ("C-b" . beta)))))
+
+(ert-deftest use-package-test/:chords-1 ()
+ (match-expansion
+ (use-package foo :chords ("C-k" . key1) ("C-u" . key2))
+ `(progn
+ (unless
+ (fboundp 'key1)
+ (autoload #'key1 "foo" nil t))
+ (unless
+ (fboundp 'key2)
+ (autoload #'key2 "foo" nil t))
+ (bind-chord "C-k" #'key1 nil)
+ (bind-chord "C-u" #'key2 nil))))
+
+(ert-deftest use-package-test/:chords-2 ()
+ (match-expansion
+ (use-package foo :chords (("C-k" . key1) ("C-u" . key2)))
+ `(progn
+ (unless (fboundp 'key1)
+ (autoload #'key1 "foo" nil t))
+ (unless (fboundp 'key2)
+ (autoload #'key2 "foo" nil t))
+ (bind-chord "C-k" #'key1 nil)
+ (bind-chord "C-u" #'key2 nil))))
+
+(ert-deftest use-package-test/:chords-3 ()
+ (match-expansion
+ (use-package foo :chords (:map my-map ("C-k" . key1) ("C-u" . key2)))
+ `(progn
+ (unless
+ (fboundp 'key1)
+ (autoload #'key1 "foo" nil t))
+ (unless
+ (fboundp 'key2)
+ (autoload #'key2 "foo" nil t))
+ (if
+ (boundp 'my-map)
+ (progn
+ (bind-chord "C-k" #'key1 my-map)
+ (bind-chord "C-u" #'key2 my-map))
+ (eval-after-load 'foo
+ '(progn
+ (bind-chord "C-k" #'key1 my-map)
+ (bind-chord "C-u" #'key2 my-map)))))))
+
+(ert-deftest use-package-test/:chords-4 ()
+ (should-error
+ (match-expansion
+ (use-package foo :chords :map my-map ("C-k" . key1) ("C-u" . key2))
+ `(bind-chords :package foo))))
+
+(ert-deftest use-package-test/:chords-5 ()
+ (match-expansion
+ (use-package foo :chords ("C-k" . key1) (:map my-map ("C-u" . key2)))
+ `(progn
+ (unless (fboundp 'key1)
+ (autoload #'key1 "foo" nil t))
+ (unless (fboundp 'key2)
+ (autoload #'key2 "foo" nil t))
+ (progn
+ (bind-chord "C-k" #'key1 nil)
+ (if
+ (boundp 'my-map)
+ (bind-chord "C-u" #'key2 my-map)
+ (eval-after-load 'foo
+ '(bind-chord "C-u" #'key2 my-map)))))))
+
+(ert-deftest use-package-test/:chords-6 ()
+ (match-expansion
+ (use-package foo
+ :chords
+ ("C-k" . key1)
+ (:map my-map ("C-u" . key2))
+ (:map my-map2 ("C-u" . key3)))
+ `(progn
+ (unless
+ (fboundp 'key1)
+ (autoload #'key1 "foo" nil t))
+ (unless
+ (fboundp 'key2)
+ (autoload #'key2 "foo" nil t))
+ (unless
+ (fboundp 'key3)
+ (autoload #'key3 "foo" nil t))
+ (progn
+ (bind-chord "C-k" #'key1 nil)
+ (if
+ (boundp 'my-map)
+ (bind-chord "C-u" #'key2 my-map)
+ (eval-after-load 'foo
+ '(bind-chord "C-u" #'key2 my-map)))
+ (if
+ (boundp 'my-map2)
+ (bind-chord "C-u" #'key3 my-map2)
+ (eval-after-load 'foo
+ '(bind-chord "C-u" #'key3 my-map2)))))))
+
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; no-byte-compile: t
+;; no-update-autoloads: t
+;; End:
+
+;;; use-package-tests.el ends here
diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el
index b8063a046f5..9510fffb01c 100644
--- a/test/lisp/use-package/use-package-tests.el
+++ b/test/lisp/use-package/use-package-tests.el
@@ -22,7 +22,7 @@
;;; Code:
-(require 'cl)
+(require 'cl-lib)
(require 'ert)
(require 'use-package)
@@ -99,20 +99,6 @@
(bind-key "C-c C-u" #'fix-expansion emacs-lisp-mode-map)
-(eval-when-compile
- (defun plist-delete (plist property)
- "Delete PROPERTY from PLIST"
- (let (p)
- (while plist
- (if (not (eq property (car plist)))
- (setq p (plist-put p (car plist) (nth 1 plist))))
- (setq plist (cddr plist)))
- p))
-
- ;; `cl-flet' does not work for some of the mocking we do below, while `flet'
- ;; always does.
- (setplist 'flet (plist-delete (symbol-plist 'flet) 'byte-obsolete-info)))
-
(ert-deftest use-package-test-recognize-function ()
(should (use-package-recognize-function nil t))
(should-not (use-package-recognize-function nil))
@@ -232,9 +218,9 @@
(require 'foo nil nil))))
(ert-deftest use-package-test-normalize/:ensure ()
- (flet ((norm (&rest args)
- (apply #'use-package-normalize/:ensure
- 'foopkg :ensure args)))
+ (cl-flet ((norm (&rest args)
+ (apply #'use-package-normalize/:ensure
+ 'foopkg :ensure args)))
(should (equal (norm '(t)) '(t)))
(should (equal (norm '(nil)) '(nil)))
(should (equal (norm '(sym)) '(sym)))
@@ -333,11 +319,11 @@
(ert-deftest use-package-test/:ensure-11 ()
(let (tried-to-install)
- (flet ((use-package-ensure-elpa
- (name ensure state &optional no-refresh)
- (when ensure
- (setq tried-to-install name)))
- (require (&rest ignore)))
+ (cl-letf (((symbol-function #'use-package-ensure-elpa)
+ (lambda (name ensure state &optional no-refresh)
+ (when ensure
+ (setq tried-to-install name))))
+ ((symbol-function #'require) #'ignore))
(use-package foo :ensure t)
(should (eq tried-to-install 'foo)))))
@@ -737,9 +723,9 @@
(add-to-list 'interpreter-mode-alist '("interp" . fun)))))
(ert-deftest use-package-test-normalize/:mode ()
- (flet ((norm (&rest args)
- (apply #'use-package-normalize/:mode
- 'foopkg :mode args)))
+ (cl-flet ((norm (&rest args)
+ (apply #'use-package-normalize/:mode
+ 'foopkg :mode args)))
(should (equal (norm '(".foo"))
'((".foo" . foopkg))))
(should (equal (norm '(".foo" ".bar"))
@@ -993,9 +979,9 @@
(load "foo" nil t))))))))
(ert-deftest use-package-test-normalize/:hook ()
- (flet ((norm (&rest args)
- (apply #'use-package-normalize/:hook
- 'foopkg :hook args)))
+ (cl-flet ((norm (&rest args)
+ (apply #'use-package-normalize/:hook
+ 'foopkg :hook args)))
(should-error (norm nil))
(should (equal (norm '(bar))
'((bar . foopkg-mode))))
@@ -1119,9 +1105,9 @@
(add-hook 'emacs-lisp-mode-hook #'(lambda nil (function))))))))
(ert-deftest use-package-test-normalize/:custom ()
- (flet ((norm (&rest args)
- (apply #'use-package-normalize/:custom
- 'foopkg :custom args)))
+ (cl-flet ((norm (&rest args)
+ (apply #'use-package-normalize/:custom
+ 'foopkg :custom args)))
(should-error (norm nil))
(should-error (norm '(bar)))
;; (should-error (norm '((foo bar baz quux))))
@@ -1167,6 +1153,19 @@
(custom-set-faces (backquote (foo ((t (:background "#e4edfc"))))))
(require 'foo nil nil))))
+(ert-deftest use-package-test/:custom-face-2 ()
+ (match-expansion
+ (use-package example
+ :custom-face
+ (example-1-face ((t (:foreground "LightPink"))))
+ (example-2-face ((t (:foreground "LightGreen")))))
+ `(progn
+ (custom-set-faces
+ (backquote (example-1-face ((t (:foreground "LightPink"))))))
+ (custom-set-faces
+ (backquote (example-2-face ((t (:foreground "LightGreen"))))))
+ (require 'example nil nil))))
+
(ert-deftest use-package-test/:init-1 ()
(match-expansion
(use-package foo :init (init))
@@ -1820,7 +1819,7 @@
`(bind-key "C-c C-r" #'org-ref-helm-insert-cite-link override-global-map nil)))
(ert-deftest use-package-test/560 ()
- (flet ((executable-find (name)))
+ (cl-letf (((symbol-function #'executable-find) #'ignore))
(let (notmuch-command)
(match-expansion
(use-package notmuch
@@ -1931,7 +1930,8 @@
(use-package-expand-minimally t)
debug-on-error
warnings)
- (flet ((display-warning (_ msg _) (push msg warnings)))
+ (cl-letf (((symbol-function #'display-warning)
+ (lambda (_ msg _) (push msg warnings))))
(progn
(macroexpand-1
'(use-package ediff :defer t (setq my-var t)))