aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Kangas2020-02-05 13:12:01 +0100
committerStefan Kangas2020-02-05 13:18:12 +0100
commitaea12d4903136c057bb14d3fd7683bf7a4e1eff6 (patch)
tree183e578c697d5b95191df9384f714c999f84a7e7 /test
parent196da3017bc9b2fc6fecff0c0ce560e6c46b8a72 (diff)
downloademacs-aea12d4903136c057bb14d3fd7683bf7a4e1eff6.tar.gz
emacs-aea12d4903136c057bb14d3fd7683bf7a4e1eff6.zip
Add new filter commands to Package Menu (Bug#38424)
* lisp/emacs-lisp/package.el (package-menu-filter-by-version) (package-menu-filter-by-status, package-menu-filter-by-archive): New filter commands. (package-menu--filter-by): New helper function. (package-menu-filter-by-keyword, package-menu-filter-by-name): Use the above helper function. (package-menu-mode-menu): (package-menu-mode-map): Update menu to include new filter commands. * doc/emacs/package.texi (Package Menu): Document the new commands and re-arrange the sort order of commands to be closer to the one in describe-major-mode. * etc/NEWS: Announce the new commands. * lisp/emacs-lisp/package.el (package-menu--display): New function extracted from.... (package-menu--generate): ...here. * test/lisp/emacs-lisp/package-tests.el (with-package-menu-test): New macro. (package-test-update-listing, package-test-list-filter-by-name) (package-test-list-filter-clear): Use above macro. (package-test-list-filter-by-archive) (package-test-list-filter-by-keyword) (package-test-list-filter-by-status) (package-test-list-filter-by-version-=) (package-test-list-filter-by-version-<) (package-test-list-filter-by-version->): New tests. (package-test-filter-by-version): New helper function.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/package-tests.el117
1 files changed, 88 insertions, 29 deletions
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index 7d354d6ecde..adf917aef46 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -349,43 +349,102 @@ Must called from within a `tar-mode' buffer."
349 (goto-char (point-min)) 349 (goto-char (point-min))
350 (should (re-search-forward re nil t))))))) 350 (should (re-search-forward re nil t)))))))
351 351
352
353;;; Package Menu tests
354
355(defmacro with-package-menu-test (&rest body)
356 "Set up Package Menu (\"*Packages*\") buffer for testing."
357 (declare (indent 0) (debug (([&rest form]) body)))
358 `(with-package-test ()
359 (let ((buf (package-list-packages)))
360 (unwind-protect
361 (progn ,@body)
362 (kill-buffer buf)))))
363
352(ert-deftest package-test-update-listing () 364(ert-deftest package-test-update-listing ()
353 "Ensure installed package status is updated." 365 "Ensure installed package status is updated."
354 (with-package-test () 366 (with-package-menu-test
355 (let ((buf (package-list-packages))) 367 (search-forward-regexp "^ +simple-single")
356 (search-forward-regexp "^ +simple-single") 368 (package-menu-mark-install)
357 (package-menu-mark-install) 369 (package-menu-execute)
358 (package-menu-execute) 370 (run-hooks 'post-command-hook)
359 (run-hooks 'post-command-hook) 371 (should (package-installed-p 'simple-single))
360 (should (package-installed-p 'simple-single)) 372 (switch-to-buffer "*Packages*")
361 (switch-to-buffer "*Packages*") 373 (goto-char (point-min))
362 (goto-char (point-min)) 374 (should (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+installed" nil t))
363 (should (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+installed" nil t)) 375 (goto-char (point-min))
364 (goto-char (point-min)) 376 (should-not (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+\\(available\\|new\\)" nil t))))
365 (should-not (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+\\(available\\|new\\)" nil t)) 377
366 (kill-buffer buf)))) 378(ert-deftest package-test-list-filter-by-archive ()
379 "Ensure package list is filtered correctly by archive version."
380 (with-package-menu-test
381 ;; TODO: Add another package archive to test filtering, because
382 ;; the testing environment currently only has one.
383 (package-menu-filter-by-archive "gnu")
384 (goto-char (point-min))
385 (should (looking-at "^\\s-+multi-file"))
386 (should (= (count-lines (point-min) (point-max)) 4))
387 (should-error (package-menu-filter-by-archive "non-existent archive"))))
388
389(ert-deftest package-test-list-filter-by-keyword ()
390 "Ensure package list is filtered correctly by package keyword."
391 (with-package-menu-test
392 (package-menu-filter-by-keyword "frobnicate")
393 (goto-char (point-min))
394 (should (re-search-forward "^\\s-+simple-single" nil t))
395 (should (= (count-lines (point-min) (point-max)) 1))
396 (should-error (package-menu-filter-by-keyword "non-existent-keyword"))))
367 397
368(ert-deftest package-test-list-filter-by-name () 398(ert-deftest package-test-list-filter-by-name ()
369 "Ensure package list is filtered correctly by package name." 399 "Ensure package list is filtered correctly by package name."
370 (with-package-test () 400 (with-package-menu-test ()
371 (let ((buf (package-list-packages))) 401 (package-menu-filter-by-name "tetris")
372 (package-menu-filter-by-name "tetris") 402 (goto-char (point-min))
373 (goto-char (point-min)) 403 (should (re-search-forward "^\\s-+tetris" nil t))
374 (should (re-search-forward "^\\s-+tetris" nil t)) 404 (should (= (count-lines (point-min) (point-max)) 1))))
375 (should (= (count-lines (point-min) (point-max)) 1)) 405
376 (kill-buffer buf)))) 406(ert-deftest package-test-list-filter-by-status ()
407 "Ensure package list is filtered correctly by package status."
408 (with-package-menu-test
409 (package-menu-filter-by-status "available")
410 (goto-char (point-min))
411 (should (re-search-forward "^\\s-+multi-file" nil t))
412 (should (= (count-lines (point-min) (point-max)) 4))
413 ;; No installed packages in default environment.
414 (should-error (package-menu-filter-by-status "installed"))))
415
416(ert-deftest package-test-list-filter-by-version ()
417 (with-package-menu-test
418 (should-error (package-menu-filter-by-version "1.1" 'unknown-symbol))) )
419
420(defun package-test-filter-by-version (version predicate name)
421 (with-package-menu-test
422 (package-menu-filter-by-version version predicate)
423 (goto-char (point-min))
424 ;; We just check that the given package is included in the
425 ;; listing. One could be more ambitious.
426 (should (re-search-forward name))))
427
428(ert-deftest package-test-list-filter-by-version-= ()
429 "Ensure package list is filtered correctly by package version (=)."
430 (package-test-filter-by-version "1.1" '= "^\\s-+simple-two-depend"))
431
432(ert-deftest package-test-list-filter-by-version-< ()
433 "Ensure package list is filtered correctly by package version (<)."
434 (package-test-filter-by-version "1.2" '< "^\\s-+simple-two-depend"))
435
436(ert-deftest package-test-list-filter-by-version-> ()
437 "Ensure package list is filtered correctly by package version (>)."
438 (package-test-filter-by-version "1.0" '> "^\\s-+simple-two-depend"))
377 439
378(ert-deftest package-test-list-clear-filter () 440(ert-deftest package-test-list-clear-filter ()
379 "Ensure package list filter is cleared correctly." 441 "Ensure package list filter is cleared correctly."
380 (with-package-test () 442 (with-package-menu-test
381 (let ((buf (package-list-packages))) 443 (let ((num-packages (count-lines (point-min) (point-max))))
382 (let ((num-packages (count-lines (point-min) (point-max)))) 444 (package-menu-filter-by-name "tetris")
383 (should (> num-packages 1)) 445 (should (= (count-lines (point-min) (point-max)) 1))
384 (package-menu-filter-by-name "tetris") 446 (package-menu-clear-filter)
385 (should (= (count-lines (point-min) (point-max)) 1)) 447 (should (= (count-lines (point-min) (point-max)) num-packages)))))
386 (package-menu-clear-filter)
387 (should (= (count-lines (point-min) (point-max)) num-packages)))
388 (kill-buffer buf))))
389 448
390(ert-deftest package-test-update-archives () 449(ert-deftest package-test-update-archives ()
391 "Test updating package archives." 450 "Test updating package archives."