aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJohn Wiegley2017-12-01 01:33:01 -0800
committerJohn Wiegley2017-12-01 01:33:01 -0800
commit7f2eec9e654cb0faf9da423b8f7a69738c2336dd (patch)
tree492f610caf1deba8c77c86e0d116ab3628c2a111 /test
parent88f8c1bb8f87dead10a8c4f980c1c32df9100f6f (diff)
downloademacs-7f2eec9e654cb0faf9da423b8f7a69738c2336dd.tar.gz
emacs-7f2eec9e654cb0faf9da423b8f7a69738c2336dd.zip
Add many new tests
Diffstat (limited to 'test')
-rw-r--r--test/lisp/use-package/use-package-tests.el310
1 files changed, 277 insertions, 33 deletions
diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el
index 35645fdce82..75ed42c229b 100644
--- a/test/lisp/use-package/use-package-tests.el
+++ b/test/lisp/use-package/use-package-tests.el
@@ -25,6 +25,10 @@
25(require 'ert) 25(require 'ert)
26(require 'use-package) 26(require 'use-package)
27 27
28(setq use-package-always-ensure nil
29 use-package-verbose nil
30 use-package-expand-minimally t)
31
28(defmacro expand-minimally (form) 32(defmacro expand-minimally (form)
29 `(let ((use-package-verbose nil) 33 `(let ((use-package-verbose nil)
30 (use-package-expand-minimally t)) 34 (use-package-expand-minimally t))
@@ -34,7 +38,6 @@
34 `(should (pcase (expand-minimally ,form) 38 `(should (pcase (expand-minimally ,form)
35 ,@(mapcar #'(lambda (x) (list x t)) value)))) 39 ,@(mapcar #'(lambda (x) (list x t)) value))))
36 40
37;; `cl-flet' does not work for the mocking we do below, while `flet' does.
38(eval-when-compile 41(eval-when-compile
39 (defun plist-delete (plist property) 42 (defun plist-delete (plist property)
40 "Delete PROPERTY from PLIST" 43 "Delete PROPERTY from PLIST"
@@ -45,9 +48,14 @@
45 (setq plist (cddr plist))) 48 (setq plist (cddr plist)))
46 p)) 49 p))
47 50
51 ;; `cl-flet' does not work for some of the mocking we do below, while `flet'
52 ;; always does.
48 (setplist 'flet (plist-delete (symbol-plist 'flet) 'byte-obsolete-info))) 53 (setplist 'flet (plist-delete (symbol-plist 'flet) 'byte-obsolete-info)))
49 54
50(ert-deftest use-package-test-recognize-function () 55(ert-deftest use-package-test-recognize-function ()
56 (should (use-package--recognize-function nil t))
57 (should-not (use-package--recognize-function nil))
58 (should (use-package--recognize-function t))
51 (should (use-package--recognize-function 'sym)) 59 (should (use-package--recognize-function 'sym))
52 (should (use-package--recognize-function #'sym)) 60 (should (use-package--recognize-function #'sym))
53 (should (use-package--recognize-function (lambda () ...))) 61 (should (use-package--recognize-function (lambda () ...)))
@@ -59,6 +67,8 @@
59 (should-not (use-package--recognize-function '(nil . nil)))) 67 (should-not (use-package--recognize-function '(nil . nil))))
60 68
61(ert-deftest use-package-test-normalize-function () 69(ert-deftest use-package-test-normalize-function ()
70 (should (equal (use-package--normalize-function nil) nil))
71 (should (equal (use-package--normalize-function t) t))
62 (should (equal (use-package--normalize-function 'sym) 'sym)) 72 (should (equal (use-package--normalize-function 'sym) 'sym))
63 (should (equal (use-package--normalize-function #'sym) 'sym)) 73 (should (equal (use-package--normalize-function #'sym) 'sym))
64 (should (equal (use-package--normalize-function (lambda () ...)) (lambda () ...))) 74 (should (equal (use-package--normalize-function (lambda () ...)) (lambda () ...)))
@@ -69,13 +79,81 @@
69 (should (equal (use-package--normalize-function "Hello") "Hello")) 79 (should (equal (use-package--normalize-function "Hello") "Hello"))
70 (should (equal (use-package--normalize-function '(nil . nil)) '(nil . nil)))) 80 (should (equal (use-package--normalize-function '(nil . nil)) '(nil . nil))))
71 81
72;; (ert-deftest use-package-test/:disabled () 82(ert-deftest use-package-test/:disabled ()
73;; (should (equal (macroexpand (use-package)) 83 (match-expansion
74;; '()))) 84 (use-package foo :disabled t)
85 `())
75 86
76;; (ert-deftest use-package-test/:preface () 87 (match-expansion
77;; (should (equal (macroexpand (use-package)) 88 ;; jww (2017-11-30): Should :disabled ignore its argument?
78;; '()))) 89 (use-package foo :disabled nil)
90 `()))
91
92(ert-deftest use-package-test/:preface ()
93 (match-expansion
94 (use-package foo :preface (t))
95 `(progn
96 (eval-and-compile
97 (t))
98 (require 'foo nil 'nil)))
99
100 (let ((byte-compile-current-file t))
101 (match-expansion
102 (use-package foo :preface (t))
103 `(progn
104 (eval-and-compile
105 (eval-when-compile
106 (with-demoted-errors
107 "Cannot load foo: %S" nil
108 (load "foo" nil t)))
109 (t))
110 (require 'foo nil 'nil))))
111
112 (let ((byte-compile-current-file t))
113 (match-expansion
114 (use-package foo
115 :preface (preface)
116 :init (init)
117 :config (config)
118 :functions func
119 :defines def)
120 `(progn
121 (eval-and-compile
122 (defvar def)
123 (declare-function func "foo")
124 (eval-when-compile
125 (with-demoted-errors
126 "Cannot load foo: %S" nil
127 (load "foo" nil t)))
128 (preface))
129 (init)
130 (require 'foo nil 'nil)
131 (config)
132 t)))
133
134 (let ((byte-compile-current-file t))
135 (match-expansion
136 (use-package foo
137 :preface (preface)
138 :init (init)
139 :config (config)
140 :functions func
141 :defines def
142 :defer t)
143 `(progn
144 (eval-and-compile
145 (defvar def)
146 (declare-function func "foo")
147 (eval-when-compile
148 (with-demoted-errors
149 "Cannot load foo: %S" nil
150 (load "foo" nil t)))
151 (preface))
152 (init)
153 (eval-after-load 'foo
154 '(progn
155 (config)
156 t))))))
79 157
80;; (ert-deftest use-package-test/:pin () 158;; (ert-deftest use-package-test/:pin ()
81;; (should (equal (macroexpand (use-package)) 159;; (should (equal (macroexpand (use-package))
@@ -181,33 +259,127 @@
181 (flet ((use-package-ensure-elpa 259 (flet ((use-package-ensure-elpa
182 (name ensure state context &optional no-refresh) 260 (name ensure state context &optional no-refresh)
183 (when ensure 261 (when ensure
184 (setq tried-to-install name)))) 262 (setq tried-to-install name)))
185 (eval '(use-package foo :ensure t)) 263 (require (&rest ignore)))
264 (use-package foo :ensure t)
186 (should (eq tried-to-install 'foo))))) 265 (should (eq tried-to-install 'foo)))))
187 266
188;; (ert-deftest use-package-test/:if () 267(ert-deftest use-package-test/:if ()
189;; (should (equal (macroexpand (use-package)) 268 (match-expansion
190;; '()))) 269 (use-package foo :if t)
270 `(if (symbol-value 't)
271 (progn
272 (require 'foo nil 'nil))))
191 273
192;; (ert-deftest use-package-test/:when () 274 (match-expansion
193;; (should (equal (macroexpand (use-package)) 275 (use-package foo :if (and t t))
194;; '()))) 276 `(if (and t t)
277 (progn
278 (require 'foo nil 'nil))))
195 279
196;; (ert-deftest use-package-test/:unless () 280 (match-expansion
197;; (should (equal (macroexpand (use-package)) 281 (use-package foo :if nil)
198;; '()))) 282 `(if nil
283 (progn
284 (require 'foo nil 'nil)))))
285
286(ert-deftest use-package-test/:when ()
287 (match-expansion
288 (use-package foo :when t)
289 `(if (symbol-value 't)
290 (progn
291 (require 'foo nil 'nil))))
292
293 (match-expansion
294 (use-package foo :when (and t t))
295 `(if (and t t)
296 (progn
297 (require 'foo nil 'nil))))
298
299 (match-expansion
300 (use-package foo :when nil)
301 `(if nil
302 (progn
303 (require 'foo nil 'nil)))))
304
305(ert-deftest use-package-test/:when ()
306 (match-expansion
307 (use-package foo :unless t)
308 `(if (symbol-value 't)
309 nil
310 (require 'foo nil 'nil)))
311
312 (match-expansion
313 (use-package foo :unless (and t t))
314 `(if (and t t)
315 nil
316 (require 'foo nil 'nil)))
317
318 (match-expansion
319 (use-package foo :unless nil)
320 `(if nil
321 nil
322 (require 'foo nil 'nil))))
199 323
200;; (ert-deftest use-package-test/:requires () 324;; (ert-deftest use-package-test/:requires ()
201;; (should (equal (macroexpand (use-package)) 325;; (should (equal (macroexpand (use-package))
202;; '()))) 326;; '())))
203 327
204;; (ert-deftest use-package-test/:load-path () 328(ert-deftest use-package-test/:load-path ()
205;; (should (equal (macroexpand (use-package)) 329 (match-expansion
206;; '()))) 330 (use-package foo :load-path "bar")
331 `(progn
332 (eval-and-compile
333 (add-to-list 'load-path
334 ,(pred (apply-partially
335 #'string=
336 (expand-file-name
337 "bar" user-emacs-directory)))))
338 (require 'foo nil 'nil)))
207 339
208;; (ert-deftest use-package-test/:no-require () 340 (match-expansion
209;; (should (equal (macroexpand (use-package)) 341 (use-package foo :load-path ("bar" "quux"))
210;; '()))) 342 `(progn
343 (eval-and-compile
344 (add-to-list 'load-path
345 ,(pred (apply-partially
346 #'string=
347 (expand-file-name
348 "bar" user-emacs-directory)))))
349 (eval-and-compile
350 (add-to-list 'load-path
351 ,(pred (apply-partially
352 #'string=
353 (expand-file-name
354 "quux" user-emacs-directory)))))
355 (require 'foo nil 'nil)))
356
357 (match-expansion
358 (use-package foo :load-path (lambda () (list "bar" "quux")))
359 `(progn
360 (eval-and-compile
361 (add-to-list 'load-path
362 ,(pred (apply-partially
363 #'string=
364 (expand-file-name
365 "bar" user-emacs-directory)))))
366 (eval-and-compile
367 (add-to-list 'load-path
368 ,(pred (apply-partially
369 #'string=
370 (expand-file-name
371 "quux" user-emacs-directory)))))
372 (require 'foo nil 'nil))))
373
374(ert-deftest use-package-test/:no-require ()
375 (match-expansion
376 (use-package foo :no-require t)
377 `nil)
378
379 (let ((byte-compile-current-file t))
380 (match-expansion
381 (use-package foo :no-require t)
382 `'nil)))
211 383
212(ert-deftest use-package-test-normalize/:bind () 384(ert-deftest use-package-test-normalize/:bind ()
213 (let ((good-values '(:map map-sym 385 (let ((good-values '(:map map-sym
@@ -271,13 +443,64 @@
271;; (should (equal (macroexpand (use-package)) 443;; (should (equal (macroexpand (use-package))
272;; '()))) 444;; '())))
273 445
274;; (ert-deftest use-package-test/:defines () 446(ert-deftest use-package-test/:defines ()
275;; (should (equal (macroexpand (use-package)) 447 (match-expansion
276;; '()))) 448 (use-package foo :defines bar)
449 `(require 'foo nil 'nil))
277 450
278;; (ert-deftest use-package-test/:functions () 451 (let ((byte-compile-current-file t))
279;; (should (equal (macroexpand (use-package)) 452 (match-expansion
280;; '()))) 453 (use-package foo :defines bar)
454 `(progn
455 (eval-and-compile
456 (defvar bar)
457 (eval-when-compile
458 (with-demoted-errors
459 "Cannot load foo: %S" nil
460 (load "foo" nil t))))
461 (require 'foo nil 'nil)))))
462
463(ert-deftest use-package-test/:functions ()
464 (match-expansion
465 (use-package foo :functions bar)
466 `(require 'foo nil 'nil))
467
468 (let ((byte-compile-current-file t))
469 (match-expansion
470 (use-package foo :functions bar)
471 `(progn
472 (eval-and-compile
473 (declare-function bar "foo")
474 (eval-when-compile
475 (with-demoted-errors
476 "Cannot load foo: %S" nil
477 (load "foo" nil t))))
478 (require 'foo nil 'nil))))
479
480 (match-expansion
481 (use-package foo :defer t :functions bar)
482 `nil)
483
484 ;; jww (2017-12-01): This exposes a bug.
485 ;; (let ((byte-compile-current-file t))
486 ;; (match-expansion
487 ;; (use-package foo :defer t :functions bar)
488 ;; `'nil))
489
490 (let ((byte-compile-current-file t))
491 (match-expansion
492 (use-package foo :defer t :config (config) :functions bar)
493 `(progn
494 (eval-and-compile
495 (declare-function bar "foo")
496 (eval-when-compile
497 (with-demoted-errors
498 "Cannot load foo: %S" nil
499 (load "foo" nil t))))
500 (eval-after-load 'foo
501 '(progn
502 (config)
503 t))))))
281 504
282;; (ert-deftest use-package-test/:defer () 505;; (ert-deftest use-package-test/:defer ()
283;; (should (equal (macroexpand (use-package)) 506;; (should (equal (macroexpand (use-package))
@@ -302,9 +525,30 @@
302 '(((bar1 bar2) . baz) 525 '(((bar1 bar2) . baz)
303 ((quux1 quux2) . bow))))) 526 ((quux1 quux2) . bow)))))
304 527
305;; (ert-deftest use-package-test/:hook () 528(ert-deftest use-package-test/:hook ()
306;; (should (equal (macroexpand (use-package)) 529 (let ((byte-compile-current-file t))
307;; '()))) 530 (should
531 (equal ; pcase crashes
532 (expand-minimally
533 (use-package foo
534 :bind (("C-a" . key))
535 :hook (hook . fun)))
536 '(progn
537 (eval-and-compile
538 (eval-when-compile
539 (with-demoted-errors "Cannot load foo: %S" nil
540 (load "foo" nil t))))
541 (unless (fboundp 'fun)
542 (autoload #'fun "foo" nil t))
543 (eval-when-compile
544 (declare-function fun "foo"))
545 (unless (fboundp 'key)
546 (autoload #'key "foo" nil t))
547 (eval-when-compile
548 (declare-function key "foo"))
549 (add-hook 'hook-hook #'fun)
550 (ignore
551 (bind-keys :package foo ("C-a" . key))))))))
308 552
309(ert-deftest use-package-test-normalize/:custom () 553(ert-deftest use-package-test-normalize/:custom ()
310 (should-error (use-package-normalize/:custom 'foopkg :custom nil)) 554 (should-error (use-package-normalize/:custom 'foopkg :custom nil))