diff options
| author | John Wiegley | 2017-11-30 12:38:01 -0800 |
|---|---|---|
| committer | John Wiegley | 2017-11-30 12:38:01 -0800 |
| commit | ca94036dce4b8018d3ac8f4798eba49af87e6bf6 (patch) | |
| tree | b6c9cb7dd0e1674c49f0ae7adea754f8971e091c /test | |
| parent | 1fc543a212021bc911a082bdfc7cc81eb401c0d4 (diff) | |
| download | emacs-ca94036dce4b8018d3ac8f4798eba49af87e6bf6.tar.gz emacs-ca94036dce4b8018d3ac8f4798eba49af87e6bf6.zip | |
Add a test case for :ensure, following up from
GitHub-reference: https://github.com/jwiegley/use-package/issues/190
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/use-package/use-package-tests.el | 114 |
1 files changed, 108 insertions, 6 deletions
diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 4eb91165780..f45c4a38462 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el | |||
| @@ -25,6 +25,19 @@ | |||
| 25 | (require 'ert) | 25 | (require 'ert) |
| 26 | (require 'use-package) | 26 | (require 'use-package) |
| 27 | 27 | ||
| 28 | (defmacro expand-minimally (form) | ||
| 29 | `(let ((use-package-verbose nil) | ||
| 30 | (use-package-expand-minimally t)) | ||
| 31 | (macroexpand ',form))) | ||
| 32 | |||
| 33 | (defmacro match-expansion (form value) | ||
| 34 | `(should (pcase (expand-minimally ,form) | ||
| 35 | (,value t)))) | ||
| 36 | |||
| 37 | ;; `cl-flet' does not work for the mocking we do below, while `flet' does. | ||
| 38 | (eval-when-compile | ||
| 39 | (setplist 'flet (plist-delete (symbol-plist 'flet) 'byte-obsolete-info))) | ||
| 40 | |||
| 28 | (ert-deftest use-package-test-recognize-function () | 41 | (ert-deftest use-package-test-recognize-function () |
| 29 | (should (use-package--recognize-function 'sym)) | 42 | (should (use-package--recognize-function 'sym)) |
| 30 | (should (use-package--recognize-function #'sym)) | 43 | (should (use-package--recognize-function #'sym)) |
| @@ -63,9 +76,97 @@ | |||
| 63 | ;; (should (equal (macroexpand (use-package)) | 76 | ;; (should (equal (macroexpand (use-package)) |
| 64 | ;; '()))) | 77 | ;; '()))) |
| 65 | 78 | ||
| 66 | ;; (ert-deftest use-package-test/:ensure () | 79 | (defvar tried-to-install) |
| 67 | ;; (should (equal (macroexpand (use-package)) | 80 | |
| 68 | ;; '()))) | 81 | (ert-deftest use-package-test/:ensure () |
| 82 | (let ((use-package-always-ensure nil)) | ||
| 83 | (match-expansion | ||
| 84 | (use-package foo :ensure t) | ||
| 85 | `(progn | ||
| 86 | (use-package-ensure-elpa 'foo 't 'nil :ensure) | ||
| 87 | (require 'foo nil 'nil)))) | ||
| 88 | |||
| 89 | (let ((use-package-always-ensure t)) | ||
| 90 | (match-expansion | ||
| 91 | (use-package foo :ensure t) | ||
| 92 | `(progn | ||
| 93 | (use-package-ensure-elpa 'foo 't 'nil :ensure) | ||
| 94 | (require 'foo nil 'nil)))) | ||
| 95 | |||
| 96 | (let ((use-package-always-ensure nil)) | ||
| 97 | (match-expansion | ||
| 98 | (use-package foo :ensure nil) | ||
| 99 | `(progn | ||
| 100 | (use-package-ensure-elpa 'foo 'nil 'nil :ensure) | ||
| 101 | (require 'foo nil 'nil)))) | ||
| 102 | |||
| 103 | (let ((use-package-always-ensure t)) | ||
| 104 | (match-expansion | ||
| 105 | (use-package foo :ensure nil) | ||
| 106 | `(progn | ||
| 107 | (use-package-ensure-elpa 'foo 'nil 'nil :ensure) | ||
| 108 | (require 'foo nil 'nil)))) | ||
| 109 | |||
| 110 | (let ((use-package-always-ensure nil)) | ||
| 111 | (match-expansion | ||
| 112 | (use-package foo :load-path "foo") | ||
| 113 | `(progn | ||
| 114 | (eval-and-compile | ||
| 115 | (add-to-list 'load-path ,(pred stringp))) | ||
| 116 | (require 'foo nil 'nil)))) | ||
| 117 | |||
| 118 | (let ((use-package-always-ensure t)) | ||
| 119 | (match-expansion | ||
| 120 | (use-package foo :load-path "foo") | ||
| 121 | `(progn | ||
| 122 | (use-package-ensure-elpa 'foo 'nil 'nil :ensure) | ||
| 123 | (eval-and-compile | ||
| 124 | (add-to-list 'load-path ,(pred stringp))) | ||
| 125 | (require 'foo nil 'nil)))) | ||
| 126 | |||
| 127 | (let ((use-package-always-ensure nil)) | ||
| 128 | (match-expansion | ||
| 129 | (use-package foo :ensure nil :load-path "foo") | ||
| 130 | `(progn | ||
| 131 | (use-package-ensure-elpa 'foo 'nil 'nil :ensure) | ||
| 132 | (eval-and-compile | ||
| 133 | (add-to-list 'load-path ,(pred stringp))) | ||
| 134 | (require 'foo nil 'nil)))) | ||
| 135 | |||
| 136 | (let ((use-package-always-ensure t)) | ||
| 137 | (match-expansion | ||
| 138 | (use-package foo :ensure nil :load-path "foo") | ||
| 139 | `(progn | ||
| 140 | (use-package-ensure-elpa 'foo 'nil 'nil :ensure) | ||
| 141 | (eval-and-compile | ||
| 142 | (add-to-list 'load-path ,(pred stringp))) | ||
| 143 | (require 'foo nil 'nil)))) | ||
| 144 | |||
| 145 | (let ((use-package-always-ensure nil)) | ||
| 146 | (match-expansion | ||
| 147 | (use-package foo :ensure t :load-path "foo") | ||
| 148 | `(progn | ||
| 149 | (use-package-ensure-elpa 'foo 't 'nil :ensure) | ||
| 150 | (eval-and-compile | ||
| 151 | (add-to-list 'load-path ,(pred stringp))) | ||
| 152 | (require 'foo nil 'nil)))) | ||
| 153 | |||
| 154 | (let ((use-package-always-ensure t)) | ||
| 155 | (match-expansion | ||
| 156 | (use-package foo :ensure t :load-path "foo") | ||
| 157 | `(progn | ||
| 158 | (use-package-ensure-elpa 'foo 't 'nil :ensure) | ||
| 159 | (eval-and-compile | ||
| 160 | (add-to-list 'load-path ,(pred stringp))) | ||
| 161 | (require 'foo nil 'nil)))) | ||
| 162 | |||
| 163 | (flet ((use-package-ensure-elpa | ||
| 164 | (name ensure state context &optional no-refresh) | ||
| 165 | (when ensure | ||
| 166 | (setq tried-to-install name)))) | ||
| 167 | (let (tried-to-install) | ||
| 168 | (eval '(use-package foo :ensure t)) | ||
| 169 | (should (eq tried-to-install 'foo))))) | ||
| 69 | 170 | ||
| 70 | ;; (ert-deftest use-package-test/:if () | 171 | ;; (ert-deftest use-package-test/:if () |
| 71 | ;; (should (equal (macroexpand (use-package)) | 172 | ;; (should (equal (macroexpand (use-package)) |
| @@ -212,9 +313,10 @@ | |||
| 212 | ;; '()))) | 313 | ;; '()))) |
| 213 | 314 | ||
| 214 | (ert-deftest use-package-test/:after () | 315 | (ert-deftest use-package-test/:after () |
| 215 | (should (equal (macroexpand '(use-package foo :after bar)) | 316 | (match-expansion |
| 216 | '(eval-after-load 'bar | 317 | (use-package foo :after bar) |
| 217 | '(require 'foo nil t))))) | 318 | `(eval-after-load 'bar |
| 319 | '(require 'foo nil t)))) | ||
| 218 | 320 | ||
| 219 | ;; (ert-deftest use-package-test/:demand () | 321 | ;; (ert-deftest use-package-test/:demand () |
| 220 | ;; (should (equal (macroexpand (use-package)) | 322 | ;; (should (equal (macroexpand (use-package)) |