]> code.delx.au - gnu-emacs/blob - test/lisp/emacs-lisp/package-tests.el
0a446fde086049faeadad638a7a2693ad5ccf9a6
[gnu-emacs] / test / lisp / emacs-lisp / package-tests.el
1 ;;; package-test.el --- Tests for the Emacs package system
2
3 ;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
4
5 ;; Author: Daniel Hackney <dan@haxney.org>
6 ;; Version: 1.0
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; You may want to run this from a separate Emacs instance from your
26 ;; main one, because a bug in the code below could mess with your
27 ;; installed packages.
28
29 ;; Run this in a clean Emacs session using:
30 ;;
31 ;; $ emacs -Q --batch -L . -l package-test.el -l ert -f ert-run-tests-batch-and-exit
32
33 ;;; Code:
34
35 (require 'package)
36 (require 'ert)
37 (require 'cl-lib)
38
39 (setq package-menu-async nil)
40
41 (defvar package-test-user-dir nil
42 "Directory to use for installing packages during testing.")
43
44 (defvar package-test-file-dir (file-name-directory (or load-file-name
45 buffer-file-name))
46 "Directory of the actual \"package-test.el\" file.")
47
48 (defvar simple-single-desc
49 (package-desc-create :name 'simple-single
50 :version '(1 3)
51 :summary "A single-file package with no dependencies"
52 :kind 'single
53 :extras '((:authors ("J. R. Hacker" . "jrh@example.com"))
54 (:maintainer "J. R. Hacker" . "jrh@example.com")
55 (:url . "http://doodles.au")))
56 "Expected `package-desc' parsed from simple-single-1.3.el.")
57
58 (defvar simple-depend-desc
59 (package-desc-create :name 'simple-depend
60 :version '(1 0)
61 :summary "A single-file package with a dependency."
62 :kind 'single
63 :reqs '((simple-single (1 3)))
64 :extras '((:authors ("J. R. Hacker" . "jrh@example.com"))
65 (:maintainer "J. R. Hacker" . "jrh@example.com")))
66 "Expected `package-desc' parsed from simple-depend-1.0.el.")
67
68 (defvar multi-file-desc
69 (package-desc-create :name 'multi-file
70 :version '(0 2 3)
71 :summary "Example of a multi-file tar package"
72 :kind 'tar
73 :extras '((:url . "http://puddles.li")))
74 "Expected `package-desc' from \"multi-file-0.2.3.tar\".")
75
76 (defvar new-pkg-desc
77 (package-desc-create :name 'new-pkg
78 :version '(1 0)
79 :kind 'single)
80 "Expected `package-desc' parsed from new-pkg-1.0.el.")
81
82 (defvar simple-depend-desc-1
83 (package-desc-create :name 'simple-depend-1
84 :version '(1 0)
85 :summary "A single-file package with a dependency."
86 :kind 'single
87 :reqs '((simple-depend (1 0))
88 (multi-file (0 1))))
89 "`package-desc' used for testing dependencies.")
90
91 (defvar simple-depend-desc-2
92 (package-desc-create :name 'simple-depend-2
93 :version '(1 0)
94 :summary "A single-file package with a dependency."
95 :kind 'single
96 :reqs '((simple-depend-1 (1 0))
97 (multi-file (0 1))))
98 "`package-desc' used for testing dependencies.")
99
100 (defvar package-test-data-dir (expand-file-name "package-resources" package-test-file-dir)
101 "Base directory of package test files.")
102
103 (defvar package-test-fake-contents-file
104 (expand-file-name "archive-contents" package-test-data-dir)
105 "Path to a static copy of \"archive-contents\".")
106
107 (cl-defmacro with-package-test ((&optional &key file
108 basedir
109 install
110 location
111 update-news
112 upload-base)
113 &rest body)
114 "Set up temporary locations and variables for testing."
115 (declare (indent 1))
116 `(let* ((package-test-user-dir (make-temp-file "pkg-test-user-dir-" t))
117 (process-environment (cons (format "HOME=%s" package-test-user-dir)
118 process-environment))
119 (package-user-dir package-test-user-dir)
120 (package-archives `(("gnu" . ,(or ,location package-test-data-dir))))
121 (default-directory package-test-file-dir)
122 abbreviated-home-dir
123 package--initialized
124 package-alist
125 ,@(if update-news
126 '(package-update-news-on-upload t)
127 (list (cl-gensym)))
128 ,@(if upload-base
129 '((package-test-archive-upload-base (make-temp-file "pkg-archive-base-" t))
130 (package-archive-upload-base package-test-archive-upload-base))
131 (list (cl-gensym)))) ;; Dummy value so `let' doesn't try to bind nil
132 (let ((buf (get-buffer "*Packages*")))
133 (when (buffer-live-p buf)
134 (kill-buffer buf)))
135 (unwind-protect
136 (progn
137 ,(if basedir `(cd ,basedir))
138 (unless (file-directory-p package-user-dir)
139 (mkdir package-user-dir))
140 (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest r) t))
141 ((symbol-function 'y-or-n-p) (lambda (&rest r) t)))
142 ,@(when install
143 `((package-initialize)
144 (package-refresh-contents)
145 (mapc 'package-install ,install)))
146 (with-temp-buffer
147 ,(if file
148 `(insert-file-contents ,file))
149 ,@body)))
150
151 (when (file-directory-p package-test-user-dir)
152 (delete-directory package-test-user-dir t))
153
154 (when (and (boundp 'package-test-archive-upload-base)
155 (file-directory-p package-test-archive-upload-base))
156 (delete-directory package-test-archive-upload-base t)))))
157
158 (defmacro with-fake-help-buffer (&rest body)
159 "Execute BODY in a temp buffer which is treated as the \"*Help*\" buffer."
160 `(with-temp-buffer
161 (help-mode)
162 ;; Trick `help-buffer' into using the temp buffer.
163 (let ((help-xref-following t))
164 ,@body)))
165
166 (defun package-test-strip-version (dir)
167 (replace-regexp-in-string "-pkg\\.el\\'" "" (package--description-file dir)))
168
169 (defun package-test-suffix-matches (base suffix-list)
170 "Return file names matching BASE concatenated with each item in SUFFIX-LIST"
171 (cl-mapcan
172 '(lambda (item) (file-expand-wildcards (concat base item)))
173 suffix-list))
174
175 (defvar tar-parse-info)
176 (declare-function tar-header-name "tar-mode" (cl-x) t) ; defstruct
177
178 (defun package-test-search-tar-file (filename)
179 "Search the current buffer's `tar-parse-info' variable for FILENAME.
180
181 Must called from within a `tar-mode' buffer."
182 (cl-dolist (header tar-parse-info)
183 (let ((tar-name (tar-header-name header)))
184 (when (string= tar-name filename)
185 (cl-return t)))))
186
187 (defun package-test-desc-version-string (desc)
188 "Return the package version as a string."
189 (package-version-join (package-desc-version desc)))
190
191 (ert-deftest package-test-desc-from-buffer ()
192 "Parse an elisp buffer to get a `package-desc' object."
193 (with-package-test (:basedir "package-resources" :file "simple-single-1.3.el")
194 (should (equal (package-buffer-info) simple-single-desc)))
195 (with-package-test (:basedir "package-resources" :file "simple-depend-1.0.el")
196 (should (equal (package-buffer-info) simple-depend-desc)))
197 (with-package-test (:basedir "package-resources"
198 :file "multi-file-0.2.3.tar")
199 (tar-mode)
200 (should (equal (package-tar-file-info) multi-file-desc))))
201
202 (ert-deftest package-test-install-single ()
203 "Install a single file without using an archive."
204 (with-package-test (:basedir "package-resources" :file "simple-single-1.3.el")
205 (should (package-install-from-buffer))
206 (package-initialize)
207 (should (package-installed-p 'simple-single))
208 ;; Check if we properly report an "already installed".
209 (package-install 'simple-single)
210 (with-current-buffer "*Messages*"
211 (should (string-match "^[`‘']simple-single[’'] is already installed\n?\\'"
212 (buffer-string))))
213 (should (package-installed-p 'simple-single))
214 (let* ((simple-pkg-dir (file-name-as-directory
215 (expand-file-name
216 "simple-single-1.3"
217 package-test-user-dir)))
218 (autoloads-file (expand-file-name "simple-single-autoloads.el"
219 simple-pkg-dir)))
220 (should (file-directory-p simple-pkg-dir))
221 (with-temp-buffer
222 (insert-file-contents (expand-file-name "simple-single-pkg.el"
223 simple-pkg-dir))
224 (should (string= (buffer-string)
225 (concat ";;; -*- no-byte-compile: t -*-\n"
226 "(define-package \"simple-single\" \"1.3\" "
227 "\"A single-file package "
228 "with no dependencies\" 'nil "
229 ":authors '((\"J. R. Hacker\" . \"jrh@example.com\")) "
230 ":maintainer '(\"J. R. Hacker\" . \"jrh@example.com\") "
231 ":url \"http://doodles.au\""
232 ")\n"))))
233 (should (file-exists-p autoloads-file))
234 (should-not (get-file-buffer autoloads-file)))))
235
236 (ert-deftest package-test-install-dependency ()
237 "Install a package which includes a dependency."
238 (with-package-test ()
239 (package-initialize)
240 (package-refresh-contents)
241 (package-install 'simple-depend)
242 (should (package-installed-p 'simple-single))
243 (should (package-installed-p 'simple-depend))))
244
245 (ert-deftest package-test-macro-compilation ()
246 "Install a package which includes a dependency."
247 (with-package-test (:basedir "package-resources")
248 (package-install-file (expand-file-name "macro-problem-package-1.0/"))
249 (require 'macro-problem)
250 ;; `macro-problem-func' uses a macro from `macro-aux'.
251 (should (equal (macro-problem-func) '(progn a b)))
252 (package-install-file (expand-file-name "macro-problem-package-2.0/"))
253 ;; After upgrading, `macro-problem-func' depends on a new version
254 ;; of the macro from `macro-aux'.
255 (should (equal (macro-problem-func) '(1 b)))
256 ;; `macro-problem-10-and-90' depends on an entirely new macro from `macro-aux'.
257 (should (equal (macro-problem-10-and-90) '(10 90)))))
258
259 (ert-deftest package-test-install-two-dependencies ()
260 "Install a package which includes a dependency."
261 (with-package-test ()
262 (package-initialize)
263 (package-refresh-contents)
264 (package-install 'simple-two-depend)
265 (should (package-installed-p 'simple-single))
266 (should (package-installed-p 'simple-depend))
267 (should (package-installed-p 'simple-two-depend))))
268
269 (ert-deftest package-test-refresh-contents ()
270 "Parse an \"archive-contents\" file."
271 (with-package-test ()
272 (package-initialize)
273 (package-refresh-contents)
274 (should (eq 4 (length package-archive-contents)))))
275
276 (ert-deftest package-test-install-single-from-archive ()
277 "Install a single package from a package archive."
278 (with-package-test ()
279 (package-initialize)
280 (package-refresh-contents)
281 (package-install 'simple-single)))
282
283 (ert-deftest package-test-install-prioritized ()
284 "Install a lower version from a higher-prioritized archive."
285 (with-package-test ()
286 (let* ((newer-version (expand-file-name "package-resources/newer-versions"
287 package-test-file-dir))
288 (package-archives `(("older" . ,package-test-data-dir)
289 ("newer" . ,newer-version)))
290 (package-archive-priorities '(("older" . 100))))
291
292 (package-initialize)
293 (package-refresh-contents)
294 (package-install 'simple-single)
295
296 (let ((installed (cadr (assq 'simple-single package-alist))))
297 (should (version-list-= '(1 3)
298 (package-desc-version installed)))))))
299
300 (ert-deftest package-test-install-multifile ()
301 "Check properties of the installed multi-file package."
302 (with-package-test (:basedir "package-resources" :install '(multi-file))
303 (let ((autoload-file
304 (expand-file-name "multi-file-autoloads.el"
305 (expand-file-name
306 "multi-file-0.2.3"
307 package-test-user-dir)))
308 (installed-files '("dir" "multi-file.info" "multi-file-sub.elc"
309 "multi-file-autoloads.el" "multi-file.elc"))
310 (autoload-forms '("^(defvar multi-file-custom-var"
311 "^(custom-autoload 'multi-file-custom-var"
312 "^(autoload 'multi-file-mode"))
313 (pkg-dir (file-name-as-directory
314 (expand-file-name
315 "multi-file-0.2.3"
316 package-test-user-dir))))
317 (package-refresh-contents)
318 (should (package-installed-p 'multi-file))
319 (with-temp-buffer
320 (insert-file-contents-literally autoload-file)
321 (dolist (fn installed-files)
322 (should (file-exists-p (expand-file-name fn pkg-dir))))
323 (dolist (re autoload-forms)
324 (goto-char (point-min))
325 (should (re-search-forward re nil t)))))))
326
327 (ert-deftest package-test-update-listing ()
328 "Ensure installed package status is updated."
329 (with-package-test ()
330 (let ((buf (package-list-packages)))
331 (search-forward-regexp "^ +simple-single")
332 (package-menu-mark-install)
333 (package-menu-execute)
334 (run-hooks 'post-command-hook)
335 (should (package-installed-p 'simple-single))
336 (switch-to-buffer "*Packages*")
337 (goto-char (point-min))
338 (should (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+installed" nil t))
339 (goto-char (point-min))
340 (should-not (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+\\(available\\|new\\)" nil t))
341 (kill-buffer buf))))
342
343 (ert-deftest package-test-update-archives ()
344 "Test updating package archives."
345 (with-package-test ()
346 (let ((buf (package-list-packages)))
347 (package-menu-refresh)
348 (search-forward-regexp "^ +simple-single")
349 (package-menu-mark-install)
350 (package-menu-execute)
351 (should (package-installed-p 'simple-single))
352 (let ((package-test-data-dir
353 (expand-file-name "package-resources/newer-versions" package-test-file-dir)))
354 (setq package-archives `(("gnu" . ,package-test-data-dir)))
355 (package-menu-refresh)
356
357 ;; New version should be available and old version should be installed
358 (goto-char (point-min))
359 (should (re-search-forward "^\\s-+simple-single\\s-+1.4\\s-+available" nil t))
360 (should (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+installed" nil t))
361
362 (goto-char (point-min))
363 (should (re-search-forward "^\\s-+new-pkg\\s-+1.0\\s-+\\(available\\|new\\)" nil t))
364
365 (package-menu-mark-upgrades)
366 (package-menu-execute)
367 (package-menu-refresh)
368 (should (package-installed-p 'simple-single '(1 4)))))))
369
370 (ert-deftest package-test-update-archives-async ()
371 "Test updating package archives asynchronously."
372 (skip-unless (executable-find "python2"))
373 ;; For some reason this test doesn't work reliably on hydra.nixos.org.
374 (skip-unless (not (getenv "NIX_STORE")))
375 (let* ((package-menu-async t)
376 (default-directory package-test-data-dir)
377 (process (start-process
378 "package-server" "package-server-buffer"
379 (executable-find "python2")
380 "package-test-server.py"))
381 port)
382 (unwind-protect
383 (progn
384 (with-current-buffer "package-server-buffer"
385 (should
386 (with-timeout (10 nil)
387 (while (not port)
388 (accept-process-output nil 1)
389 (goto-char (point-min))
390 (if (re-search-forward "Serving HTTP on .* port \\([0-9]+\\) "
391 nil t)
392 (setq port (match-string 1))))
393 port)))
394 (with-package-test (:basedir
395 package-test-data-dir
396 :location (format "http://0.0.0.0:%s/" port))
397 (list-packages)
398 (should package--downloads-in-progress)
399 (should mode-line-process)
400 (should-not
401 (with-timeout (10 'timeout)
402 (while package--downloads-in-progress
403 (accept-process-output nil 1))
404 nil))
405 ;; If the server process died, there's some non-Emacs problem.
406 ;; Eg maybe the port was already in use.
407 (skip-unless (process-live-p process))
408 (goto-char (point-min))
409 (should
410 (search-forward-regexp "^ +simple-single" nil t))))
411 (if (process-live-p process) (kill-process process)))))
412
413 (ert-deftest package-test-describe-package ()
414 "Test displaying help for a package."
415
416 (require 'finder-inf)
417 ;; Built-in
418 (with-fake-help-buffer
419 (describe-package '5x5)
420 (goto-char (point-min))
421 (should (search-forward "5x5 is a built-in package." nil t))
422 ;; Don't assume the descriptions are in any particular order.
423 (save-excursion (should (search-forward "Status: Built-in." nil t)))
424 (save-excursion (should (search-forward "Summary: simple little puzzle game" nil t)))
425 (should (search-forward "The aim of 5x5" nil t)))
426
427 ;; Installed
428 (with-package-test ()
429 (package-initialize)
430 (package-refresh-contents)
431 (package-install 'simple-single)
432 (with-fake-help-buffer
433 (describe-package 'simple-single)
434 (goto-char (point-min))
435 (should (search-forward "simple-single is an installed package." nil t))
436 (save-excursion (should (re-search-forward "Status: Installed in ['`‘]simple-single-1.3/['’] (unsigned)." nil t)))
437 (save-excursion (should (search-forward "Version: 1.3" nil t)))
438 (save-excursion (should (search-forward "Summary: A single-file package with no dependencies" nil t)))
439 (save-excursion (should (search-forward "Homepage: http://doodles.au" nil t)))
440 (save-excursion (should (re-search-forward "Keywords: \\[?frobnicate\\]?" nil t)))
441 ;; No description, though. Because at this point we don't know
442 ;; what archive the package originated from, and we don't have
443 ;; its readme file saved.
444 )))
445
446 (ert-deftest package-test-describe-non-installed-package ()
447 "Test displaying of the readme for non-installed package."
448
449 (with-package-test ()
450 (package-initialize)
451 (package-refresh-contents)
452 (with-fake-help-buffer
453 (describe-package 'simple-single)
454 (goto-char (point-min))
455 (should (search-forward "Homepage: http://doodles.au" nil t))
456 (should (search-forward "This package provides a minor mode to frobnicate"
457 nil t)))))
458
459 (ert-deftest package-test-describe-non-installed-multi-file-package ()
460 "Test displaying of the readme for non-installed multi-file package."
461
462 (with-package-test ()
463 (package-initialize)
464 (package-refresh-contents)
465 (with-fake-help-buffer
466 (describe-package 'multi-file)
467 (goto-char (point-min))
468 (should (search-forward "Homepage: http://puddles.li" nil t))
469 (should (search-forward "This is a bare-bones readme file for the multi-file"
470 nil t)))))
471
472 (ert-deftest package-test-signed ()
473 "Test verifying package signature."
474 (skip-unless (ignore-errors
475 (let ((homedir (make-temp-file "package-test" t)))
476 (unwind-protect
477 (let ((process-environment
478 (cons (format "HOME=%s" homedir)
479 process-environment)))
480 (epg-check-configuration (epg-configuration))
481 (epg-find-configuration 'OpenPGP))
482 (delete-directory homedir t)))))
483 (let* ((keyring (expand-file-name "key.pub" package-test-data-dir))
484 (package-test-data-dir
485 (expand-file-name "package-resources/signed" package-test-file-dir)))
486 (with-package-test ()
487 (package-initialize)
488 (package-import-keyring keyring)
489 (package-refresh-contents)
490 (let ((package-check-signature 'allow-unsigned))
491 (should (package-install 'signed-good))
492 (should-error (package-install 'signed-bad)))
493 (let ((package-check-signature t))
494 (should (package-install 'signed-good))
495 (should-error (package-install 'signed-bad)))
496 (let ((package-check-signature nil))
497 (should (package-install 'signed-good))
498 (should (package-install 'signed-bad)))
499 ;; Check if the installed package status is updated.
500 (let ((buf (package-list-packages)))
501 (package-menu-refresh)
502 (should (re-search-forward
503 "^\\s-+signed-good\\s-+\\(\\S-+\\)\\s-+\\(\\S-+\\)\\s-"
504 nil t))
505 (should (string-equal (match-string-no-properties 1) "1.0"))
506 (should (string-equal (match-string-no-properties 2) "installed")))
507 ;; Check if the package description is updated.
508 (with-fake-help-buffer
509 (describe-package 'signed-good)
510 (goto-char (point-min))
511 (should (re-search-forward "signed-good is an? \\(\\S-+\\) package." nil t))
512 (should (string-equal (match-string-no-properties 1) "installed"))
513 (should (re-search-forward
514 "Status: Installed in ['`‘]signed-good-1.0/['’]."
515 nil t))))))
516
517
518 \f
519 ;;; Tests for package-x features.
520
521 (require 'package-x)
522
523 (defvar package-x-test--single-archive-entry-1-3
524 (cons 'simple-single
525 (package-make-ac-desc '(1 3) nil
526 "A single-file package with no dependencies"
527 'single
528 '((:authors ("J. R. Hacker" . "jrh@example.com"))
529 (:maintainer "J. R. Hacker" . "jrh@example.com")
530 (:url . "http://doodles.au"))))
531 "Expected contents of the archive entry from the \"simple-single\" package.")
532
533 (defvar package-x-test--single-archive-entry-1-4
534 (cons 'simple-single
535 (package-make-ac-desc '(1 4) nil
536 "A single-file package with no dependencies"
537 'single
538 '((:authors ("J. R. Hacker" . "jrh@example.com"))
539 (:maintainer "J. R. Hacker" . "jrh@example.com"))))
540 "Expected contents of the archive entry from the updated \"simple-single\" package.")
541
542 (ert-deftest package-x-test-upload-buffer ()
543 "Test creating an \"archive-contents\" file"
544 (with-package-test (:basedir "package-resources"
545 :file "simple-single-1.3.el"
546 :upload-base t)
547 (package-upload-buffer)
548 (should (file-exists-p (expand-file-name "archive-contents"
549 package-archive-upload-base)))
550 (should (file-exists-p (expand-file-name "simple-single-1.3.el"
551 package-archive-upload-base)))
552 (should (file-exists-p (expand-file-name "simple-single-readme.txt"
553 package-archive-upload-base)))
554
555 (let (archive-contents)
556 (with-temp-buffer
557 (insert-file-contents
558 (expand-file-name "archive-contents"
559 package-archive-upload-base))
560 (setq archive-contents
561 (package-read-from-string
562 (buffer-substring (point-min) (point-max)))))
563 (should (equal archive-contents
564 (list 1 package-x-test--single-archive-entry-1-3))))))
565
566 (ert-deftest package-x-test-upload-new-version ()
567 "Test uploading a new version of a package"
568 (with-package-test (:basedir "package-resources"
569 :file "simple-single-1.3.el"
570 :upload-base t)
571 (package-upload-buffer)
572 (with-temp-buffer
573 (insert-file-contents "newer-versions/simple-single-1.4.el")
574 (package-upload-buffer))
575
576 (let (archive-contents)
577 (with-temp-buffer
578 (insert-file-contents
579 (expand-file-name "archive-contents"
580 package-archive-upload-base))
581 (setq archive-contents
582 (package-read-from-string
583 (buffer-substring (point-min) (point-max)))))
584 (should (equal archive-contents
585 (list 1 package-x-test--single-archive-entry-1-4))))))
586
587 (ert-deftest package-test-get-deps ()
588 "Test `package--get-deps' with complex structures."
589 (let ((package-alist
590 (mapcar (lambda (p) (list (package-desc-name p) p))
591 (list simple-single-desc
592 simple-depend-desc
593 multi-file-desc
594 new-pkg-desc
595 simple-depend-desc-1
596 simple-depend-desc-2))))
597 (should
598 (equal (package--get-deps 'simple-depend)
599 '(simple-single)))
600 (should
601 (equal (package--get-deps 'simple-depend 'indirect)
602 nil))
603 (should
604 (equal (package--get-deps 'simple-depend 'direct)
605 '(simple-single)))
606 (should
607 (equal (package--get-deps 'simple-depend-2)
608 '(simple-depend-1 multi-file simple-depend simple-single)))
609 (should
610 (equal (package--get-deps 'simple-depend-2 'indirect)
611 '(simple-depend multi-file simple-single)))
612 (should
613 (equal (package--get-deps 'simple-depend-2 'direct)
614 '(simple-depend-1 multi-file)))))
615
616 (ert-deftest package-test-sort-by-dependence ()
617 "Test `package--sort-by-dependence' with complex structures."
618 (let ((package-alist
619 (mapcar (lambda (p) (list (package-desc-name p) p))
620 (list simple-single-desc
621 simple-depend-desc
622 multi-file-desc
623 new-pkg-desc
624 simple-depend-desc-1
625 simple-depend-desc-2)))
626 (delete-list
627 (list simple-single-desc
628 simple-depend-desc
629 multi-file-desc
630 new-pkg-desc
631 simple-depend-desc-1
632 simple-depend-desc-2)))
633 (should
634 (equal (package--sort-by-dependence delete-list)
635
636 (list simple-depend-desc-2 simple-depend-desc-1 new-pkg-desc
637 multi-file-desc simple-depend-desc simple-single-desc)))
638 (should
639 (equal (package--sort-by-dependence (reverse delete-list))
640 (list new-pkg-desc simple-depend-desc-2 simple-depend-desc-1
641 multi-file-desc simple-depend-desc simple-single-desc)))))
642
643 (provide 'package-test)
644
645 ;;; package-test.el ends here