Closed kaushalmodi closed 6 years ago
some way to add tests for these things in use-package-tests.el that is independent from whether I do or don't use it in my own config?
Writing ert tests is on my long list of Emacs things to learn.. Aren't the ert tests run using emacs --batch
? So they would automatically be agnostic to the user config.. Now I don't know the main part.. "How to write the above test in ert".
I believe, the same test as above can be replicated in ert.. I just don't know the syntax:
provide
.. make sure that that "package" couldn't ever be found on GNU Elpa (as we are running emacs --batch
.. we can make it use just that archive).. and so I have that arbitrary name in my test.use-package
load that package with use-package-always-ensure
set to t
and :load-path
set to the path where ert generated that dummy package.use-package
form, run the fn from that package and compare the return value of that fn with the expected constant.With this bug, ert will see that "package not available" error in the "eval use-package" stage.
Sorry, but I wished I could have helped more..
Create a dummy "package"
I think it would be simpler to do something like
(cl-letf* ((tried-to-install nil)
((symbol-function 'package-install)
(lambda (pkg) (setq tried-to-install pkg))))
(eval '(use-package foo :ensure t))
(should (eq tried-to-install 'foo)))
@npostavs If I understand correctly, that test doesn't test this bug fix.. somewhere use-package-always-ensure
must be set to t
and :load-path
must also be set.. and it should be checked that tried-to-install
stays at nil
, right?.. or may be I just need to bookmark this to revisit to understand it better.
@kaushalmodi yeah, that was just a sketch to give the flavour, several tests would be necessary to hit all the relevant cases that you point out.
@npostavs Excellent! With your help I was able to make a decent test, which even uncovered yet another corner case when using :ensure
with :load-path
:
(ert-deftest use-package-test/:ensure ()
(let ((use-package-always-ensure nil))
(match-expansion
(use-package foo :ensure t)
`(progn
(use-package-ensure-elpa 'foo 't 'nil :ensure)
(require 'foo nil 'nil))))
(let ((use-package-always-ensure t))
(match-expansion
(use-package foo :ensure t)
`(progn
(use-package-ensure-elpa 'foo 't 'nil :ensure)
(require 'foo nil 'nil))))
(let ((use-package-always-ensure nil))
(match-expansion
(use-package foo :ensure nil)
`(progn
(use-package-ensure-elpa 'foo 'nil 'nil :ensure)
(require 'foo nil 'nil))))
(let ((use-package-always-ensure t))
(match-expansion
(use-package foo :ensure nil)
`(progn
(use-package-ensure-elpa 'foo 'nil 'nil :ensure)
(require 'foo nil 'nil))))
(let ((use-package-always-ensure nil))
(match-expansion
(use-package foo :load-path "foo")
`(progn
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil 'nil))))
(let ((use-package-always-ensure t))
(match-expansion
(use-package foo :load-path "foo")
`(progn
(use-package-ensure-elpa 'foo 'nil 'nil :ensure)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil 'nil))))
(let ((use-package-always-ensure nil))
(match-expansion
(use-package foo :ensure nil :load-path "foo")
`(progn
(use-package-ensure-elpa 'foo 'nil 'nil :ensure)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil 'nil))))
(let ((use-package-always-ensure t))
(match-expansion
(use-package foo :ensure nil :load-path "foo")
`(progn
(use-package-ensure-elpa 'foo 'nil 'nil :ensure)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil 'nil))))
(let ((use-package-always-ensure nil))
(match-expansion
(use-package foo :ensure t :load-path "foo")
`(progn
(use-package-ensure-elpa 'foo 't 'nil :ensure)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil 'nil))))
(let ((use-package-always-ensure t))
(match-expansion
(use-package foo :ensure t :load-path "foo")
`(progn
(use-package-ensure-elpa 'foo 't 'nil :ensure)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil 'nil))))
(let (tried-to-install)
(flet ((use-package-ensure-elpa
(name ensure state context &optional no-refresh)
(when ensure
(setq tried-to-install name))))
(eval '(use-package foo :ensure t))
(should (eq tried-to-install 'foo)))))
(flet ((use-package-ensure-elpa (name ensure state context &optional no-refresh)
Using (cl-flet (((symbol-function 'use-package-ensure-elpa) (lambda (name ...
would be the non-deprecated way of doing that.
Mon Jan 15 12:52:27 GMT 2018
Not sure if I should open another issue for this.
Recently spent some time recently cleaning up/modernising my init.d
to use use-package
.
Setting use-package-always-ensure t
, I get the following errors:
Error (use-package): Failed to install dired-x: Package ‘dired-x-’ is unavailable
Error (use-package): Failed to install dired: Package ‘dired-’ is unavailable
Error (use-package): Failed to install uniquify: Package ‘uniquify-’ is unavailable
Error (use-package): Failed to install font-lock: Package ‘font-lock-’ is unavailable
Error (use-package): Failed to install em-smart: Package ‘em-smart-’ is unavailable
These errors can be silenced using :ensure nil
, but raises the questions:
package
?features
also be considered as packages
?use-package
be used to configure features
?(With use-package-always-ensure
unset, no errors are generated.)
I get similar errors as reported by @rprimus above when running profile-dotemacs.el to profile my init file. In my case, it was the following packages:
Error (use-package): Failed to install cus-edit: Package ‘cus-edit-’ is unavailable
Error (use-package): Failed to install ediff-wind: Package ‘ediff-wind-’ is unavailable
Error (use-package): Failed to install frame: Package ‘frame-’ is unavailable
Error (use-package): Failed to install dired: Package ‘dired-’ is unavailable
Error (use-package): Failed to install dired-x: Package ‘dired-x-’ is unavailable
Error (use-package): Failed to install newcomment: Package ‘newcomment-’ is unavailable
Error (use-package): Failed to install isearch: Package ‘isearch-’ is unavailable
Error (use-package): Failed to install auto-insert: Package ‘auto-insert-’ is unavailable
Error (use-package): Failed to install org-agenda: Package ‘org-agenda-’ is unavailable
Are these examples of edge cases not detected by the above tests?
Getting same error
Failed to install cus-edit: Package ‘cus-edit’ is unavailable
Hi ,
I tried out the new option and set it to
t
.But it gives me this error:
I have the below in my emacs init:
The
defuns.el
is present in thatelisp/
path.But is looks like
defuns
is being tried to be installed by the package manager (even though it is available in theload-path
) when this new option ist
(or probably because:ensure
ist
).