Stefan Kangas writes: > Philip Kaludercic writes: > >> How does this look like: > > Thanks, some comments below: > >> From e865604c6a9d06cb986752e28b9ae88d7bc8011e Mon Sep 17 00:00:00 2001 >> From: Philip Kaludercic >> Date: Thu, 14 Sep 2023 15:09:19 +0200 >> Subject: [PATCH] package-tests.el: Add test Bug#65475 >> >> * test/lisp/emacs-lisp/package-tests.el (with-package-test): Bind >> package-selected-packages. >> (package-test-bug65475): Add test. >> --- >> test/lisp/emacs-lisp/package-tests.el | 18 ++++++++++++++++++ >> 1 file changed, 18 insertions(+) >> >> diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el >> index 113b4ec12a8..b55254bc036 100644 >> --- a/test/lisp/emacs-lisp/package-tests.el >> +++ b/test/lisp/emacs-lisp/package-tests.el >> @@ -125,6 +125,7 @@ with-package-test >> abbreviated-home-dir >> package--initialized >> package-alist >> + package-selected-packages >> ,@(if update-news >> '(package-update-news-on-upload t) >> (list (cl-gensym))) >> @@ -307,6 +308,23 @@ package-test-bug58367 >> (package-delete (cadr (assq 'v7-withsub package-alist)))) >> )) >> >> +(ert-deftest package-test-bug65475 () >> + "Ensure deleting a package clears `package-selected-packages'." > ^^^^^^ (1) ^^^^^^^^^ (2) > > 1. Is this word redundant? > 2. Maybe: "the last package"? Makes sense. >> + (with-package-test (:basedir (ert-resource-directory)) >> + (package-initialize) >> + (let* ((pkg-el "simple-single-1.3.el") >> + (source-file (expand-file-name pkg-el (ert-resource-directory)))) >> + (should-not package-alist) >> + (should-not package-selected-packages) >> + (package-install-file source-file) >> + (should package-alist) >> + (should package-selected-packages) >> + (let ((desc (cadr (assq 'simple-single package-alist)))) >> + (should desc) >> + (package-delete desc)) > > I'm not sure that the `should's and `should-not's above help, because > they make the intention of this test case less clear. For example, the > test fails if installing the package fails, but don't we already have a > separate test for that? Do we really need this test to fail in that > case also? > > If we want to check that, as a precondition, `package-alist' and > `package-selected-packages' are empty, perhaps that should be some > `cl-assert's in the `with-package-test' macro? OTOH, we already know > it's nil because of the let in the macro, so wouldn't that just be > verifying that let-binding a variable works correctly? > > It seems like the relevant `should's for this particular test are the > two below: No, I think it should be OK to drop the first two, I just wasn't familiar with the `with-package-test' at first when writing the test. Here is the updated patch: