diff options
| author | Stefan Kangas | 2022-11-29 18:01:53 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2022-11-29 18:01:53 +0100 |
| commit | 0d7e6b1d101a8e87e1157ba8aa4c698ced1b39f1 (patch) | |
| tree | 29455d59b3bc60f6b2d10360777ac12ffc9520f7 /test | |
| parent | 7939184f8e0370e7a3397d492812c6d202c2a193 (diff) | |
| parent | 58cc931e92ece70c3e64131ee12a799d65409100 (diff) | |
| download | emacs-scratch/use-package.tar.gz emacs-scratch/use-package.zip | |
; Merge from https://github.com/jwiegley/use-packagescratch/use-package
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/use-package/use-package-chords-tests.el | 153 | ||||
| -rw-r--r-- | test/lisp/use-package/use-package-tests.el | 1957 |
2 files changed, 2110 insertions, 0 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..d78f6883c7d --- /dev/null +++ b/test/lisp/use-package/use-package-chords-tests.el | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | ;;; use-package-chords-tests.el --- Tests for use-package-chords.el -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; This program is free software; you can redistribute it and/or modify | ||
| 4 | ;; it under the terms of the GNU General Public License as published by | ||
| 5 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 6 | ;; (at your option) any later version. | ||
| 7 | |||
| 8 | ;; This program is distributed in the hope that it will be useful, | ||
| 9 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | ;; GNU General Public License for more details. | ||
| 12 | |||
| 13 | ;; You should have received a copy of the GNU General Public License | ||
| 14 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 15 | |||
| 16 | ;;; Code: | ||
| 17 | |||
| 18 | (require 'use-package) | ||
| 19 | (require 'use-package-tests) | ||
| 20 | (require 'use-package-chords) | ||
| 21 | |||
| 22 | (defmacro match-expansion (form &rest value) | ||
| 23 | `(should (pcase (expand-minimally ,form) | ||
| 24 | ,@(mapcar #'(lambda (x) (list x t)) value)))) | ||
| 25 | |||
| 26 | (defun use-package-test-normalize-chord (&rest args) | ||
| 27 | (apply #'use-package-normalize-binder 'foo :chords args)) | ||
| 28 | |||
| 29 | (ert-deftest use-package-test-normalize/:chords-1 () | ||
| 30 | (should (equal (use-package-test-normalize-chord | ||
| 31 | '(("C-a" . alpha))) | ||
| 32 | '(("C-a" . alpha))))) | ||
| 33 | |||
| 34 | (ert-deftest use-package-test-normalize/:chords-2 () | ||
| 35 | (should (equal (use-package-test-normalize-chord | ||
| 36 | '(("C-a" . alpha) | ||
| 37 | :map foo-map | ||
| 38 | ("C-b" . beta))) | ||
| 39 | '(("C-a" . alpha) | ||
| 40 | :map foo-map | ||
| 41 | ("C-b" . beta))))) | ||
| 42 | |||
| 43 | (ert-deftest use-package-test-normalize/:chords-3 () | ||
| 44 | (should (equal (use-package-test-normalize-chord | ||
| 45 | '(:map foo-map | ||
| 46 | ("C-a" . alpha) | ||
| 47 | ("C-b" . beta))) | ||
| 48 | '(:map foo-map | ||
| 49 | ("C-a" . alpha) | ||
| 50 | ("C-b" . beta))))) | ||
| 51 | |||
| 52 | (ert-deftest use-package-test/:chords-1 () | ||
| 53 | (match-expansion | ||
| 54 | (use-package foo :chords ("C-k" . key1) ("C-u" . key2)) | ||
| 55 | `(progn | ||
| 56 | (unless | ||
| 57 | (fboundp 'key1) | ||
| 58 | (autoload #'key1 "foo" nil t)) | ||
| 59 | (unless | ||
| 60 | (fboundp 'key2) | ||
| 61 | (autoload #'key2 "foo" nil t)) | ||
| 62 | (bind-chord "C-k" #'key1 nil) | ||
| 63 | (bind-chord "C-u" #'key2 nil)))) | ||
| 64 | |||
| 65 | (ert-deftest use-package-test/:chords-2 () | ||
| 66 | (match-expansion | ||
| 67 | (use-package foo :chords (("C-k" . key1) ("C-u" . key2))) | ||
| 68 | `(progn | ||
| 69 | (unless (fboundp 'key1) | ||
| 70 | (autoload #'key1 "foo" nil t)) | ||
| 71 | (unless (fboundp 'key2) | ||
| 72 | (autoload #'key2 "foo" nil t)) | ||
| 73 | (bind-chord "C-k" #'key1 nil) | ||
| 74 | (bind-chord "C-u" #'key2 nil)))) | ||
| 75 | |||
| 76 | (ert-deftest use-package-test/:chords-3 () | ||
| 77 | (match-expansion | ||
| 78 | (use-package foo :chords (:map my-map ("C-k" . key1) ("C-u" . key2))) | ||
| 79 | `(progn | ||
| 80 | (unless | ||
| 81 | (fboundp 'key1) | ||
| 82 | (autoload #'key1 "foo" nil t)) | ||
| 83 | (unless | ||
| 84 | (fboundp 'key2) | ||
| 85 | (autoload #'key2 "foo" nil t)) | ||
| 86 | (if | ||
| 87 | (boundp 'my-map) | ||
| 88 | (progn | ||
| 89 | (bind-chord "C-k" #'key1 my-map) | ||
| 90 | (bind-chord "C-u" #'key2 my-map)) | ||
| 91 | (eval-after-load 'foo | ||
| 92 | '(progn | ||
| 93 | (bind-chord "C-k" #'key1 my-map) | ||
| 94 | (bind-chord "C-u" #'key2 my-map))))))) | ||
| 95 | |||
| 96 | (ert-deftest use-package-test/:chords-4 () | ||
| 97 | (should-error | ||
| 98 | (match-expansion | ||
| 99 | (use-package foo :chords :map my-map ("C-k" . key1) ("C-u" . key2)) | ||
| 100 | `(bind-chords :package foo)))) | ||
| 101 | |||
| 102 | (ert-deftest use-package-test/:chords-5 () | ||
| 103 | (match-expansion | ||
| 104 | (use-package foo :chords ("C-k" . key1) (:map my-map ("C-u" . key2))) | ||
| 105 | `(progn | ||
| 106 | (unless (fboundp 'key1) | ||
| 107 | (autoload #'key1 "foo" nil t)) | ||
| 108 | (unless (fboundp 'key2) | ||
| 109 | (autoload #'key2 "foo" nil t)) | ||
| 110 | (progn | ||
| 111 | (bind-chord "C-k" #'key1 nil) | ||
| 112 | (if | ||
| 113 | (boundp 'my-map) | ||
| 114 | (bind-chord "C-u" #'key2 my-map) | ||
| 115 | (eval-after-load 'foo | ||
| 116 | '(bind-chord "C-u" #'key2 my-map))))))) | ||
| 117 | |||
| 118 | (ert-deftest use-package-test/:chords-6 () | ||
| 119 | (match-expansion | ||
| 120 | (use-package foo | ||
| 121 | :chords | ||
| 122 | ("C-k" . key1) | ||
| 123 | (:map my-map ("C-u" . key2)) | ||
| 124 | (:map my-map2 ("C-u" . key3))) | ||
| 125 | `(progn | ||
| 126 | (unless | ||
| 127 | (fboundp 'key1) | ||
| 128 | (autoload #'key1 "foo" nil t)) | ||
| 129 | (unless | ||
| 130 | (fboundp 'key2) | ||
| 131 | (autoload #'key2 "foo" nil t)) | ||
| 132 | (unless | ||
| 133 | (fboundp 'key3) | ||
| 134 | (autoload #'key3 "foo" nil t)) | ||
| 135 | (progn | ||
| 136 | (bind-chord "C-k" #'key1 nil) | ||
| 137 | (if | ||
| 138 | (boundp 'my-map) | ||
| 139 | (bind-chord "C-u" #'key2 my-map) | ||
| 140 | (eval-after-load 'foo | ||
| 141 | '(bind-chord "C-u" #'key2 my-map))) | ||
| 142 | (if | ||
| 143 | (boundp 'my-map2) | ||
| 144 | (bind-chord "C-u" #'key3 my-map2) | ||
| 145 | (eval-after-load 'foo | ||
| 146 | '(bind-chord "C-u" #'key3 my-map2))))))) | ||
| 147 | |||
| 148 | ;; Local Variables: | ||
| 149 | ;; no-byte-compile: t | ||
| 150 | ;; no-update-autoloads: t | ||
| 151 | ;; End: | ||
| 152 | |||
| 153 | ;;; use-package-chords-tests.el ends here | ||
diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el new file mode 100644 index 00000000000..b66b08ec117 --- /dev/null +++ b/test/lisp/use-package/use-package-tests.el | |||
| @@ -0,0 +1,1957 @@ | |||
| 1 | ;;; use-package-tests.el --- Tests for use-package.el -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; This program is free software; you can redistribute it and/or modify | ||
| 4 | ;; it under the terms of the GNU General Public License as published by | ||
| 5 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 6 | ;; (at your option) any later version. | ||
| 7 | |||
| 8 | ;; This program is distributed in the hope that it will be useful, | ||
| 9 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | ;; GNU General Public License for more details. | ||
| 12 | |||
| 13 | ;; You should have received a copy of the GNU General Public License | ||
| 14 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 15 | |||
| 16 | ;;; Commentary: | ||
| 17 | |||
| 18 | ;;; Code: | ||
| 19 | |||
| 20 | (require 'cl-lib) | ||
| 21 | (require 'ert) | ||
| 22 | (require 'use-package) | ||
| 23 | |||
| 24 | (setq use-package-always-ensure nil | ||
| 25 | use-package-verbose 'errors | ||
| 26 | use-package-expand-minimally t | ||
| 27 | ;; These are needed for certain tests below where the `pcase' match | ||
| 28 | ;; expression is large and contains holes, such as the :after tests. | ||
| 29 | max-lisp-eval-depth 8000 | ||
| 30 | max-specpdl-size 8000) | ||
| 31 | |||
| 32 | (unless (fboundp 'macroexpand-1) | ||
| 33 | (defun macroexpand-1 (form &optional environment) | ||
| 34 | "Perform (at most) one step of macroexpansion." | ||
| 35 | (cond | ||
| 36 | ((consp form) | ||
| 37 | (let* ((head (car form)) | ||
| 38 | (env-expander (assq head environment))) | ||
| 39 | (if env-expander | ||
| 40 | (if (cdr env-expander) | ||
| 41 | (apply (cdr env-expander) (cdr form)) | ||
| 42 | form) | ||
| 43 | (if (not (and (symbolp head) (fboundp head))) | ||
| 44 | form | ||
| 45 | (let ((def (autoload-do-load (symbol-function head) head 'macro))) | ||
| 46 | (cond | ||
| 47 | ;; Follow alias, but only for macros, otherwise we may end up | ||
| 48 | ;; skipping an important compiler-macro (e.g. cl--block-wrapper). | ||
| 49 | ((and (symbolp def) (macrop def)) (cons def (cdr form))) | ||
| 50 | ((not (consp def)) form) | ||
| 51 | (t | ||
| 52 | (if (eq 'macro (car def)) | ||
| 53 | (apply (cdr def) (cdr form)) | ||
| 54 | form)))))))) | ||
| 55 | (t form)))) | ||
| 56 | |||
| 57 | (defmacro expand-minimally (form) | ||
| 58 | `(let ((use-package-verbose 'errors) | ||
| 59 | (use-package-expand-minimally t)) | ||
| 60 | (macroexpand-1 ',form))) | ||
| 61 | |||
| 62 | (defmacro expand-maximally (form) | ||
| 63 | `(let ((use-package-verbose 'debug) | ||
| 64 | (use-package-expand-minimally nil)) | ||
| 65 | (macroexpand-1 ',form))) | ||
| 66 | |||
| 67 | (defmacro match-expansion (form &rest value) | ||
| 68 | `(should (pcase (expand-minimally ,form) | ||
| 69 | ,@(mapcar #'(lambda (x) (list x t)) value)))) | ||
| 70 | |||
| 71 | (defun fix-expansion () | ||
| 72 | (interactive) | ||
| 73 | (save-excursion | ||
| 74 | (unless (looking-at "(match-expansion") | ||
| 75 | (backward-up-list)) | ||
| 76 | (when (looking-at "(match-expansion") | ||
| 77 | (re-search-forward "(\\(use-package\\|bind-key\\)") | ||
| 78 | (goto-char (match-beginning 0)) | ||
| 79 | (let ((decl (read (current-buffer)))) | ||
| 80 | (kill-sexp) | ||
| 81 | (let (vars) | ||
| 82 | (catch 'exit | ||
| 83 | (save-excursion | ||
| 84 | (while (ignore-errors (backward-up-list) t) | ||
| 85 | (when (looking-at "(let\\s-+") | ||
| 86 | (goto-char (match-end 0)) | ||
| 87 | (setq vars (read (current-buffer))) | ||
| 88 | (throw 'exit t))))) | ||
| 89 | (eval | ||
| 90 | `(let (,@ (append vars | ||
| 91 | '((use-package-verbose 'errors) | ||
| 92 | (use-package-expand-minimally t)))) | ||
| 93 | (insert ?\n ?\` (pp-to-string (macroexpand-1 decl)))))))))) | ||
| 94 | |||
| 95 | (bind-key "C-c C-u" #'fix-expansion emacs-lisp-mode-map) | ||
| 96 | |||
| 97 | (ert-deftest use-package-test-recognize-function () | ||
| 98 | (should (use-package-recognize-function nil t)) | ||
| 99 | (should-not (use-package-recognize-function nil)) | ||
| 100 | (should (use-package-recognize-function t)) | ||
| 101 | (should (use-package-recognize-function 'sym)) | ||
| 102 | (should (use-package-recognize-function #'sym)) | ||
| 103 | (should (use-package-recognize-function (lambda () ...))) | ||
| 104 | (should (use-package-recognize-function '(lambda () ...))) | ||
| 105 | (should (use-package-recognize-function #'(lambda () ...))) | ||
| 106 | |||
| 107 | (should-not (use-package-recognize-function 1)) | ||
| 108 | (should-not (use-package-recognize-function "Hello")) | ||
| 109 | (should-not (use-package-recognize-function '(nil . nil)))) | ||
| 110 | |||
| 111 | (ert-deftest use-package-test-normalize-function () | ||
| 112 | (should (equal (use-package-normalize-function nil) nil)) | ||
| 113 | (should (equal (use-package-normalize-function t) t)) | ||
| 114 | (should (equal (use-package-normalize-function 'sym) 'sym)) | ||
| 115 | (should (equal (use-package-normalize-function #'sym) 'sym)) | ||
| 116 | (should (equal (use-package-normalize-function '(lambda () ...)) '(lambda () ...))) | ||
| 117 | (should (equal (use-package-normalize-function ''(lambda () ...)) '(lambda () ...))) | ||
| 118 | (should (equal (use-package-normalize-function '#'(lambda () ...)) '(lambda () ...))) | ||
| 119 | |||
| 120 | (should (equal (use-package-normalize-function 1) 1)) | ||
| 121 | (should (equal (use-package-normalize-function "Hello") "Hello")) | ||
| 122 | (should (equal (use-package-normalize-function '(nil . nil)) '(nil . nil)))) | ||
| 123 | |||
| 124 | (ert-deftest use-package-test/:disabled-1 () | ||
| 125 | (match-expansion | ||
| 126 | (use-package foo :disabled t) | ||
| 127 | `())) | ||
| 128 | |||
| 129 | (ert-deftest use-package-test/:preface-1 () | ||
| 130 | (match-expansion | ||
| 131 | (use-package foo :preface (t)) | ||
| 132 | `(progn | ||
| 133 | (eval-and-compile | ||
| 134 | (t)) | ||
| 135 | (require 'foo nil nil)))) | ||
| 136 | |||
| 137 | (ert-deftest use-package-test/:preface-2 () | ||
| 138 | (let ((byte-compile-current-file t)) | ||
| 139 | (match-expansion | ||
| 140 | (use-package foo :preface (t)) | ||
| 141 | `(progn | ||
| 142 | (eval-and-compile | ||
| 143 | (eval-when-compile | ||
| 144 | (with-demoted-errors | ||
| 145 | "Cannot load foo: %S" nil | ||
| 146 | (unless (featurep 'foo) | ||
| 147 | (load "foo" nil t)))) | ||
| 148 | (t)) | ||
| 149 | (require 'foo nil nil))))) | ||
| 150 | |||
| 151 | (ert-deftest use-package-test/:preface-3 () | ||
| 152 | (let ((byte-compile-current-file t)) | ||
| 153 | (match-expansion | ||
| 154 | (use-package foo | ||
| 155 | :preface (preface) | ||
| 156 | :init (init) | ||
| 157 | :config (config) | ||
| 158 | :functions func | ||
| 159 | :defines def) | ||
| 160 | `(progn | ||
| 161 | (eval-and-compile | ||
| 162 | (defvar def) | ||
| 163 | (declare-function func "foo") | ||
| 164 | (eval-when-compile | ||
| 165 | (with-demoted-errors | ||
| 166 | "Cannot load foo: %S" nil | ||
| 167 | (unless (featurep 'foo) | ||
| 168 | (load "foo" nil t)))) | ||
| 169 | (preface)) | ||
| 170 | (init) | ||
| 171 | (require 'foo nil nil) | ||
| 172 | (config) | ||
| 173 | t)))) | ||
| 174 | |||
| 175 | (ert-deftest use-package-test/:preface-4 () | ||
| 176 | (let ((byte-compile-current-file t)) | ||
| 177 | (match-expansion | ||
| 178 | (use-package foo | ||
| 179 | :preface (preface) | ||
| 180 | :init (init) | ||
| 181 | :config (config) | ||
| 182 | :functions func | ||
| 183 | :defines def | ||
| 184 | :defer t) | ||
| 185 | `(progn | ||
| 186 | (eval-and-compile | ||
| 187 | (defvar def) | ||
| 188 | (declare-function func "foo") | ||
| 189 | (eval-when-compile | ||
| 190 | (with-demoted-errors | ||
| 191 | "Cannot load foo: %S" nil | ||
| 192 | (unless (featurep 'foo) | ||
| 193 | (load "foo" nil t)))) | ||
| 194 | (preface)) | ||
| 195 | (init) | ||
| 196 | (eval-after-load 'foo | ||
| 197 | '(progn | ||
| 198 | (config) | ||
| 199 | t)))))) | ||
| 200 | |||
| 201 | (ert-deftest use-package-test/:pin-1 () | ||
| 202 | (match-expansion | ||
| 203 | (use-package foo :pin foo) | ||
| 204 | `(progn | ||
| 205 | (use-package-pin-package 'foo "foo") | ||
| 206 | (require 'foo nil nil)))) | ||
| 207 | |||
| 208 | (ert-deftest use-package-test/:pin-2 () | ||
| 209 | (match-expansion | ||
| 210 | (use-package foo :pin "foo") | ||
| 211 | `(progn | ||
| 212 | (use-package-pin-package 'foo "foo") | ||
| 213 | (require 'foo nil nil)))) | ||
| 214 | |||
| 215 | (ert-deftest use-package-test-normalize/:ensure () | ||
| 216 | (cl-flet ((norm (&rest args) | ||
| 217 | (apply #'use-package-normalize/:ensure | ||
| 218 | 'foopkg :ensure args))) | ||
| 219 | (should (equal (norm '(t)) '(t))) | ||
| 220 | (should (equal (norm '(nil)) '(nil))) | ||
| 221 | (should (equal (norm '(sym)) '(sym))) | ||
| 222 | (should-error (norm '(1))) | ||
| 223 | (should-error (norm '("Hello"))))) | ||
| 224 | |||
| 225 | (ert-deftest use-package-test/:ensure-1 () | ||
| 226 | (let ((use-package-always-ensure nil)) | ||
| 227 | (match-expansion | ||
| 228 | (use-package foo :ensure t) | ||
| 229 | `(progn | ||
| 230 | (use-package-ensure-elpa 'foo '(t) 'nil) | ||
| 231 | (require 'foo nil nil))))) | ||
| 232 | |||
| 233 | (ert-deftest use-package-test/:ensure-2 () | ||
| 234 | (let ((use-package-always-ensure t)) | ||
| 235 | (match-expansion | ||
| 236 | (use-package foo :ensure t) | ||
| 237 | `(progn | ||
| 238 | (use-package-ensure-elpa 'foo '(t) 'nil) | ||
| 239 | (require 'foo nil nil))))) | ||
| 240 | |||
| 241 | (ert-deftest use-package-test/:ensure-3 () | ||
| 242 | (let ((use-package-always-ensure nil)) | ||
| 243 | (match-expansion | ||
| 244 | (use-package foo :ensure nil) | ||
| 245 | `(progn | ||
| 246 | (use-package-ensure-elpa 'foo '(nil) 'nil) | ||
| 247 | (require 'foo nil nil))))) | ||
| 248 | |||
| 249 | (ert-deftest use-package-test/:ensure-4 () | ||
| 250 | (let ((use-package-always-ensure t)) | ||
| 251 | (match-expansion | ||
| 252 | (use-package foo :ensure nil) | ||
| 253 | `(progn | ||
| 254 | (use-package-ensure-elpa 'foo '(nil) 'nil) | ||
| 255 | (require 'foo nil nil))))) | ||
| 256 | |||
| 257 | (ert-deftest use-package-test/:ensure-5 () | ||
| 258 | (let ((use-package-always-ensure nil)) | ||
| 259 | (match-expansion | ||
| 260 | (use-package foo :load-path "foo") | ||
| 261 | `(progn | ||
| 262 | (eval-and-compile | ||
| 263 | (add-to-list 'load-path ,(pred stringp))) | ||
| 264 | (require 'foo nil nil))))) | ||
| 265 | |||
| 266 | (ert-deftest use-package-test/:ensure-6 () | ||
| 267 | (let ((use-package-always-ensure t)) | ||
| 268 | (match-expansion | ||
| 269 | (use-package foo :load-path "foo") | ||
| 270 | `(progn | ||
| 271 | (eval-and-compile | ||
| 272 | (add-to-list 'load-path ,(pred stringp))) | ||
| 273 | (require 'foo nil nil))))) | ||
| 274 | |||
| 275 | (ert-deftest use-package-test/:ensure-7 () | ||
| 276 | (let ((use-package-always-ensure nil)) | ||
| 277 | (match-expansion | ||
| 278 | (use-package foo :ensure nil :load-path "foo") | ||
| 279 | `(progn | ||
| 280 | (use-package-ensure-elpa 'foo '(nil) 'nil) | ||
| 281 | (eval-and-compile | ||
| 282 | (add-to-list 'load-path ,(pred stringp))) | ||
| 283 | (require 'foo nil nil))))) | ||
| 284 | |||
| 285 | (ert-deftest use-package-test/:ensure-8 () | ||
| 286 | (let ((use-package-always-ensure t)) | ||
| 287 | (match-expansion | ||
| 288 | (use-package foo :ensure nil :load-path "foo") | ||
| 289 | `(progn | ||
| 290 | (use-package-ensure-elpa 'foo '(nil) 'nil) | ||
| 291 | (eval-and-compile | ||
| 292 | (add-to-list 'load-path ,(pred stringp))) | ||
| 293 | (require 'foo nil nil))))) | ||
| 294 | |||
| 295 | (ert-deftest use-package-test/:ensure-9 () | ||
| 296 | (let ((use-package-always-ensure nil)) | ||
| 297 | (match-expansion | ||
| 298 | (use-package foo :ensure t :load-path "foo") | ||
| 299 | `(progn | ||
| 300 | (use-package-ensure-elpa 'foo '(t) 'nil) | ||
| 301 | (eval-and-compile | ||
| 302 | (add-to-list 'load-path ,(pred stringp))) | ||
| 303 | (require 'foo nil nil))))) | ||
| 304 | |||
| 305 | (ert-deftest use-package-test/:ensure-10 () | ||
| 306 | (let ((use-package-always-ensure t)) | ||
| 307 | (match-expansion | ||
| 308 | (use-package foo :ensure t :load-path "foo") | ||
| 309 | `(progn | ||
| 310 | (use-package-ensure-elpa 'foo '(t) 'nil) | ||
| 311 | (eval-and-compile | ||
| 312 | (add-to-list 'load-path ,(pred stringp))) | ||
| 313 | (require 'foo nil nil))))) | ||
| 314 | |||
| 315 | (ert-deftest use-package-test/:ensure-11 () | ||
| 316 | (let (tried-to-install) | ||
| 317 | (cl-letf (((symbol-function #'use-package-ensure-elpa) | ||
| 318 | (lambda (name ensure state &optional no-refresh) | ||
| 319 | (when ensure | ||
| 320 | (setq tried-to-install name)))) | ||
| 321 | ((symbol-function #'require) #'ignore)) | ||
| 322 | (use-package foo :ensure t) | ||
| 323 | (should (eq tried-to-install 'foo))))) | ||
| 324 | |||
| 325 | (ert-deftest use-package-test/:ensure-12 () | ||
| 326 | (let ((use-package-always-ensure t)) | ||
| 327 | (match-expansion | ||
| 328 | (use-package foo :ensure bar) | ||
| 329 | `(progn | ||
| 330 | (use-package-ensure-elpa 'foo '(bar) 'nil) | ||
| 331 | (require 'foo nil nil))))) | ||
| 332 | |||
| 333 | (ert-deftest use-package-test/:ensure-13 () | ||
| 334 | (let ((use-package-always-ensure t)) | ||
| 335 | (match-expansion | ||
| 336 | (use-package foo :ensure bar :ensure quux) | ||
| 337 | `(progn | ||
| 338 | (use-package-ensure-elpa 'foo '(bar quux) 'nil) | ||
| 339 | (require 'foo nil nil))))) | ||
| 340 | |||
| 341 | (ert-deftest use-package-test/:ensure-14 () | ||
| 342 | (match-expansion | ||
| 343 | (use-package ess-site | ||
| 344 | :ensure ess1 | ||
| 345 | :ensure ess2 | ||
| 346 | :ensure (ess3 :pin "melpa-unstable") | ||
| 347 | :pin melpa-stable) | ||
| 348 | `(progn | ||
| 349 | (use-package-pin-package 'ess-site "melpa-stable") | ||
| 350 | (use-package-ensure-elpa 'ess-site | ||
| 351 | '(ess1 ess2 | ||
| 352 | (ess3 . "melpa-unstable")) | ||
| 353 | 'nil) | ||
| 354 | (require 'ess-site nil nil)))) | ||
| 355 | |||
| 356 | (ert-deftest use-package-test/:ensure-15 () | ||
| 357 | (let ((use-package-always-ensure t)) | ||
| 358 | (match-expansion | ||
| 359 | (use-package foo | ||
| 360 | :pin "elpa" | ||
| 361 | :ensure bar | ||
| 362 | :ensure (quux :pin "melpa")) | ||
| 363 | `(progn | ||
| 364 | (use-package-pin-package 'foo "elpa") | ||
| 365 | (use-package-ensure-elpa 'foo | ||
| 366 | '(bar | ||
| 367 | (quux . "melpa")) | ||
| 368 | 'nil) | ||
| 369 | (require 'foo nil nil))))) | ||
| 370 | |||
| 371 | (ert-deftest use-package-test/:if-1 () | ||
| 372 | (match-expansion | ||
| 373 | (use-package foo :if t) | ||
| 374 | `(when t | ||
| 375 | (require 'foo nil nil)))) | ||
| 376 | |||
| 377 | (ert-deftest use-package-test/:if-2 () | ||
| 378 | (match-expansion | ||
| 379 | (use-package foo :if (and t t)) | ||
| 380 | `(when (and t t) | ||
| 381 | (require 'foo nil nil)))) | ||
| 382 | |||
| 383 | (ert-deftest use-package-test/:if-3 () | ||
| 384 | (match-expansion | ||
| 385 | (use-package foo :if nil) | ||
| 386 | `(when nil | ||
| 387 | (require 'foo nil nil)))) | ||
| 388 | |||
| 389 | (ert-deftest use-package-test/:when-1 () | ||
| 390 | (match-expansion | ||
| 391 | (use-package foo :when t) | ||
| 392 | `(when t | ||
| 393 | (require 'foo nil nil)))) | ||
| 394 | |||
| 395 | (ert-deftest use-package-test/:when-2 () | ||
| 396 | (match-expansion | ||
| 397 | (use-package foo :when (and t t)) | ||
| 398 | `(when (and t t) | ||
| 399 | (require 'foo nil nil)))) | ||
| 400 | |||
| 401 | (ert-deftest use-package-test/:when-3 () | ||
| 402 | (match-expansion | ||
| 403 | (use-package foo :when nil) | ||
| 404 | `(when nil | ||
| 405 | (require 'foo nil nil)))) | ||
| 406 | |||
| 407 | (ert-deftest use-package-test/:unless-1 () | ||
| 408 | (match-expansion | ||
| 409 | (use-package foo :unless t) | ||
| 410 | `(when (not t) | ||
| 411 | (require 'foo nil nil)))) | ||
| 412 | |||
| 413 | (ert-deftest use-package-test/:unless-2 () | ||
| 414 | (match-expansion | ||
| 415 | (use-package foo :unless (and t t)) | ||
| 416 | `(when (not (and t t)) | ||
| 417 | (require 'foo nil nil)))) | ||
| 418 | |||
| 419 | (ert-deftest use-package-test/:unless-3 () | ||
| 420 | (match-expansion | ||
| 421 | (use-package foo :unless nil) | ||
| 422 | `(unless nil | ||
| 423 | (require 'foo nil nil)))) | ||
| 424 | |||
| 425 | (ert-deftest use-package-test/:requires-1 () | ||
| 426 | (match-expansion | ||
| 427 | (use-package foo :requires bar) | ||
| 428 | `(when (featurep 'bar) | ||
| 429 | (require 'foo nil nil)))) | ||
| 430 | |||
| 431 | (ert-deftest use-package-test/:requires-2 () | ||
| 432 | (let ((byte-compile-current-file t)) | ||
| 433 | (match-expansion | ||
| 434 | (use-package foo :requires bar) | ||
| 435 | `(when (featurep 'bar) | ||
| 436 | (eval-and-compile | ||
| 437 | (eval-when-compile | ||
| 438 | (with-demoted-errors | ||
| 439 | "Cannot load foo: %S" nil | ||
| 440 | (unless (featurep 'foo) | ||
| 441 | (load "foo" nil t))))) | ||
| 442 | (require 'foo nil nil))))) | ||
| 443 | |||
| 444 | (ert-deftest use-package-test/:requires-3 () | ||
| 445 | (match-expansion | ||
| 446 | (use-package foo :requires (bar quux)) | ||
| 447 | `(when (not (member nil (mapcar #'featurep '(bar quux)))) | ||
| 448 | (require 'foo nil nil)))) | ||
| 449 | |||
| 450 | (ert-deftest use-package-test/:requires-4 () | ||
| 451 | (let ((byte-compile-current-file t)) | ||
| 452 | (match-expansion | ||
| 453 | (use-package foo :requires bar) | ||
| 454 | `(when (featurep 'bar) | ||
| 455 | (eval-and-compile | ||
| 456 | (eval-when-compile | ||
| 457 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 458 | (unless (featurep 'foo) | ||
| 459 | (load "foo" nil t))))) | ||
| 460 | (require 'foo nil nil))))) | ||
| 461 | |||
| 462 | (ert-deftest use-package-test/:load-path-1 () | ||
| 463 | (match-expansion | ||
| 464 | (use-package foo :load-path "bar") | ||
| 465 | `(progn | ||
| 466 | (eval-and-compile | ||
| 467 | (add-to-list 'load-path | ||
| 468 | ,(pred (apply-partially | ||
| 469 | #'string= | ||
| 470 | (expand-file-name | ||
| 471 | "bar" user-emacs-directory))))) | ||
| 472 | (require 'foo nil nil)))) | ||
| 473 | |||
| 474 | (ert-deftest use-package-test/:load-path-2 () | ||
| 475 | (let ((byte-compile-current-file t)) | ||
| 476 | (match-expansion | ||
| 477 | (use-package foo :load-path "bar") | ||
| 478 | `(progn | ||
| 479 | (eval-and-compile | ||
| 480 | (add-to-list 'load-path | ||
| 481 | ,(pred (apply-partially | ||
| 482 | #'string= | ||
| 483 | (expand-file-name | ||
| 484 | "bar" user-emacs-directory))))) | ||
| 485 | (eval-and-compile | ||
| 486 | (eval-when-compile | ||
| 487 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 488 | (unless (featurep 'foo) | ||
| 489 | (load "foo" nil t))))) | ||
| 490 | (require 'foo nil nil))))) | ||
| 491 | |||
| 492 | (ert-deftest use-package-test/:load-path-3 () | ||
| 493 | (match-expansion | ||
| 494 | (use-package foo :load-path ("bar" "quux")) | ||
| 495 | `(progn | ||
| 496 | (eval-and-compile | ||
| 497 | (add-to-list 'load-path | ||
| 498 | ,(pred (apply-partially | ||
| 499 | #'string= | ||
| 500 | (expand-file-name | ||
| 501 | "bar" user-emacs-directory))))) | ||
| 502 | (eval-and-compile | ||
| 503 | (add-to-list 'load-path | ||
| 504 | ,(pred (apply-partially | ||
| 505 | #'string= | ||
| 506 | (expand-file-name | ||
| 507 | "quux" user-emacs-directory))))) | ||
| 508 | (require 'foo nil nil)))) | ||
| 509 | |||
| 510 | (ert-deftest use-package-test/:load-path-4 () | ||
| 511 | (match-expansion | ||
| 512 | (use-package foo :load-path (lambda () (list "bar" "quux"))) | ||
| 513 | `(progn | ||
| 514 | (eval-and-compile | ||
| 515 | (add-to-list 'load-path | ||
| 516 | ,(pred (apply-partially | ||
| 517 | #'string= | ||
| 518 | (expand-file-name | ||
| 519 | "bar" user-emacs-directory))))) | ||
| 520 | (eval-and-compile | ||
| 521 | (add-to-list 'load-path | ||
| 522 | ,(pred (apply-partially | ||
| 523 | #'string= | ||
| 524 | (expand-file-name | ||
| 525 | "quux" user-emacs-directory))))) | ||
| 526 | (require 'foo nil nil)))) | ||
| 527 | |||
| 528 | (ert-deftest use-package-test/:no-require-1 () | ||
| 529 | (match-expansion | ||
| 530 | (use-package foo :no-require t) | ||
| 531 | `nil)) | ||
| 532 | |||
| 533 | (ert-deftest use-package-test/:no-require-2 () | ||
| 534 | (match-expansion | ||
| 535 | (use-package foo :no-require t :config (config)) | ||
| 536 | `(progn | ||
| 537 | (config) | ||
| 538 | t))) | ||
| 539 | |||
| 540 | (ert-deftest use-package-test/:no-require-3 () | ||
| 541 | (let ((byte-compile-current-file t)) | ||
| 542 | (match-expansion | ||
| 543 | (use-package foo :no-require t) | ||
| 544 | `(eval-and-compile | ||
| 545 | (eval-when-compile | ||
| 546 | (with-demoted-errors "Cannot load foo: %S" nil nil)))))) | ||
| 547 | |||
| 548 | (defun use-package-test-normalize-bind (&rest args) | ||
| 549 | (apply #'use-package-normalize-binder 'foo :bind args)) | ||
| 550 | |||
| 551 | (ert-deftest use-package-test-normalize/:bind-1 () | ||
| 552 | (should (equal (use-package-test-normalize-bind | ||
| 553 | '(("C-a" . alpha))) | ||
| 554 | '(("C-a" . alpha))))) | ||
| 555 | |||
| 556 | (ert-deftest use-package-test-normalize/:bind-2 () | ||
| 557 | (should (equal (use-package-test-normalize-bind | ||
| 558 | '(("C-a" . alpha) | ||
| 559 | :map foo-map | ||
| 560 | ("C-b" . beta))) | ||
| 561 | '(("C-a" . alpha) | ||
| 562 | :map foo-map | ||
| 563 | ("C-b" . beta))))) | ||
| 564 | |||
| 565 | (ert-deftest use-package-test-normalize/:bind-3 () | ||
| 566 | (should (equal (use-package-test-normalize-bind | ||
| 567 | '(:map foo-map | ||
| 568 | ("C-a" . alpha) | ||
| 569 | ("C-b" . beta))) | ||
| 570 | '(:map foo-map | ||
| 571 | ("C-a" . alpha) | ||
| 572 | ("C-b" . beta))))) | ||
| 573 | |||
| 574 | (ert-deftest use-package-test/:bind-1 () | ||
| 575 | (match-expansion | ||
| 576 | (use-package foo :bind ("C-k" . key1) ("C-u" . key2)) | ||
| 577 | `(progn | ||
| 578 | (unless | ||
| 579 | (fboundp 'key1) | ||
| 580 | (autoload #'key1 "foo" nil t)) | ||
| 581 | (unless | ||
| 582 | (fboundp 'key2) | ||
| 583 | (autoload #'key2 "foo" nil t)) | ||
| 584 | (bind-keys :package foo | ||
| 585 | ("C-k" . key1) | ||
| 586 | ("C-u" . key2))))) | ||
| 587 | |||
| 588 | (ert-deftest use-package-test/:bind-2 () | ||
| 589 | (match-expansion | ||
| 590 | (use-package foo :bind (("C-k" . key1) ("C-u" . key2))) | ||
| 591 | `(progn | ||
| 592 | (unless (fboundp 'key1) | ||
| 593 | (autoload #'key1 "foo" nil t)) | ||
| 594 | (unless (fboundp 'key2) | ||
| 595 | (autoload #'key2 "foo" nil t)) | ||
| 596 | (bind-keys :package foo | ||
| 597 | ("C-k" . key1) | ||
| 598 | ("C-u" . key2))))) | ||
| 599 | |||
| 600 | (ert-deftest use-package-test/:bind-3 () | ||
| 601 | (match-expansion | ||
| 602 | (use-package foo :bind (:map my-map ("C-k" . key1) ("C-u" . key2))) | ||
| 603 | `(progn | ||
| 604 | (unless | ||
| 605 | (fboundp 'key1) | ||
| 606 | (autoload #'key1 "foo" nil t)) | ||
| 607 | (unless | ||
| 608 | (fboundp 'key2) | ||
| 609 | (autoload #'key2 "foo" nil t)) | ||
| 610 | (bind-keys :package foo :map my-map | ||
| 611 | ("C-k" . key1) | ||
| 612 | ("C-u" . key2))))) | ||
| 613 | |||
| 614 | (ert-deftest use-package-test/:bind-4 () | ||
| 615 | (should-error | ||
| 616 | (match-expansion | ||
| 617 | (use-package foo :bind :map my-map ("C-k" . key1) ("C-u" . key2)) | ||
| 618 | `(bind-keys :package foo)))) | ||
| 619 | |||
| 620 | (ert-deftest use-package-test/:bind-5 () | ||
| 621 | (match-expansion | ||
| 622 | (use-package foo :bind ("C-k" . key1) (:map my-map ("C-u" . key2))) | ||
| 623 | `(progn | ||
| 624 | (unless (fboundp 'key1) | ||
| 625 | (autoload #'key1 "foo" nil t)) | ||
| 626 | (unless (fboundp 'key2) | ||
| 627 | (autoload #'key2 "foo" nil t)) | ||
| 628 | (bind-keys :package foo | ||
| 629 | ("C-k" . key1) | ||
| 630 | :map my-map | ||
| 631 | ("C-u" . key2))))) | ||
| 632 | |||
| 633 | (ert-deftest use-package-test/:bind-6 () | ||
| 634 | (match-expansion | ||
| 635 | (use-package foo | ||
| 636 | :bind | ||
| 637 | ("C-k" . key1) | ||
| 638 | (:map my-map ("C-u" . key2)) | ||
| 639 | (:map my-map2 ("C-u" . key3))) | ||
| 640 | `(progn | ||
| 641 | (unless (fboundp 'key1) | ||
| 642 | (autoload #'key1 "foo" nil t)) | ||
| 643 | (unless (fboundp 'key2) | ||
| 644 | (autoload #'key2 "foo" nil t)) | ||
| 645 | (unless (fboundp 'key3) | ||
| 646 | (autoload #'key3 "foo" nil t)) | ||
| 647 | (bind-keys :package foo | ||
| 648 | ("C-k" . key1) | ||
| 649 | :map my-map ("C-u" . key2) | ||
| 650 | :map my-map2 ("C-u" . key3))))) | ||
| 651 | |||
| 652 | (ert-deftest use-package-test/:bind-7 () | ||
| 653 | (match-expansion | ||
| 654 | (use-package foo | ||
| 655 | :ensure | ||
| 656 | :bind ("C-c r" . browse-at-remote)) | ||
| 657 | `(progn | ||
| 658 | (use-package-ensure-elpa 'foo '(t) 'nil) | ||
| 659 | (unless (fboundp 'browse-at-remote) | ||
| 660 | (autoload #'browse-at-remote "foo" nil t)) | ||
| 661 | (bind-keys :package foo ("C-c r" . browse-at-remote))))) | ||
| 662 | |||
| 663 | (ert-deftest use-package-test/:bind-8 () | ||
| 664 | (match-expansion | ||
| 665 | (use-package foo | ||
| 666 | :ensure | ||
| 667 | :bind (:map foo-map | ||
| 668 | (("C-c r" . foo) | ||
| 669 | ("C-c r" . bar)))) | ||
| 670 | `(progn | ||
| 671 | (use-package-ensure-elpa 'foo '(t) 'nil) | ||
| 672 | (unless (fboundp 'foo) | ||
| 673 | (autoload #'foo "foo" nil t)) | ||
| 674 | (unless (fboundp 'bar) | ||
| 675 | (autoload #'bar "foo" nil t)) | ||
| 676 | (bind-keys :package foo :map foo-map | ||
| 677 | ("C-c r" . foo) | ||
| 678 | ("C-c r" . bar))))) | ||
| 679 | |||
| 680 | (ert-deftest use-package-test/:bind*-1 () | ||
| 681 | (match-expansion | ||
| 682 | (use-package foo :bind* ("C-k" . key)) | ||
| 683 | `(progn | ||
| 684 | (unless (fboundp 'key) | ||
| 685 | (autoload #'key "foo" nil t)) | ||
| 686 | (bind-keys* :package foo ("C-k" . key))))) | ||
| 687 | |||
| 688 | (ert-deftest use-package-test/:bind-keymap-1 () | ||
| 689 | (match-expansion | ||
| 690 | (use-package foo :bind-keymap ("C-k" . key)) | ||
| 691 | `(bind-key "C-k" | ||
| 692 | #'(lambda nil | ||
| 693 | (interactive) | ||
| 694 | (use-package-autoload-keymap 'key 'foo nil))))) | ||
| 695 | |||
| 696 | (ert-deftest use-package-test/:bind-keymap*-1 () | ||
| 697 | (match-expansion | ||
| 698 | (use-package foo :bind-keymap* ("C-k" . key)) | ||
| 699 | `(bind-key* "C-k" | ||
| 700 | #'(lambda () | ||
| 701 | (interactive) | ||
| 702 | (use-package-autoload-keymap 'key 'foo t))))) | ||
| 703 | |||
| 704 | (ert-deftest use-package-test/:interpreter-1 () | ||
| 705 | (match-expansion | ||
| 706 | (use-package foo :interpreter "interp") | ||
| 707 | `(progn | ||
| 708 | (unless (fboundp 'foo) | ||
| 709 | (autoload #'foo "foo" nil t)) | ||
| 710 | (add-to-list 'interpreter-mode-alist '("interp" . foo))))) | ||
| 711 | |||
| 712 | (ert-deftest use-package-test/:interpreter-2 () | ||
| 713 | (match-expansion | ||
| 714 | (use-package foo :interpreter ("interp" . fun)) | ||
| 715 | `(progn | ||
| 716 | (unless (fboundp 'fun) | ||
| 717 | (autoload #'fun "foo" nil t)) | ||
| 718 | (add-to-list 'interpreter-mode-alist '("interp" . fun))))) | ||
| 719 | |||
| 720 | (ert-deftest use-package-test-normalize/:mode () | ||
| 721 | (cl-flet ((norm (&rest args) | ||
| 722 | (apply #'use-package-normalize/:mode | ||
| 723 | 'foopkg :mode args))) | ||
| 724 | (should (equal (norm '(".foo")) | ||
| 725 | '((".foo" . foopkg)))) | ||
| 726 | (should (equal (norm '(".foo" ".bar")) | ||
| 727 | '((".foo" . foopkg) (".bar" . foopkg)))) | ||
| 728 | (should (equal (norm '((".foo" ".bar"))) | ||
| 729 | '((".foo" . foopkg) (".bar" . foopkg)))) | ||
| 730 | (should (equal (norm '((".foo"))) | ||
| 731 | '((".foo" . foopkg)))) | ||
| 732 | (should (equal (norm '((".foo" . foo) (".bar" . bar))) | ||
| 733 | '((".foo" . foo) (".bar" . bar)))))) | ||
| 734 | |||
| 735 | (ert-deftest use-package-test/:mode-1 () | ||
| 736 | (match-expansion | ||
| 737 | (use-package foo :mode "interp") | ||
| 738 | `(progn | ||
| 739 | (unless (fboundp 'foo) | ||
| 740 | (autoload #'foo "foo" nil t)) | ||
| 741 | (add-to-list 'auto-mode-alist '("interp" . foo))))) | ||
| 742 | |||
| 743 | (ert-deftest use-package-test/:mode-2 () | ||
| 744 | (match-expansion | ||
| 745 | (use-package foo :mode ("interp" . fun)) | ||
| 746 | `(progn | ||
| 747 | (unless (fboundp 'fun) | ||
| 748 | (autoload #'fun "foo" nil t)) | ||
| 749 | (add-to-list 'auto-mode-alist '("interp" . fun))))) | ||
| 750 | |||
| 751 | (ert-deftest use-package-test/:magic-1 () | ||
| 752 | (match-expansion | ||
| 753 | (use-package foo :magic "interp") | ||
| 754 | `(progn | ||
| 755 | (unless (fboundp 'foo) | ||
| 756 | (autoload #'foo "foo" nil t)) | ||
| 757 | (add-to-list 'magic-mode-alist '("interp" . foo))))) | ||
| 758 | |||
| 759 | (ert-deftest use-package-test/:magic-2 () | ||
| 760 | (match-expansion | ||
| 761 | (use-package foo :magic ("interp" . fun)) | ||
| 762 | `(progn | ||
| 763 | (unless (fboundp 'fun) | ||
| 764 | (autoload #'fun "foo" nil t)) | ||
| 765 | (add-to-list 'magic-mode-alist '("interp" . fun))))) | ||
| 766 | |||
| 767 | (ert-deftest use-package-test/:magic-fallback-1 () | ||
| 768 | (match-expansion | ||
| 769 | (use-package foo :magic-fallback "interp") | ||
| 770 | `(progn | ||
| 771 | (unless (fboundp 'foo) | ||
| 772 | (autoload #'foo "foo" nil t)) | ||
| 773 | (add-to-list 'magic-fallback-mode-alist '("interp" . foo))))) | ||
| 774 | |||
| 775 | (ert-deftest use-package-test/:magic-fallback-2 () | ||
| 776 | (match-expansion | ||
| 777 | (use-package foo :magic-fallback ("interp" . fun)) | ||
| 778 | `(progn | ||
| 779 | (unless (fboundp 'fun) | ||
| 780 | (autoload #'fun "foo" nil t)) | ||
| 781 | (add-to-list 'magic-fallback-mode-alist '("interp" . fun))))) | ||
| 782 | |||
| 783 | (ert-deftest use-package-test/:commands-1 () | ||
| 784 | (match-expansion | ||
| 785 | (use-package foo :commands bar) | ||
| 786 | `(unless (fboundp 'bar) | ||
| 787 | (autoload #'bar "foo" nil t)))) | ||
| 788 | |||
| 789 | (ert-deftest use-package-test/:commands-2 () | ||
| 790 | (match-expansion | ||
| 791 | (use-package foo :commands (bar quux)) | ||
| 792 | `(progn | ||
| 793 | (unless (fboundp 'bar) | ||
| 794 | (autoload #'bar "foo" nil t)) | ||
| 795 | (unless (fboundp 'quux) | ||
| 796 | (autoload #'quux "foo" nil t))))) | ||
| 797 | |||
| 798 | (ert-deftest use-package-test/:commands-3 () | ||
| 799 | (let ((byte-compile-current-file t)) | ||
| 800 | (match-expansion | ||
| 801 | (use-package foo :commands (bar quux)) | ||
| 802 | `(progn | ||
| 803 | (eval-and-compile | ||
| 804 | (eval-when-compile | ||
| 805 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 806 | (unless (featurep 'foo) | ||
| 807 | (load "foo" nil t))))) | ||
| 808 | (unless (fboundp 'bar) | ||
| 809 | (autoload #'bar "foo" nil t)) | ||
| 810 | (eval-when-compile | ||
| 811 | (declare-function bar "foo")) | ||
| 812 | (unless (fboundp 'quux) | ||
| 813 | (autoload #'quux "foo" nil t)) | ||
| 814 | (eval-when-compile | ||
| 815 | (declare-function quux "foo")))))) | ||
| 816 | |||
| 817 | (ert-deftest use-package-test/:commands-4 () | ||
| 818 | (match-expansion | ||
| 819 | (use-package foo :commands bar :init (bar)) | ||
| 820 | `(progn | ||
| 821 | (unless | ||
| 822 | (fboundp 'bar) | ||
| 823 | (autoload #'bar "foo" nil t)) | ||
| 824 | (bar)))) | ||
| 825 | |||
| 826 | (ert-deftest use-package-test/:commands-5 () | ||
| 827 | (match-expansion | ||
| 828 | (use-package gnus-harvest | ||
| 829 | :load-path "foo" | ||
| 830 | :commands gnus-harvest-install | ||
| 831 | :demand t | ||
| 832 | :config | ||
| 833 | (if (featurep 'message-x) | ||
| 834 | (gnus-harvest-install 'message-x) | ||
| 835 | (gnus-harvest-install))) | ||
| 836 | `(progn | ||
| 837 | (eval-and-compile | ||
| 838 | (add-to-list 'load-path ,(pred stringp))) | ||
| 839 | (require 'gnus-harvest nil nil) | ||
| 840 | (if (featurep 'message-x) | ||
| 841 | (gnus-harvest-install 'message-x) | ||
| 842 | (gnus-harvest-install)) | ||
| 843 | t))) | ||
| 844 | |||
| 845 | (ert-deftest use-package-test/:commands-6 () | ||
| 846 | (let ((byte-compile-current-file t)) | ||
| 847 | (match-expansion | ||
| 848 | (use-package gnus-harvest | ||
| 849 | :load-path "foo" | ||
| 850 | :commands gnus-harvest-install | ||
| 851 | :demand t | ||
| 852 | :config | ||
| 853 | (if (featurep 'message-x) | ||
| 854 | (gnus-harvest-install 'message-x) | ||
| 855 | (gnus-harvest-install))) | ||
| 856 | `(progn | ||
| 857 | (eval-and-compile | ||
| 858 | (add-to-list 'load-path ,(pred stringp))) | ||
| 859 | (eval-and-compile | ||
| 860 | (eval-when-compile | ||
| 861 | (with-demoted-errors "Cannot load gnus-harvest: %S" nil | ||
| 862 | (unless (featurep 'gnus-harvest) | ||
| 863 | (load "gnus-harvest" nil t))))) | ||
| 864 | (eval-when-compile | ||
| 865 | (declare-function gnus-harvest-install "gnus-harvest")) | ||
| 866 | (require 'gnus-harvest nil nil) | ||
| 867 | (if | ||
| 868 | (featurep 'message-x) | ||
| 869 | (gnus-harvest-install 'message-x) | ||
| 870 | (gnus-harvest-install)) | ||
| 871 | t)))) | ||
| 872 | |||
| 873 | (ert-deftest use-package-test/:autoload-1 () | ||
| 874 | (match-expansion | ||
| 875 | (use-package foo :autoload bar) | ||
| 876 | `(unless (fboundp 'bar) | ||
| 877 | (autoload #'bar "foo")))) | ||
| 878 | |||
| 879 | (ert-deftest use-package-test/:defines-1 () | ||
| 880 | (match-expansion | ||
| 881 | (use-package foo :defines bar) | ||
| 882 | `(require 'foo nil nil))) | ||
| 883 | |||
| 884 | (ert-deftest use-package-test/:defines-2 () | ||
| 885 | (let ((byte-compile-current-file t)) | ||
| 886 | (match-expansion | ||
| 887 | (use-package foo :defines bar) | ||
| 888 | `(progn | ||
| 889 | (eval-and-compile | ||
| 890 | (defvar bar) | ||
| 891 | (eval-when-compile | ||
| 892 | (with-demoted-errors | ||
| 893 | "Cannot load foo: %S" nil | ||
| 894 | (unless (featurep 'foo) | ||
| 895 | (load "foo" nil t))))) | ||
| 896 | (require 'foo nil nil))))) | ||
| 897 | |||
| 898 | (ert-deftest use-package-test/:functions-1 () | ||
| 899 | (match-expansion | ||
| 900 | (use-package foo :functions bar) | ||
| 901 | `(require 'foo nil nil))) | ||
| 902 | |||
| 903 | (ert-deftest use-package-test/:functions-2 () | ||
| 904 | (let ((byte-compile-current-file t)) | ||
| 905 | (match-expansion | ||
| 906 | (use-package foo :functions bar) | ||
| 907 | `(progn | ||
| 908 | (eval-and-compile | ||
| 909 | (declare-function bar "foo") | ||
| 910 | (eval-when-compile | ||
| 911 | (with-demoted-errors | ||
| 912 | "Cannot load foo: %S" nil | ||
| 913 | (unless (featurep 'foo) | ||
| 914 | (load "foo" nil t))))) | ||
| 915 | (require 'foo nil nil))))) | ||
| 916 | |||
| 917 | (ert-deftest use-package-test/:functions-3 () | ||
| 918 | (match-expansion | ||
| 919 | (use-package foo :defer t :functions bar) | ||
| 920 | `nil)) | ||
| 921 | |||
| 922 | (ert-deftest use-package-test/:functions-4 () | ||
| 923 | (let ((byte-compile-current-file t)) | ||
| 924 | (match-expansion | ||
| 925 | (use-package foo :defer t :functions bar) | ||
| 926 | `(eval-and-compile | ||
| 927 | (declare-function bar "foo") | ||
| 928 | (eval-when-compile | ||
| 929 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 930 | (unless (featurep 'foo) | ||
| 931 | (load "foo" nil t)))))))) | ||
| 932 | |||
| 933 | (ert-deftest use-package-test/:functions-5 () | ||
| 934 | (let ((byte-compile-current-file t)) | ||
| 935 | (match-expansion | ||
| 936 | (use-package foo :defer t :config (config) :functions bar) | ||
| 937 | `(progn | ||
| 938 | (eval-and-compile | ||
| 939 | (declare-function bar "foo") | ||
| 940 | (eval-when-compile | ||
| 941 | (with-demoted-errors | ||
| 942 | "Cannot load foo: %S" nil | ||
| 943 | (unless (featurep 'foo) | ||
| 944 | (load "foo" nil t))))) | ||
| 945 | (eval-after-load 'foo | ||
| 946 | '(progn | ||
| 947 | (config) | ||
| 948 | t)))))) | ||
| 949 | |||
| 950 | (ert-deftest use-package-test/:defer-1 () | ||
| 951 | (match-expansion | ||
| 952 | (use-package foo) | ||
| 953 | `(require 'foo nil nil))) | ||
| 954 | |||
| 955 | (ert-deftest use-package-test/:defer-2 () | ||
| 956 | (let ((byte-compile-current-file t)) | ||
| 957 | (match-expansion | ||
| 958 | (use-package foo) | ||
| 959 | `(progn | ||
| 960 | (eval-and-compile | ||
| 961 | (eval-when-compile | ||
| 962 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 963 | (unless (featurep 'foo) | ||
| 964 | (load "foo" nil t))))) | ||
| 965 | (require 'foo nil nil))))) | ||
| 966 | |||
| 967 | (ert-deftest use-package-test/:defer-3 () | ||
| 968 | (match-expansion | ||
| 969 | (use-package foo :defer t) | ||
| 970 | `nil)) | ||
| 971 | |||
| 972 | (ert-deftest use-package-test/:defer-4 () | ||
| 973 | (let ((byte-compile-current-file t)) | ||
| 974 | (match-expansion | ||
| 975 | (use-package foo :defer t) | ||
| 976 | `(eval-and-compile | ||
| 977 | (eval-when-compile | ||
| 978 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 979 | (unless (featurep 'foo) | ||
| 980 | (load "foo" nil t)))))))) | ||
| 981 | |||
| 982 | (ert-deftest use-package-test-normalize/:hook () | ||
| 983 | (cl-flet ((norm (&rest args) | ||
| 984 | (apply #'use-package-normalize/:hook | ||
| 985 | 'foopkg :hook args))) | ||
| 986 | (should-error (norm nil)) | ||
| 987 | (should (equal (norm '(bar)) | ||
| 988 | '((bar . foopkg-mode)))) | ||
| 989 | (should (equal (norm '((bar . foopkg))) | ||
| 990 | '((bar . foopkg)))) | ||
| 991 | (should (equal (norm '((bar . baz))) | ||
| 992 | '((bar . baz)))) | ||
| 993 | (should (equal (norm '(((bar baz) . quux))) | ||
| 994 | '(((bar baz) . quux)))) | ||
| 995 | (should (equal (norm '(bar baz)) | ||
| 996 | '(((bar baz) . foopkg-mode)))) | ||
| 997 | (should (equal (norm '((bar baz) (quux bow))) | ||
| 998 | '(((bar baz) . foopkg-mode) ((quux bow) . foopkg-mode)))) | ||
| 999 | (should (equal (norm '((bar . baz) (quux . bow))) | ||
| 1000 | '((bar . baz) (quux . bow)))) | ||
| 1001 | (should (equal (norm '(((bar1 bar2) . baz) ((quux1 quux2) . bow))) | ||
| 1002 | '(((bar1 bar2) . baz) ((quux1 quux2) . bow)))))) | ||
| 1003 | |||
| 1004 | (ert-deftest use-package-test/:hook-1 () | ||
| 1005 | (let ((byte-compile-current-file t)) | ||
| 1006 | (match-expansion | ||
| 1007 | (use-package foo | ||
| 1008 | :bind (("C-a" . key)) | ||
| 1009 | :hook (hook . fun)) | ||
| 1010 | `(progn | ||
| 1011 | (eval-and-compile | ||
| 1012 | (eval-when-compile | ||
| 1013 | (with-demoted-errors | ||
| 1014 | "Cannot load foo: %S" nil | ||
| 1015 | (unless (featurep 'foo) | ||
| 1016 | (load "foo" nil t))))) | ||
| 1017 | (unless | ||
| 1018 | (fboundp 'key) | ||
| 1019 | (autoload #'key "foo" nil t)) | ||
| 1020 | (eval-when-compile | ||
| 1021 | (declare-function key "foo")) | ||
| 1022 | (unless | ||
| 1023 | (fboundp 'fun) | ||
| 1024 | (autoload #'fun "foo" nil t)) | ||
| 1025 | (eval-when-compile | ||
| 1026 | (declare-function fun "foo")) | ||
| 1027 | (add-hook 'hook-hook #'fun) | ||
| 1028 | (bind-keys :package foo ("C-a" . key)))))) | ||
| 1029 | |||
| 1030 | (ert-deftest use-package-test/:hook-2 () | ||
| 1031 | (match-expansion | ||
| 1032 | (use-package foo | ||
| 1033 | :hook (hook . fun)) | ||
| 1034 | `(progn | ||
| 1035 | (unless (fboundp 'fun) | ||
| 1036 | (autoload #'fun "foo" nil t)) | ||
| 1037 | (add-hook 'hook-hook #'fun)))) | ||
| 1038 | |||
| 1039 | (ert-deftest use-package-test/:hook-3 () | ||
| 1040 | (let ((use-package-hook-name-suffix nil)) | ||
| 1041 | (match-expansion | ||
| 1042 | (use-package foo | ||
| 1043 | :hook (hook . fun)) | ||
| 1044 | `(progn | ||
| 1045 | (unless (fboundp 'fun) | ||
| 1046 | (autoload #'fun "foo" nil t)) | ||
| 1047 | (add-hook 'hook #'fun))))) | ||
| 1048 | |||
| 1049 | (ert-deftest use-package-test/:hook-4 () | ||
| 1050 | (let ((use-package-hook-name-suffix "-special")) | ||
| 1051 | (match-expansion | ||
| 1052 | (use-package foo | ||
| 1053 | :hook (hook . fun)) | ||
| 1054 | `(progn | ||
| 1055 | (unless (fboundp 'fun) | ||
| 1056 | (autoload #'fun "foo" nil t)) | ||
| 1057 | (add-hook 'hook-special #'fun))))) | ||
| 1058 | |||
| 1059 | (ert-deftest use-package-test/:hook-5 () | ||
| 1060 | (match-expansion | ||
| 1061 | (use-package erefactor | ||
| 1062 | :load-path "foo" | ||
| 1063 | :after elisp-mode | ||
| 1064 | :load t | ||
| 1065 | :hook (emacs-lisp-mode | ||
| 1066 | . (lambda () | ||
| 1067 | (bind-key "\C-c\C-v" erefactor-map emacs-lisp-mode-map)))) | ||
| 1068 | `(progn | ||
| 1069 | (eval-and-compile | ||
| 1070 | (add-to-list 'load-path ,(pred stringp))) | ||
| 1071 | (eval-after-load 'elisp-mode | ||
| 1072 | '(progn | ||
| 1073 | (require 'erefactor nil nil) | ||
| 1074 | (add-hook | ||
| 1075 | 'emacs-lisp-mode-hook | ||
| 1076 | #'(lambda nil | ||
| 1077 | (bind-key "" erefactor-map emacs-lisp-mode-map)))))))) | ||
| 1078 | |||
| 1079 | (ert-deftest use-package-test/:hook-6 () | ||
| 1080 | (match-expansion | ||
| 1081 | (use-package erefactor | ||
| 1082 | :load-path "foo" | ||
| 1083 | :after elisp-mode | ||
| 1084 | :hook (emacs-lisp-mode . function)) | ||
| 1085 | `(progn | ||
| 1086 | (eval-and-compile | ||
| 1087 | (add-to-list 'load-path ,(pred stringp))) | ||
| 1088 | (eval-after-load 'elisp-mode | ||
| 1089 | '(progn | ||
| 1090 | (unless (fboundp 'function) | ||
| 1091 | (autoload #'function "erefactor" nil t)) | ||
| 1092 | (add-hook 'emacs-lisp-mode-hook #'function)))))) | ||
| 1093 | |||
| 1094 | (ert-deftest use-package-test/:hook-7 () | ||
| 1095 | (match-expansion | ||
| 1096 | (use-package erefactor | ||
| 1097 | :load-path "foo" | ||
| 1098 | :after elisp-mode | ||
| 1099 | :hook (emacs-lisp-mode . (lambda () (function)))) | ||
| 1100 | `(progn | ||
| 1101 | (eval-and-compile | ||
| 1102 | (add-to-list 'load-path ,(pred stringp))) | ||
| 1103 | (eval-after-load 'elisp-mode | ||
| 1104 | '(progn | ||
| 1105 | (require 'erefactor nil nil) | ||
| 1106 | (add-hook 'emacs-lisp-mode-hook #'(lambda nil (function)))))))) | ||
| 1107 | |||
| 1108 | (ert-deftest use-package-test-normalize/:custom () | ||
| 1109 | (cl-flet ((norm (&rest args) | ||
| 1110 | (apply #'use-package-normalize/:custom | ||
| 1111 | 'foopkg :custom args))) | ||
| 1112 | (should-error (norm nil)) | ||
| 1113 | (should-error (norm '(bar))) | ||
| 1114 | ;; (should-error (norm '((foo bar baz quux)))) | ||
| 1115 | (should (equal (norm '(foo bar)) '((foo bar)))) | ||
| 1116 | ;; (should-error (norm '(foo bar baz))) | ||
| 1117 | ;; (should (equal (norm '(foo bar "baz")) | ||
| 1118 | ;; '((foo bar baz)))) | ||
| 1119 | )) | ||
| 1120 | |||
| 1121 | |||
| 1122 | (ert-deftest use-package-test/:custom-1 () | ||
| 1123 | (match-expansion | ||
| 1124 | (use-package foo :custom (foo bar)) | ||
| 1125 | `(progn | ||
| 1126 | (let | ||
| 1127 | ((custom--inhibit-theme-enable nil)) | ||
| 1128 | (unless (memq 'use-package custom-known-themes) | ||
| 1129 | (deftheme use-package) | ||
| 1130 | (enable-theme 'use-package) | ||
| 1131 | (setq custom-enabled-themes (remq 'use-package custom-enabled-themes))) | ||
| 1132 | (custom-theme-set-variables 'use-package | ||
| 1133 | '(foo bar nil nil "Customized with use-package foo"))) | ||
| 1134 | (require 'foo nil nil)))) | ||
| 1135 | |||
| 1136 | (ert-deftest use-package-test/:custom-with-comment1 () | ||
| 1137 | (match-expansion | ||
| 1138 | (use-package foo :custom (foo bar "commented")) | ||
| 1139 | `(progn | ||
| 1140 | (let | ||
| 1141 | ((custom--inhibit-theme-enable nil)) | ||
| 1142 | (unless (memq 'use-package custom-known-themes) | ||
| 1143 | (deftheme use-package) | ||
| 1144 | (enable-theme 'use-package) | ||
| 1145 | (setq custom-enabled-themes (remq 'use-package custom-enabled-themes))) | ||
| 1146 | (custom-theme-set-variables 'use-package | ||
| 1147 | '(foo bar nil nil "commented"))) | ||
| 1148 | (require 'foo nil nil)))) | ||
| 1149 | |||
| 1150 | (ert-deftest use-package-test/:custom-face-1 () | ||
| 1151 | (match-expansion | ||
| 1152 | (use-package foo :custom-face (foo ((t (:background "#e4edfc"))))) | ||
| 1153 | `(progn | ||
| 1154 | (apply #'face-spec-set (backquote (foo ((t (:background "#e4edfc")))))) | ||
| 1155 | (require 'foo nil nil)))) | ||
| 1156 | |||
| 1157 | (ert-deftest use-package-test/:custom-face-2 () | ||
| 1158 | (match-expansion | ||
| 1159 | (use-package example | ||
| 1160 | :custom-face | ||
| 1161 | (example-1-face ((t (:foreground "LightPink")))) | ||
| 1162 | (example-2-face ((t (:foreground "LightGreen"))))) | ||
| 1163 | `(progn | ||
| 1164 | (apply #'face-spec-set | ||
| 1165 | (backquote (example-1-face ((t (:foreground "LightPink")))))) | ||
| 1166 | (apply #'face-spec-set | ||
| 1167 | (backquote (example-2-face ((t (:foreground "LightGreen")))))) | ||
| 1168 | (require 'example nil nil)))) | ||
| 1169 | |||
| 1170 | (ert-deftest use-package-test/:custom-face-3 () | ||
| 1171 | (match-expansion | ||
| 1172 | (use-package foo :custom-face (foo ((t (:background "#e4edfc"))) face-defspec-spec)) | ||
| 1173 | `(progn | ||
| 1174 | (apply #'face-spec-set (backquote (foo ((t (:background "#e4edfc"))) face-defspec-spec))) | ||
| 1175 | (require 'foo nil nil)))) | ||
| 1176 | |||
| 1177 | (ert-deftest use-package-test/:init-1 () | ||
| 1178 | (match-expansion | ||
| 1179 | (use-package foo :init (init)) | ||
| 1180 | `(progn | ||
| 1181 | (init) | ||
| 1182 | (require 'foo nil nil)))) | ||
| 1183 | |||
| 1184 | (ert-deftest use-package-test/:init-2 () | ||
| 1185 | (let ((byte-compile-current-file t)) | ||
| 1186 | (match-expansion | ||
| 1187 | (use-package foo :init (init)) | ||
| 1188 | `(progn | ||
| 1189 | (eval-and-compile | ||
| 1190 | (eval-when-compile | ||
| 1191 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 1192 | (unless (featurep 'foo) | ||
| 1193 | (load "foo" nil t))))) | ||
| 1194 | (init) | ||
| 1195 | (require 'foo nil nil))))) | ||
| 1196 | |||
| 1197 | (ert-deftest use-package-test/:catch-1 () | ||
| 1198 | (match-expansion | ||
| 1199 | (use-package foo :catch t) | ||
| 1200 | `(progn | ||
| 1201 | (defvar ,_ | ||
| 1202 | #'(lambda (keyword err) | ||
| 1203 | (let ((msg (format "%s/%s: %s" 'foo keyword | ||
| 1204 | (error-message-string err)))) | ||
| 1205 | (display-warning 'use-package msg :error)))) | ||
| 1206 | (condition-case-unless-debug err | ||
| 1207 | (require 'foo nil nil) | ||
| 1208 | (error | ||
| 1209 | (funcall ,_ :catch err)))))) | ||
| 1210 | |||
| 1211 | (ert-deftest use-package-test/:catch-2 () | ||
| 1212 | (match-expansion | ||
| 1213 | (use-package foo :catch nil) | ||
| 1214 | `(require 'foo nil nil))) | ||
| 1215 | |||
| 1216 | (ert-deftest use-package-test/:catch-3 () | ||
| 1217 | (match-expansion | ||
| 1218 | (use-package foo :catch (lambda (keyword error))) | ||
| 1219 | `(progn | ||
| 1220 | (defvar ,_ (lambda (keyword error))) | ||
| 1221 | (condition-case-unless-debug err | ||
| 1222 | (require 'foo nil nil) | ||
| 1223 | (error | ||
| 1224 | (funcall ,_ :catch err)))))) | ||
| 1225 | |||
| 1226 | (ert-deftest use-package-test/:after-1 () | ||
| 1227 | (match-expansion | ||
| 1228 | (use-package foo :after bar) | ||
| 1229 | `(eval-after-load 'bar | ||
| 1230 | '(require 'foo nil nil)))) | ||
| 1231 | |||
| 1232 | (ert-deftest use-package-test/:after-2 () | ||
| 1233 | (let ((byte-compile-current-file t)) | ||
| 1234 | (match-expansion | ||
| 1235 | (use-package foo :after bar) | ||
| 1236 | `(progn | ||
| 1237 | (eval-and-compile | ||
| 1238 | (eval-when-compile | ||
| 1239 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 1240 | (unless (featurep 'foo) | ||
| 1241 | (load "foo" nil t))))) | ||
| 1242 | (eval-after-load 'bar | ||
| 1243 | '(require 'foo nil nil)))))) | ||
| 1244 | |||
| 1245 | (ert-deftest use-package-test/:after-3 () | ||
| 1246 | (match-expansion | ||
| 1247 | (use-package foo :after (bar quux)) | ||
| 1248 | `(eval-after-load 'quux | ||
| 1249 | '(eval-after-load 'bar | ||
| 1250 | '(require 'foo nil nil))))) | ||
| 1251 | |||
| 1252 | (ert-deftest use-package-test/:after-4 () | ||
| 1253 | (match-expansion | ||
| 1254 | (use-package foo :after (:all bar quux)) | ||
| 1255 | `(eval-after-load 'quux | ||
| 1256 | '(eval-after-load 'bar | ||
| 1257 | '(require 'foo nil nil))))) | ||
| 1258 | |||
| 1259 | (ert-deftest use-package-test/:after-5 () | ||
| 1260 | (match-expansion | ||
| 1261 | (use-package foo :after (:any bar quux)) | ||
| 1262 | `(progn | ||
| 1263 | (defvar ,_ nil) | ||
| 1264 | (defvar ,_ nil) | ||
| 1265 | (defvar ,_ | ||
| 1266 | #'(lambda nil | ||
| 1267 | (if ,_ ,_ | ||
| 1268 | (setq ,_ t ,_ | ||
| 1269 | (require 'foo nil nil))))) | ||
| 1270 | (eval-after-load 'bar | ||
| 1271 | '(funcall ,_)) | ||
| 1272 | (eval-after-load 'quux | ||
| 1273 | '(funcall ,_))))) | ||
| 1274 | |||
| 1275 | (ert-deftest use-package-test/:after-6 () | ||
| 1276 | (match-expansion | ||
| 1277 | (use-package foo :after (:all (:any bar quux) bow)) | ||
| 1278 | `(progn | ||
| 1279 | (defvar ,_ nil) | ||
| 1280 | (defvar ,_ nil) | ||
| 1281 | (defvar ,_ | ||
| 1282 | #'(lambda nil | ||
| 1283 | (if ,_ ,_ | ||
| 1284 | (setq ,_ t ,_ | ||
| 1285 | (require 'foo nil nil))))) | ||
| 1286 | (eval-after-load 'bow | ||
| 1287 | '(progn | ||
| 1288 | (eval-after-load 'bar | ||
| 1289 | '(funcall ,_)) | ||
| 1290 | (eval-after-load 'quux | ||
| 1291 | '(funcall ,_))))))) | ||
| 1292 | |||
| 1293 | (ert-deftest use-package-test/:after-7 () | ||
| 1294 | (match-expansion | ||
| 1295 | (use-package foo :after (:any (:all bar quux) bow)) | ||
| 1296 | `(progn | ||
| 1297 | (defvar ,_ nil) | ||
| 1298 | (defvar ,_ nil) | ||
| 1299 | (defvar ,_ | ||
| 1300 | #'(lambda nil | ||
| 1301 | (if ,_ ,_ | ||
| 1302 | (setq ,_ t ,_ | ||
| 1303 | (require 'foo nil nil))))) | ||
| 1304 | (eval-after-load 'quux | ||
| 1305 | '(eval-after-load 'bar | ||
| 1306 | '(funcall ,_))) | ||
| 1307 | (eval-after-load 'bow | ||
| 1308 | '(funcall ,_))))) | ||
| 1309 | |||
| 1310 | (ert-deftest use-package-test/:after-8 () | ||
| 1311 | (match-expansion | ||
| 1312 | (use-package foo :after (:all (:any bar quux) (:any bow baz))) | ||
| 1313 | `(progn | ||
| 1314 | (defvar ,_ nil) | ||
| 1315 | (defvar ,_ nil) | ||
| 1316 | (defvar ,_ | ||
| 1317 | #'(lambda nil | ||
| 1318 | (if ,_ ,_ | ||
| 1319 | (setq ,_ t ,_ | ||
| 1320 | (require 'foo nil nil))))) | ||
| 1321 | (eval-after-load 'bow | ||
| 1322 | '(progn | ||
| 1323 | (eval-after-load 'bar | ||
| 1324 | '(funcall ,_)) | ||
| 1325 | (eval-after-load 'quux | ||
| 1326 | '(funcall ,_)))) | ||
| 1327 | (eval-after-load 'baz | ||
| 1328 | '(progn | ||
| 1329 | (eval-after-load 'bar | ||
| 1330 | '(funcall ,_)) | ||
| 1331 | (eval-after-load 'quux | ||
| 1332 | '(funcall ,_))))))) | ||
| 1333 | |||
| 1334 | (ert-deftest use-package-test/:after-9 () | ||
| 1335 | (match-expansion | ||
| 1336 | (use-package foo :after (:any (:all bar quux) (:all bow baz))) | ||
| 1337 | `(progn | ||
| 1338 | (defvar ,_ nil) | ||
| 1339 | (defvar ,_ nil) | ||
| 1340 | (defvar ,_ | ||
| 1341 | #'(lambda nil | ||
| 1342 | (if ,_ ,_ | ||
| 1343 | (setq ,_ t ,_ | ||
| 1344 | (require 'foo nil nil))))) | ||
| 1345 | (eval-after-load 'quux | ||
| 1346 | '(eval-after-load 'bar | ||
| 1347 | '(funcall ,_))) | ||
| 1348 | (eval-after-load 'baz | ||
| 1349 | '(eval-after-load 'bow | ||
| 1350 | '(funcall ,_)))))) | ||
| 1351 | |||
| 1352 | (ert-deftest use-package-test/:after-10 () | ||
| 1353 | (match-expansion | ||
| 1354 | (use-package foo :after (:any (:all bar quux) (:any bow baz))) | ||
| 1355 | `(progn | ||
| 1356 | (defvar ,_ nil) | ||
| 1357 | (defvar ,_ nil) | ||
| 1358 | (defvar ,_ | ||
| 1359 | #'(lambda nil | ||
| 1360 | (if ,_ ,_ | ||
| 1361 | (setq ,_ t ,_ | ||
| 1362 | (require 'foo nil nil))))) | ||
| 1363 | (eval-after-load 'quux | ||
| 1364 | '(eval-after-load 'bar | ||
| 1365 | '(funcall ,_))) | ||
| 1366 | (eval-after-load 'bow | ||
| 1367 | '(funcall ,_)) | ||
| 1368 | (eval-after-load 'baz | ||
| 1369 | '(funcall ,_))))) | ||
| 1370 | |||
| 1371 | (ert-deftest use-package-test/:demand-1 () | ||
| 1372 | (match-expansion | ||
| 1373 | (use-package foo :demand t) | ||
| 1374 | `(require 'foo nil nil))) | ||
| 1375 | |||
| 1376 | (ert-deftest use-package-test/:demand-2 () | ||
| 1377 | (let ((byte-compile-current-file t)) | ||
| 1378 | (match-expansion | ||
| 1379 | (use-package foo :demand t) | ||
| 1380 | `(progn | ||
| 1381 | (eval-and-compile | ||
| 1382 | (eval-when-compile | ||
| 1383 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 1384 | (unless (featurep 'foo) | ||
| 1385 | (load "foo" nil t))))) | ||
| 1386 | (require 'foo nil nil))))) | ||
| 1387 | |||
| 1388 | (ert-deftest use-package-test/:demand-3 () | ||
| 1389 | (match-expansion | ||
| 1390 | (use-package foo :demand t :config (config)) | ||
| 1391 | `(progn | ||
| 1392 | (require 'foo nil nil) | ||
| 1393 | (config) | ||
| 1394 | t))) | ||
| 1395 | |||
| 1396 | (ert-deftest use-package-test/:demand-4 () | ||
| 1397 | (let ((byte-compile-current-file t)) | ||
| 1398 | (match-expansion | ||
| 1399 | (use-package foo :demand t :config (config)) | ||
| 1400 | `(progn | ||
| 1401 | (eval-and-compile | ||
| 1402 | (eval-when-compile | ||
| 1403 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 1404 | (unless (featurep 'foo) | ||
| 1405 | (load "foo" nil t))))) | ||
| 1406 | (require 'foo nil nil) | ||
| 1407 | (config) | ||
| 1408 | t)))) | ||
| 1409 | |||
| 1410 | (ert-deftest use-package-test/:demand-5 () | ||
| 1411 | ;; #529 - :demand should not override an explicit use of :after | ||
| 1412 | (match-expansion | ||
| 1413 | (use-package foo :demand t :after bar) | ||
| 1414 | `(eval-after-load 'bar | ||
| 1415 | '(require 'foo nil nil)))) | ||
| 1416 | |||
| 1417 | (ert-deftest use-package-test/:demand-6 () | ||
| 1418 | (let ((byte-compile-current-file t)) | ||
| 1419 | (match-expansion | ||
| 1420 | (use-package foo :demand t :after bar) | ||
| 1421 | `(progn | ||
| 1422 | (eval-and-compile | ||
| 1423 | (eval-when-compile | ||
| 1424 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 1425 | (unless (featurep 'foo) | ||
| 1426 | (load "foo" nil t))))) | ||
| 1427 | (eval-after-load 'bar | ||
| 1428 | '(require 'foo nil nil)))))) | ||
| 1429 | |||
| 1430 | (ert-deftest use-package-test/:demand-7 () | ||
| 1431 | (match-expansion | ||
| 1432 | (use-package counsel | ||
| 1433 | :load-path "foo" | ||
| 1434 | :after ivy | ||
| 1435 | :demand t | ||
| 1436 | :diminish | ||
| 1437 | :bind (("C-*" . counsel-org-agenda-headlines) | ||
| 1438 | ("M-x" . counsel-M-x)) | ||
| 1439 | :commands (counsel-minibuffer-history | ||
| 1440 | counsel-find-library | ||
| 1441 | counsel-unicode-char) | ||
| 1442 | :preface (preface-code) | ||
| 1443 | :init | ||
| 1444 | ;; This is actually wrong, but it's just part of the example. | ||
| 1445 | (define-key minibuffer-local-map (kbd "M-r") | ||
| 1446 | 'counsel-minibuffer-history)) | ||
| 1447 | `(progn | ||
| 1448 | (eval-and-compile | ||
| 1449 | (add-to-list 'load-path ,(pred stringp))) | ||
| 1450 | (eval-and-compile | ||
| 1451 | (preface-code)) | ||
| 1452 | (eval-after-load 'ivy | ||
| 1453 | '(progn | ||
| 1454 | (define-key minibuffer-local-map (kbd "M-r") | ||
| 1455 | 'counsel-minibuffer-history) | ||
| 1456 | (require 'counsel nil nil) | ||
| 1457 | (if (fboundp 'diminish) | ||
| 1458 | (diminish 'counsel-mode)) | ||
| 1459 | (bind-keys :package counsel | ||
| 1460 | ("C-*" . counsel-org-agenda-headlines) | ||
| 1461 | ("M-x" . counsel-M-x))))))) | ||
| 1462 | |||
| 1463 | (ert-deftest use-package-test/:config-1 () | ||
| 1464 | (match-expansion | ||
| 1465 | (use-package foo :config (config)) | ||
| 1466 | `(progn | ||
| 1467 | (require 'foo nil nil) | ||
| 1468 | (config) | ||
| 1469 | t))) | ||
| 1470 | |||
| 1471 | (ert-deftest use-package-test/:config-2 () | ||
| 1472 | (let ((byte-compile-current-file t)) | ||
| 1473 | (match-expansion | ||
| 1474 | (use-package foo :config (config)) | ||
| 1475 | `(progn | ||
| 1476 | (eval-and-compile | ||
| 1477 | (eval-when-compile | ||
| 1478 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 1479 | (unless (featurep 'foo) | ||
| 1480 | (load "foo" nil t))))) | ||
| 1481 | (require 'foo nil nil) | ||
| 1482 | (config) | ||
| 1483 | t)))) | ||
| 1484 | |||
| 1485 | (ert-deftest use-package-test/:config-3 () | ||
| 1486 | (match-expansion | ||
| 1487 | (use-package foo :defer t :config (config)) | ||
| 1488 | `(eval-after-load 'foo | ||
| 1489 | '(progn | ||
| 1490 | (config) | ||
| 1491 | t)))) | ||
| 1492 | |||
| 1493 | (ert-deftest use-package-test/:config-4 () | ||
| 1494 | (let ((byte-compile-current-file t)) | ||
| 1495 | (match-expansion | ||
| 1496 | (use-package foo :defer t :config (config)) | ||
| 1497 | `(progn | ||
| 1498 | (eval-and-compile | ||
| 1499 | (eval-when-compile | ||
| 1500 | (with-demoted-errors "Cannot load foo: %S" nil | ||
| 1501 | (unless (featurep 'foo) | ||
| 1502 | (load "foo" nil t))))) | ||
| 1503 | (eval-after-load 'foo | ||
| 1504 | '(progn | ||
| 1505 | (config) | ||
| 1506 | t)))))) | ||
| 1507 | |||
| 1508 | (ert-deftest use-package-test-normalize/:diminish () | ||
| 1509 | (should (equal (use-package-normalize-diminish 'foopkg :diminish nil) | ||
| 1510 | '(foopkg-mode))) | ||
| 1511 | (should (equal (use-package-normalize-diminish 'foopkg :diminish 'bar) | ||
| 1512 | '(bar))) | ||
| 1513 | (should (equal (use-package-normalize-diminish 'foopkg :diminish "bar") | ||
| 1514 | '((foopkg-mode . "bar")))) | ||
| 1515 | (should (equal (use-package-normalize-diminish 'foopkg :diminish 'foo-mode) | ||
| 1516 | '(foo-mode))) | ||
| 1517 | (should (equal (use-package-normalize-diminish 'foopkg :diminish '(foo . "bar")) | ||
| 1518 | '((foo . "bar"))))) | ||
| 1519 | |||
| 1520 | (ert-deftest use-package-test/:diminish-1 () | ||
| 1521 | (match-expansion | ||
| 1522 | (use-package foo :diminish nil) | ||
| 1523 | `(progn | ||
| 1524 | (require 'foo nil nil) | ||
| 1525 | (if (fboundp 'diminish) | ||
| 1526 | (diminish 'foo-mode))))) | ||
| 1527 | |||
| 1528 | (ert-deftest use-package-test/:diminish-2 () | ||
| 1529 | (match-expansion | ||
| 1530 | (use-package foo :diminish bar) | ||
| 1531 | `(progn | ||
| 1532 | (require 'foo nil nil) | ||
| 1533 | (if (fboundp 'diminish) | ||
| 1534 | (diminish 'bar))))) | ||
| 1535 | |||
| 1536 | (ert-deftest use-package-test/:diminish-3 () | ||
| 1537 | (match-expansion | ||
| 1538 | (use-package foo :diminish "bar") | ||
| 1539 | `(progn | ||
| 1540 | (require 'foo nil nil) | ||
| 1541 | (if (fboundp 'diminish) | ||
| 1542 | (diminish 'foo-mode "bar"))))) | ||
| 1543 | |||
| 1544 | (ert-deftest use-package-test/:diminish-4 () | ||
| 1545 | (match-expansion | ||
| 1546 | (use-package foo :diminish (foo . "bar")) | ||
| 1547 | `(progn | ||
| 1548 | (require 'foo nil nil) | ||
| 1549 | (if (fboundp 'diminish) | ||
| 1550 | (diminish 'foo "bar"))))) | ||
| 1551 | |||
| 1552 | (ert-deftest use-package-test-normalize/:delight () | ||
| 1553 | (should (equal `((foo-mode nil foo)) | ||
| 1554 | (use-package-normalize/:delight 'foo :delight nil))) | ||
| 1555 | (should (equal `((foo-mode nil foo-mode)) | ||
| 1556 | (use-package-normalize/:delight 'foo-mode :delight nil))) | ||
| 1557 | (should (equal `((bar-mode nil foo)) | ||
| 1558 | (use-package-normalize/:delight 'foo :delight '(bar-mode)))) | ||
| 1559 | (should (equal `((bar-mode nil :major)) | ||
| 1560 | (use-package-normalize/:delight 'foo :delight '((bar-mode nil :major))))) | ||
| 1561 | (should (equal `((foo-mode "abc" foo)) | ||
| 1562 | (use-package-normalize/:delight 'foo :delight '("abc")))) | ||
| 1563 | (should (equal `((foo-mode (:eval 1) foo)) | ||
| 1564 | (use-package-normalize/:delight 'foo :delight '('(:eval 1))))) | ||
| 1565 | (should (equal (use-package-normalize/:delight 'foo :delight '((a-mode) (b-mode " b"))) | ||
| 1566 | `((a-mode nil foo) (b-mode " b" foo)))) | ||
| 1567 | (should-error (use-package-normalize/:delight 'foo :delight '((:eval 1))))) | ||
| 1568 | |||
| 1569 | (ert-deftest use-package-test/:delight-1 () | ||
| 1570 | (match-expansion | ||
| 1571 | (use-package foo :delight) | ||
| 1572 | `(progn | ||
| 1573 | (require 'foo nil nil) | ||
| 1574 | (if (fboundp 'delight) | ||
| 1575 | (delight '((foo-mode nil foo))))))) | ||
| 1576 | |||
| 1577 | (ert-deftest use-package-test/:delight-2 () | ||
| 1578 | (should-error | ||
| 1579 | (match-expansion | ||
| 1580 | (use-package foo :delight nil) | ||
| 1581 | `(progn | ||
| 1582 | (require 'foo nil nil) | ||
| 1583 | (if (fboundp 'diminish) | ||
| 1584 | (diminish 'foo-mode)))))) | ||
| 1585 | |||
| 1586 | (ert-deftest use-package-test/:delight-3 () | ||
| 1587 | (match-expansion | ||
| 1588 | (use-package foo :delight bar) | ||
| 1589 | `(progn | ||
| 1590 | (require 'foo nil nil) | ||
| 1591 | (if (fboundp 'delight) | ||
| 1592 | (delight '((bar nil foo))))))) | ||
| 1593 | |||
| 1594 | (ert-deftest use-package-test/:delight-4 () | ||
| 1595 | (match-expansion | ||
| 1596 | (use-package foo :delight "bar") | ||
| 1597 | `(progn | ||
| 1598 | (require 'foo nil nil) | ||
| 1599 | (if (fboundp 'delight) | ||
| 1600 | (delight '((foo-mode "bar" foo))))))) | ||
| 1601 | |||
| 1602 | (ert-deftest use-package-test/:delight-5 () | ||
| 1603 | (should-error | ||
| 1604 | (match-expansion | ||
| 1605 | (use-package foo :delight (foo . "bar")) | ||
| 1606 | `(progn | ||
| 1607 | (require 'foo nil nil) | ||
| 1608 | (if (fboundp 'diminish) | ||
| 1609 | (diminish 'foo "bar")))))) | ||
| 1610 | |||
| 1611 | (ert-deftest use-package-test/:delight-6 () | ||
| 1612 | (match-expansion | ||
| 1613 | (use-package foo :delight (foo "bar")) | ||
| 1614 | `(progn | ||
| 1615 | (require 'foo nil nil) | ||
| 1616 | (if (fboundp 'delight) | ||
| 1617 | (delight '((foo "bar" foo))))))) | ||
| 1618 | |||
| 1619 | (ert-deftest use-package-test/334-1 () | ||
| 1620 | (let (foo1-map foo2-map | ||
| 1621 | bar1-func1 | ||
| 1622 | bar1-func2 | ||
| 1623 | bar2-func1 | ||
| 1624 | bar2-func2 | ||
| 1625 | bar3-func1 | ||
| 1626 | bar3-func2 | ||
| 1627 | bar4-func1 | ||
| 1628 | bar4-func2) | ||
| 1629 | (match-expansion | ||
| 1630 | (bind-keys :map foo1-map | ||
| 1631 | ("Y" . foo1) | ||
| 1632 | :prefix "y" | ||
| 1633 | :prefix-map bar1-prefix-map | ||
| 1634 | ("y" . bar1-func1) | ||
| 1635 | ("f" . bar1-func2) | ||
| 1636 | :prefix "y" | ||
| 1637 | :prefix-map bar2-prefix-map | ||
| 1638 | ("y" . bar2-func1) | ||
| 1639 | ("f" . bar2-func2) | ||
| 1640 | :map foo2-map | ||
| 1641 | ("Y" . foo2) | ||
| 1642 | :prefix "y" | ||
| 1643 | :prefix-map bar3-prefix-map | ||
| 1644 | ("y" . bar3-func1) | ||
| 1645 | ("f" . bar3-func2) | ||
| 1646 | :prefix "y" | ||
| 1647 | :prefix-map bar4-prefix-map | ||
| 1648 | ("y" . bar4-func1) | ||
| 1649 | ("f" . bar4-func2)) | ||
| 1650 | `(progn | ||
| 1651 | (bind-key "Y" #'foo1 foo1-map nil) | ||
| 1652 | (defvar bar1-prefix-map) | ||
| 1653 | (define-prefix-command 'bar1-prefix-map) | ||
| 1654 | (bind-key "y" 'bar1-prefix-map foo1-map nil) | ||
| 1655 | (bind-key "y" #'bar1-func1 bar1-prefix-map nil) | ||
| 1656 | (bind-key "f" #'bar1-func2 bar1-prefix-map nil) | ||
| 1657 | (defvar bar2-prefix-map) | ||
| 1658 | (define-prefix-command 'bar2-prefix-map) | ||
| 1659 | (bind-key "y" 'bar2-prefix-map foo1-map nil) | ||
| 1660 | (bind-key "y" #'bar2-func1 bar2-prefix-map nil) | ||
| 1661 | (bind-key "f" #'bar2-func2 bar2-prefix-map nil) | ||
| 1662 | (bind-key "Y" #'foo2 foo2-map nil) | ||
| 1663 | (defvar bar3-prefix-map) | ||
| 1664 | (define-prefix-command 'bar3-prefix-map) | ||
| 1665 | (bind-key "y" 'bar3-prefix-map foo2-map nil) | ||
| 1666 | (bind-key "y" #'bar3-func1 bar3-prefix-map nil) | ||
| 1667 | (bind-key "f" #'bar3-func2 bar3-prefix-map nil) | ||
| 1668 | (defvar bar4-prefix-map) | ||
| 1669 | (define-prefix-command 'bar4-prefix-map) | ||
| 1670 | (bind-key "y" 'bar4-prefix-map foo2-map nil) | ||
| 1671 | (bind-key "y" #'bar4-func1 bar4-prefix-map nil) | ||
| 1672 | (bind-key "f" #'bar4-func2 bar4-prefix-map nil))))) | ||
| 1673 | |||
| 1674 | (ert-deftest use-package-test/334-2 () | ||
| 1675 | (let (w3m-lnum-mode-map | ||
| 1676 | w3m-print-current-url | ||
| 1677 | w3m-lnum-print-this-url | ||
| 1678 | w3m-print-this-url) | ||
| 1679 | (match-expansion | ||
| 1680 | (bind-keys :map w3m-lnum-mode-map | ||
| 1681 | :prefix "y" | ||
| 1682 | :prefix-map w3m-y-prefix-map | ||
| 1683 | ("y" . w3m-print-current-url) | ||
| 1684 | ("f" . w3m-lnum-print-this-url) | ||
| 1685 | ("t" . w3m-print-this-url)) | ||
| 1686 | `(progn | ||
| 1687 | (defvar w3m-y-prefix-map) | ||
| 1688 | (define-prefix-command 'w3m-y-prefix-map) | ||
| 1689 | (bind-key "y" 'w3m-y-prefix-map w3m-lnum-mode-map nil) | ||
| 1690 | (bind-key "y" #'w3m-print-current-url w3m-y-prefix-map nil) | ||
| 1691 | (bind-key "f" #'w3m-lnum-print-this-url w3m-y-prefix-map nil) | ||
| 1692 | (bind-key "t" #'w3m-print-this-url w3m-y-prefix-map nil))))) | ||
| 1693 | |||
| 1694 | (ert-deftest use-package-test/482-1 () | ||
| 1695 | (match-expansion | ||
| 1696 | (use-package simple | ||
| 1697 | :bind-keymap ("C-t " . my/transpose-map) | ||
| 1698 | :bind (:map my/transpose-map | ||
| 1699 | ("w" . transpose-words))) | ||
| 1700 | `(progn | ||
| 1701 | (unless (fboundp 'transpose-words) | ||
| 1702 | (autoload #'transpose-words "simple" nil t)) | ||
| 1703 | (bind-key "C-t " | ||
| 1704 | #'(lambda nil | ||
| 1705 | (interactive) | ||
| 1706 | (use-package-autoload-keymap 'my/transpose-map 'simple nil))) | ||
| 1707 | (bind-keys :package simple :map my/transpose-map | ||
| 1708 | ("w" . transpose-words))))) | ||
| 1709 | |||
| 1710 | (ert-deftest use-package-test/482-2 () | ||
| 1711 | (match-expansion | ||
| 1712 | (use-package simple | ||
| 1713 | :bind (:prefix-map my/transpose-map | ||
| 1714 | :prefix "C-t" | ||
| 1715 | ("w" . transpose-words))) | ||
| 1716 | `(progn | ||
| 1717 | (unless (fboundp 'transpose-words) | ||
| 1718 | (autoload #'transpose-words "simple" nil t)) | ||
| 1719 | (bind-keys :package simple | ||
| 1720 | :prefix-map my/transpose-map | ||
| 1721 | :prefix "C-t" | ||
| 1722 | ("w" . transpose-words))))) | ||
| 1723 | |||
| 1724 | (ert-deftest use-package-test/482-3 () | ||
| 1725 | (match-expansion | ||
| 1726 | (bind-keys :package simple | ||
| 1727 | :prefix-map my/transpose-map | ||
| 1728 | :prefix "C-t" | ||
| 1729 | ("w" . transpose-words)) | ||
| 1730 | `(progn | ||
| 1731 | (defvar my/transpose-map) | ||
| 1732 | (define-prefix-command 'my/transpose-map) | ||
| 1733 | (bind-key "C-t" 'my/transpose-map nil nil) | ||
| 1734 | (bind-key "w" #'transpose-words my/transpose-map nil)))) | ||
| 1735 | |||
| 1736 | (ert-deftest use-package-test/538 () | ||
| 1737 | (match-expansion | ||
| 1738 | (use-package mu4e | ||
| 1739 | :commands (mu4e) | ||
| 1740 | :bind (("<f9>" . mu4e)) | ||
| 1741 | :init | ||
| 1742 | :config | ||
| 1743 | (config)) | ||
| 1744 | `(progn | ||
| 1745 | (unless (fboundp 'mu4e) | ||
| 1746 | (autoload #'mu4e "mu4e" nil t)) | ||
| 1747 | (eval-after-load 'mu4e | ||
| 1748 | '(progn (config) t)) | ||
| 1749 | (bind-keys :package mu4e ("<f9>" . mu4e))))) | ||
| 1750 | |||
| 1751 | (ert-deftest use-package-test/543 () | ||
| 1752 | (match-expansion | ||
| 1753 | (use-package hydra | ||
| 1754 | :ensure) | ||
| 1755 | `(progn | ||
| 1756 | (use-package-ensure-elpa 'hydra '(t) 'nil) | ||
| 1757 | (require 'hydra nil nil)))) | ||
| 1758 | |||
| 1759 | (ert-deftest use-package-test/545 () | ||
| 1760 | (match-expansion | ||
| 1761 | (use-package spacemacs-theme | ||
| 1762 | :ensure t | ||
| 1763 | :init ; or :config | ||
| 1764 | (load-theme 'spacemacs-dark t) | ||
| 1765 | ) | ||
| 1766 | `(progn | ||
| 1767 | (use-package-ensure-elpa 'spacemacs-theme '(t) 'nil) | ||
| 1768 | (load-theme 'spacemacs-dark t) | ||
| 1769 | (require 'spacemacs-theme nil nil)) | ||
| 1770 | )) | ||
| 1771 | |||
| 1772 | (ert-deftest use-package-test/550 () | ||
| 1773 | (match-expansion | ||
| 1774 | (use-package company-try-hard | ||
| 1775 | :ensure t | ||
| 1776 | :bind | ||
| 1777 | ("C-c M-/" . company-try-hard) | ||
| 1778 | (:map company-active-map | ||
| 1779 | ("C-c M-/" . company-try-hard))) | ||
| 1780 | `(progn | ||
| 1781 | (use-package-ensure-elpa 'company-try-hard | ||
| 1782 | '(t) | ||
| 1783 | 'nil) | ||
| 1784 | (unless | ||
| 1785 | (fboundp 'company-try-hard) | ||
| 1786 | (autoload #'company-try-hard "company-try-hard" nil t)) | ||
| 1787 | (bind-keys :package company-try-hard | ||
| 1788 | ("C-c M-/" . company-try-hard) | ||
| 1789 | :map company-active-map | ||
| 1790 | ("C-c M-/" . company-try-hard))))) | ||
| 1791 | |||
| 1792 | (ert-deftest use-package-test/558 () | ||
| 1793 | (match-expansion | ||
| 1794 | (bind-keys* :package org-ref | ||
| 1795 | ("C-c C-r" . org-ref-helm-insert-cite-link)) | ||
| 1796 | `(bind-key "C-c C-r" #'org-ref-helm-insert-cite-link override-global-map nil))) | ||
| 1797 | |||
| 1798 | (ert-deftest use-package-test/560 () | ||
| 1799 | (cl-letf (((symbol-function #'executable-find) #'ignore)) | ||
| 1800 | (let (notmuch-command) | ||
| 1801 | (match-expansion | ||
| 1802 | (use-package notmuch | ||
| 1803 | :preface (setq-default notmuch-command (executable-find "notmuch")) | ||
| 1804 | :if notmuch-command | ||
| 1805 | :requires foo | ||
| 1806 | :load-path "foo" | ||
| 1807 | :defines var) | ||
| 1808 | `(progn | ||
| 1809 | (eval-and-compile | ||
| 1810 | (add-to-list 'load-path ,(pred stringp))) | ||
| 1811 | (when (featurep 'foo) | ||
| 1812 | (eval-and-compile | ||
| 1813 | (setq-default notmuch-command | ||
| 1814 | (executable-find "notmuch"))) | ||
| 1815 | (when (symbol-value 'notmuch-command) | ||
| 1816 | (require 'notmuch nil nil)))))))) | ||
| 1817 | |||
| 1818 | (ert-deftest use-package-test/572-1 () | ||
| 1819 | (let ((use-package-always-defer t)) | ||
| 1820 | (match-expansion | ||
| 1821 | (use-package auth-password-store | ||
| 1822 | :after auth-source | ||
| 1823 | :init | ||
| 1824 | (setq auth-sources '(password-store))) | ||
| 1825 | `(eval-after-load 'auth-source | ||
| 1826 | '(setq auth-sources '(password-store)))))) | ||
| 1827 | |||
| 1828 | (ert-deftest use-package-test/572-2 () | ||
| 1829 | (let ((use-package-always-defer t)) | ||
| 1830 | (match-expansion | ||
| 1831 | (use-package ivy-hydra :after ivy) | ||
| 1832 | `nil))) | ||
| 1833 | |||
| 1834 | (ert-deftest use-package-test/572-3 () | ||
| 1835 | (let ((use-package-always-defer t) | ||
| 1836 | (use-package-defaults | ||
| 1837 | (let ((defaults (copy-alist use-package-defaults))) | ||
| 1838 | (setcdr (assq :defer defaults) | ||
| 1839 | '(use-package-always-defer | ||
| 1840 | (lambda (name args) | ||
| 1841 | (and use-package-always-defer | ||
| 1842 | (not (plist-member args :after)) | ||
| 1843 | (not (plist-member args :defer)) | ||
| 1844 | (not (plist-member args :demand)))))) | ||
| 1845 | defaults))) | ||
| 1846 | (match-expansion | ||
| 1847 | (use-package ivy-hydra :after ivy) | ||
| 1848 | `(eval-after-load 'ivy | ||
| 1849 | '(require 'ivy-hydra nil nil))))) | ||
| 1850 | |||
| 1851 | (ert-deftest use-package-test/575-1 () | ||
| 1852 | (match-expansion | ||
| 1853 | (use-package helm | ||
| 1854 | :defer t | ||
| 1855 | :after (:any ido dired) | ||
| 1856 | :config | ||
| 1857 | (message "test. helm start")) | ||
| 1858 | `(progn | ||
| 1859 | (defvar ,_ nil) | ||
| 1860 | (defvar ,_ nil) | ||
| 1861 | (defvar ,_ | ||
| 1862 | #'(lambda nil | ||
| 1863 | (if ,_ ,_ | ||
| 1864 | (setq ,_ t ,_ | ||
| 1865 | (eval-after-load 'helm | ||
| 1866 | '(progn | ||
| 1867 | (message "test. helm start") | ||
| 1868 | t)))))) | ||
| 1869 | (eval-after-load 'ido | ||
| 1870 | '(funcall ,_)) | ||
| 1871 | (eval-after-load 'dired | ||
| 1872 | '(funcall ,_))))) | ||
| 1873 | |||
| 1874 | (ert-deftest use-package-test/575-2 () | ||
| 1875 | (match-expansion | ||
| 1876 | (use-package helm | ||
| 1877 | :defer t | ||
| 1878 | :bind ("C-c d" . helm-mini) | ||
| 1879 | :config | ||
| 1880 | (message "test. helm start")) | ||
| 1881 | `(progn | ||
| 1882 | (unless (fboundp 'helm-mini) | ||
| 1883 | (autoload #'helm-mini "helm" nil t)) | ||
| 1884 | (eval-after-load 'helm | ||
| 1885 | '(progn | ||
| 1886 | (message "test. helm start") | ||
| 1887 | t)) | ||
| 1888 | (bind-keys :package helm ("C-c d" . helm-mini))))) | ||
| 1889 | |||
| 1890 | (ert-deftest use-package-test/585 () | ||
| 1891 | (match-expansion | ||
| 1892 | (use-package bug | ||
| 1893 | :bind (:map bug-map ("C-a" . alpha)) | ||
| 1894 | :bind (("C-b" . beta))) | ||
| 1895 | `(progn | ||
| 1896 | (unless (fboundp 'alpha) | ||
| 1897 | (autoload #'alpha "bug" nil t)) | ||
| 1898 | (unless (fboundp 'beta) | ||
| 1899 | (autoload #'beta "bug" nil t)) | ||
| 1900 | (bind-keys :package bug :map bug-map | ||
| 1901 | ("C-a" . alpha)) | ||
| 1902 | (bind-keys :package bug | ||
| 1903 | ("C-b" . beta))))) | ||
| 1904 | |||
| 1905 | (ert-deftest use-package-test/589 () | ||
| 1906 | (let ((use-package-verbose t) | ||
| 1907 | (use-package-expand-minimally t) | ||
| 1908 | debug-on-error | ||
| 1909 | warnings) | ||
| 1910 | (cl-letf (((symbol-function #'display-warning) | ||
| 1911 | (lambda (_ msg _) (push msg warnings)))) | ||
| 1912 | (progn | ||
| 1913 | (macroexpand-1 | ||
| 1914 | '(use-package ediff :defer t (setq my-var t))) | ||
| 1915 | (should (= (and (> (length warnings) 0) | ||
| 1916 | (string-match ":defer wants exactly one argument" | ||
| 1917 | (car warnings))) 44)))))) | ||
| 1918 | |||
| 1919 | (ert-deftest use-package-test/591 () | ||
| 1920 | (let ((use-package-defaults | ||
| 1921 | (cons '(:if (lambda (name _) `(locate-library ,name)) t) | ||
| 1922 | use-package-defaults))) | ||
| 1923 | (match-expansion | ||
| 1924 | (use-package nonexistent | ||
| 1925 | :hook lisp-mode) | ||
| 1926 | `(when (locate-library nonexistent) | ||
| 1927 | (unless (fboundp 'nonexistent-mode) | ||
| 1928 | (autoload #'nonexistent-mode "nonexistent" nil t)) | ||
| 1929 | (add-hook 'lisp-mode-hook #'nonexistent-mode))))) | ||
| 1930 | |||
| 1931 | (ert-deftest bind-key/:prefix-map () | ||
| 1932 | (match-expansion | ||
| 1933 | (bind-keys :prefix "<f1>" | ||
| 1934 | :prefix-map my/map) | ||
| 1935 | `(progn | ||
| 1936 | (defvar my/map) | ||
| 1937 | (define-prefix-command 'my/map) | ||
| 1938 | (bind-key "<f1>" 'my/map nil nil)))) | ||
| 1939 | |||
| 1940 | |||
| 1941 | (ert-deftest bind-key/845 () | ||
| 1942 | (defvar test-map (make-keymap)) | ||
| 1943 | (bind-key "<f1>" 'ignore 'test-map) | ||
| 1944 | (should (eq (lookup-key test-map (kbd "<f1>")) 'ignore)) | ||
| 1945 | (let ((binding (cl-find "<f1>" personal-keybindings :test 'string= :key 'caar))) | ||
| 1946 | (message "test-map %s" test-map) | ||
| 1947 | (message "binding %s" binding) | ||
| 1948 | (should (eq (cdar binding) 'test-map)) | ||
| 1949 | (should (eq (nth 1 binding) 'ignore)) | ||
| 1950 | (should (eq (nth 2 binding) nil)))) | ||
| 1951 | |||
| 1952 | ;; Local Variables: | ||
| 1953 | ;; no-byte-compile: t | ||
| 1954 | ;; no-update-autoloads: t | ||
| 1955 | ;; End: | ||
| 1956 | |||
| 1957 | ;;; use-package-tests.el ends here | ||