aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2013-06-27 13:26:54 +0400
committerDmitry Gutov2013-06-27 13:26:54 +0400
commit9ea5cf9fbd3c27ec743b6c42f64205054c8a130f (patch)
tree4b6f61a911f05f3b36ef45d6999302ab2b1c0a1d
parent1e0726398dd27532178fd0fb491872e7e2be396c (diff)
downloademacs-9ea5cf9fbd3c27ec743b6c42f64205054c8a130f.tar.gz
emacs-9ea5cf9fbd3c27ec743b6c42f64205054c8a130f.zip
* automated/Makefile.in (setwins): Include the 'data' subdirectory.
* automated/package-x-test.el: New file. * automated/package-test.el: New file. * automated/data/package: New directory, with test examples. * lisp/emacs-lisp/package-x.el (package-upload-buffer-internal): Adapt to `package-desc-version' being a list. Use `package--ac-desc-version' to retrieve version from a package archive element.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/emacs-lisp/package-x.el6
-rw-r--r--test/ChangeLog10
-rw-r--r--test/automated/Makefile.in2
-rw-r--r--test/automated/data/package/archive-contents10
-rw-r--r--test/automated/data/package/multi-file-0.2.3.tarbin0 -> 20480 bytes
-rw-r--r--test/automated/data/package/multi-file-readme.txt1
-rw-r--r--test/automated/data/package/newer-versions/archive-contents13
-rw-r--r--test/automated/data/package/newer-versions/new-pkg-1.0.el18
-rw-r--r--test/automated/data/package/newer-versions/simple-single-1.4.el36
-rw-r--r--test/automated/data/package/simple-depend-1.0.el17
-rw-r--r--test/automated/data/package/simple-single-1.3.el32
-rw-r--r--test/automated/data/package/simple-single-readme.txt3
-rwxr-xr-xtest/automated/package-test.el398
-rwxr-xr-xtest/automated/package-x-test.el107
15 files changed, 656 insertions, 4 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c8b213b6529..7e5b621a75c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12013-06-27 Dmitry Gutov <dgutov@yandex.ru>
2
3 * emacs-lisp/package-x.el (package-upload-buffer-internal): Adapt
4 to `package-desc-version' being a list. Use
5 `package--ac-desc-version' to retrieve version from a package
6 archive element.
7
12013-06-27 Juanma Barranquero <lekktu@gmail.com> 82013-06-27 Juanma Barranquero <lekktu@gmail.com>
2 9
3 New experimental feature to save&restore window and frame setup. 10 New experimental feature to save&restore window and frame setup.
diff --git a/lisp/emacs-lisp/package-x.el b/lisp/emacs-lisp/package-x.el
index 628eb88eea0..76d7565d64b 100644
--- a/lisp/emacs-lisp/package-x.el
+++ b/lisp/emacs-lisp/package-x.el
@@ -204,12 +204,12 @@ if it exists."
204 package--default-summary) 204 package--default-summary)
205 (read-string "Description of package: ") 205 (read-string "Description of package: ")
206 (package-desc-summary pkg-desc))) 206 (package-desc-summary pkg-desc)))
207 (pkg-version (package-desc-version pkg-desc)) 207 (split-version (package-desc-version pkg-desc))
208 (commentary 208 (commentary
209 (pcase file-type 209 (pcase file-type
210 (`single (lm-commentary)) 210 (`single (lm-commentary))
211 (`tar nil))) ;; FIXME: Get it from the README file. 211 (`tar nil))) ;; FIXME: Get it from the README file.
212 (split-version (version-to-list pkg-version)) 212 (pkg-version (package-version-join split-version))
213 (pkg-buffer (current-buffer))) 213 (pkg-buffer (current-buffer)))
214 214
215 ;; Get archive-contents from ARCHIVE-URL if it's non-nil, or 215 ;; Get archive-contents from ARCHIVE-URL if it's non-nil, or
@@ -223,7 +223,7 @@ if it exists."
223 (let ((elt (assq pkg-name (cdr contents)))) 223 (let ((elt (assq pkg-name (cdr contents))))
224 (if elt 224 (if elt
225 (if (version-list-<= split-version 225 (if (version-list-<= split-version
226 (package-desc-version (cdr elt))) 226 (package--ac-desc-version (cdr elt)))
227 (error "New package has smaller version: %s" pkg-version) 227 (error "New package has smaller version: %s" pkg-version)
228 (setcdr elt new-desc)) 228 (setcdr elt new-desc))
229 (setq contents (cons (car contents) 229 (setq contents (cons (car contents)
diff --git a/test/ChangeLog b/test/ChangeLog
index d3bd3d673cf..c556a65e05c 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,13 @@
12013-06-27 Daniel Hackney <dan@haxney.org>
2
3 * automated/Makefile.in (setwins): Include the 'data' subdirectory.
4
5 * automated/package-x-test.el: New file.
6
7 * automated/package-test.el: New file.
8
9 * automated/data/package: New directory, with test examples.
10
12013-06-27 Glenn Morris <rgm@gnu.org> 112013-06-27 Glenn Morris <rgm@gnu.org>
2 12
3 * automated/python-tests.el (python-tests-with-temp-file): 13 * automated/python-tests.el (python-tests-with-temp-file):
diff --git a/test/automated/Makefile.in b/test/automated/Makefile.in
index 1a4e3c9b1ea..6e7111e589c 100644
--- a/test/automated/Makefile.in
+++ b/test/automated/Makefile.in
@@ -50,7 +50,7 @@ emacs = EMACSLOADPATH=$(lispsrc):$(test) LC_ALL=C $(EMACS) $(EMACSOPT)
50# Common command to find subdirectories 50# Common command to find subdirectories
51setwins=subdirs=`find . -type d -print`; \ 51setwins=subdirs=`find . -type d -print`; \
52 for file in $$subdirs; do \ 52 for file in $$subdirs; do \
53 case $$file in */.* | */.*/* | */=* ) ;; \ 53 case $$file in */.* | */.*/* | */=* | ./data* ) ;; \
54 *) wins="$$wins $$file" ;; \ 54 *) wins="$$wins $$file" ;; \
55 esac; \ 55 esac; \
56 done 56 done
diff --git a/test/automated/data/package/archive-contents b/test/automated/data/package/archive-contents
new file mode 100644
index 00000000000..7e4a410030f
--- /dev/null
+++ b/test/automated/data/package/archive-contents
@@ -0,0 +1,10 @@
1(1
2 (simple-single .
3 [(1 3)
4 nil "A single-file package with no dependencies" single])
5 (simple-depend .
6 [(1 0)
7 ((simple-single (1 3))) "A single-file package with a dependency." single])
8 (multi-file .
9 [(0 2 3)
10 nil "Example of a multi-file tar package" tar]))
diff --git a/test/automated/data/package/multi-file-0.2.3.tar b/test/automated/data/package/multi-file-0.2.3.tar
new file mode 100644
index 00000000000..bdbbab0e6f4
--- /dev/null
+++ b/test/automated/data/package/multi-file-0.2.3.tar
Binary files differ
diff --git a/test/automated/data/package/multi-file-readme.txt b/test/automated/data/package/multi-file-readme.txt
new file mode 100644
index 00000000000..affd2e96fb0
--- /dev/null
+++ b/test/automated/data/package/multi-file-readme.txt
@@ -0,0 +1 @@
This is a bare-bones readme file for the multi-file package.
diff --git a/test/automated/data/package/newer-versions/archive-contents b/test/automated/data/package/newer-versions/archive-contents
new file mode 100644
index 00000000000..add5f2909d0
--- /dev/null
+++ b/test/automated/data/package/newer-versions/archive-contents
@@ -0,0 +1,13 @@
1(1
2 (simple-single .
3 [(1 4)
4 nil "A single-file package with no dependencies" single])
5 (simple-depend .
6 [(1 0)
7 ((simple-single (1 3))) "A single-file package with a dependency." single])
8 (new-pkg .
9 [(1 0)
10 nil "A package only seen after "updating" archive-contents" single])
11 (multi-file .
12 [(0 2 3)
13 nil "Example of a multi-file tar package" tar]))
diff --git a/test/automated/data/package/newer-versions/new-pkg-1.0.el b/test/automated/data/package/newer-versions/new-pkg-1.0.el
new file mode 100644
index 00000000000..7251622fa59
--- /dev/null
+++ b/test/automated/data/package/newer-versions/new-pkg-1.0.el
@@ -0,0 +1,18 @@
1;;; new-pkg.el --- A package only seen after "updating" archive-contents
2
3;; Author: J. R. Hacker <jrh@example.com>
4;; Version: 1.0
5
6;;; Commentary:
7
8;; This will only show up after updating "archive-contents".
9
10;;; Code:
11
12(defun new-pkg-frob ()
13 "Ignore me."
14 (ignore))
15
16(provide 'new-pkg)
17
18;;; new-pkg.el ends here
diff --git a/test/automated/data/package/newer-versions/simple-single-1.4.el b/test/automated/data/package/newer-versions/simple-single-1.4.el
new file mode 100644
index 00000000000..7d8178c05a5
--- /dev/null
+++ b/test/automated/data/package/newer-versions/simple-single-1.4.el
@@ -0,0 +1,36 @@
1;;; simple-single.el --- A single-file package with no dependencies
2
3;; Author: J. R. Hacker <jrh@example.com>
4;; Version: 1.4
5;; Keywords: frobnicate
6
7;;; Commentary:
8
9;; This package provides a minor mode to frobnicate and/or bifurcate
10;; any flanges you desire. To activate it, type "C-M-r M-3 butterfly"
11;; and all your dreams will come true.
12;;
13;; This is a new, updated version.
14
15;;; Code:
16
17(defgroup simple-single nil "Simply a file"
18 :group 'lisp)
19
20(defcustom simple-single-super-sunday nil
21 "How great is this?
22Default changed to `nil'."
23 :type 'boolean
24 :group 'simple-single
25 :package-version "1.4")
26
27(defvar simple-single-sudo-sandwich nil
28 "Make a sandwich?")
29
30;;;###autoload
31(define-minor-mode simple-single-mode
32 "It does good things to stuff")
33
34(provide 'simple-single)
35
36;;; simple-single.el ends here
diff --git a/test/automated/data/package/simple-depend-1.0.el b/test/automated/data/package/simple-depend-1.0.el
new file mode 100644
index 00000000000..b58b658d024
--- /dev/null
+++ b/test/automated/data/package/simple-depend-1.0.el
@@ -0,0 +1,17 @@
1;;; simple-depend.el --- A single-file package with a dependency.
2
3;; Author: J. R. Hacker <jrh@example.com>
4;; Version: 1.0
5;; Keywords: frobnicate
6;; Package-Requires: ((simple-single "1.3"))
7
8;;; Commentary:
9
10;; Depends on another package.
11
12;;; Code:
13
14(defvar simple-depend "Value"
15 "Some trivial code")
16
17;;; simple-depend.el ends here
diff --git a/test/automated/data/package/simple-single-1.3.el b/test/automated/data/package/simple-single-1.3.el
new file mode 100644
index 00000000000..a61784164f8
--- /dev/null
+++ b/test/automated/data/package/simple-single-1.3.el
@@ -0,0 +1,32 @@
1;;; simple-single.el --- A single-file package with no dependencies
2
3;; Author: J. R. Hacker <jrh@example.com>
4;; Version: 1.3
5;; Keywords: frobnicate
6
7;;; Commentary:
8
9;; This package provides a minor mode to frobnicate and/or bifurcate
10;; any flanges you desire. To activate it, type "C-M-r M-3 butterfly"
11;; and all your dreams will come true.
12
13;;; Code:
14
15(defgroup simple-single nil "Simply a file"
16 :group 'lisp)
17
18(defcustom simple-single-super-sunday t
19 "How great is this?"
20 :type 'boolean
21 :group 'simple-single)
22
23(defvar simple-single-sudo-sandwich nil
24 "Make a sandwich?")
25
26;;;###autoload
27(define-minor-mode simple-single-mode
28 "It does good things to stuff")
29
30(provide 'simple-single)
31
32;;; simple-single.el ends here
diff --git a/test/automated/data/package/simple-single-readme.txt b/test/automated/data/package/simple-single-readme.txt
new file mode 100644
index 00000000000..25d3034032b
--- /dev/null
+++ b/test/automated/data/package/simple-single-readme.txt
@@ -0,0 +1,3 @@
1This package provides a minor mode to frobnicate and/or bifurcate
2any flanges you desire. To activate it, type "C-M-r M-3 butterfly"
3and all your dreams will come true.
diff --git a/test/automated/package-test.el b/test/automated/package-test.el
new file mode 100755
index 00000000000..19402af0cdf
--- /dev/null
+++ b/test/automated/package-test.el
@@ -0,0 +1,398 @@
1;;; package-test.el --- Tests for the Emacs package system
2
3;; Author: Daniel Hackney <dan@haxney.org>
4;; Version: 1.0
5
6;; This file is part of GNU Emacs.
7
8;; GNU Emacs is free software; you can redistribute it and/or modify
9;; it under the terms of the GNU General Public License as published by
10;; the Free Software Foundation; either version 3, or (at your option)
11;; any later version.
12
13;; GNU Emacs is distributed in the hope that it will be useful,
14;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;; GNU General Public License for more details.
17
18;; You should have received a copy of the GNU General Public License
19;; along with GNU Emacs; see the file COPYING. If not, write to the
20;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21;; Boston, MA 02110-1301, USA.
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(defvar package-test-user-dir nil
40 "Directory to use for installing packages during testing.")
41
42(defvar package-test-file-dir (file-name-directory (or load-file-name
43 buffer-file-name))
44 "Directory of the actual \"package-test.el\" file.")
45
46(defvar simple-single-desc
47 (package-desc-create :name 'simple-single
48 :version '(1 3)
49 :summary "A single-file package with no dependencies"
50 :kind 'single)
51 "Expected `package-desc' parsed from simple-single-1.3.el.")
52
53(defvar simple-single-desc-1-4
54 (package-desc-create :name 'simple-single
55 :version '(1 4)
56 :summary "A single-file package with no dependencies"
57 :kind 'single)
58 "Expected `package-desc' parsed from simple-single-1.4.el.")
59
60(defvar simple-depend-desc
61 (package-desc-create :name 'simple-depend
62 :version '(1 0)
63 :summary "A single-file package with a dependency."
64 :kind 'single
65 :reqs '((simple-single (1 3))))
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 "Expected `package-desc' from \"multi-file-0.2.3.tar\".")
74
75(defvar new-pkg-desc
76 (package-desc-create :name 'new-pkg
77 :version '(1 0)
78 :kind 'single)
79 "Expected `package-desc' parsed from new-pkg-1.0.el.")
80
81(defvar package-test-data-dir (expand-file-name "data/package" package-test-file-dir)
82 "Base directory of package test files.")
83
84(defvar package-test-fake-contents-file
85 (expand-file-name "archive-contents" package-test-data-dir)
86 "Path to a static copy of \"archive-contents\".")
87
88(defvar package-test-built-file-suffixes '(".tar" "/dir" "/*.info")
89 "Remove these files when cleaning up a built package.")
90
91(cl-defmacro with-package-test ((&optional &key file
92 basedir
93 install
94 update-news
95 upload-base)
96 &rest body)
97 "Set up temporary locations and variables for testing."
98 (declare (indent 1))
99 `(let* ((package-test-user-dir (make-temp-file "pkg-test-user-dir-" t))
100 (package-user-dir package-test-user-dir)
101 (package-archives `(("gnu" . ,package-test-data-dir)))
102 (old-yes-no-defn (symbol-function 'yes-or-no-p))
103 (old-pwd default-directory)
104 package--initialized
105 package-alist
106 ,@(if update-news
107 '(package-update-news-on-upload t)
108 (list (cl-gensym)))
109 ,@(if upload-base
110 '((package-test-archive-upload-base (make-temp-file "pkg-archive-base-" t))
111 (package-archive-upload-base package-test-archive-upload-base))
112 (list (cl-gensym)))) ;; Dummy value so `let' doesn't try to bind `nil'
113 (unwind-protect
114 (progn
115 ,(if basedir `(cd ,basedir))
116 (setf (symbol-function 'yes-or-no-p) #'(lambda (&rest r) t))
117 (unless (file-directory-p package-user-dir)
118 (mkdir package-user-dir))
119 ,@(when install
120 `((package-initialize)
121 (package-refresh-contents)
122 (mapc 'package-install ,install)))
123 (with-temp-buffer
124 ,(if file
125 `(insert-file-contents ,file))
126 ,@body))
127
128 (when (file-directory-p package-test-user-dir)
129 (delete-directory package-test-user-dir t))
130
131 (when (and (boundp 'package-test-archive-upload-base)
132 (file-directory-p package-test-archive-upload-base))
133 (delete-directory package-test-archive-upload-base t))
134 (setf (symbol-function 'yes-or-no-p) old-yes-no-defn)
135 (cd old-pwd))))
136
137(defmacro with-fake-help-buffer (&rest body)
138 "Execute BODY in a temp buffer which is treated as the \"*Help*\" buffer."
139 `(with-temp-buffer
140 (help-mode)
141 ;; Trick `help-buffer' into using the temp buffer.
142 (let ((help-xref-following t))
143 ,@body)))
144
145(defun package-test-install-texinfo (file)
146 "Install from texinfo FILE.
147
148FILE should be a .texinfo file relative to the current
149`default-directory'"
150 (require 'info)
151 (let* ((full-file (expand-file-name file))
152 (info-file (replace-regexp-in-string "\\.texi\\'" ".info" full-file))
153 (old-info-defn (symbol-function 'Info-revert-find-node)))
154 (require 'info)
155 (setf (symbol-function 'Info-revert-find-node) #'ignore)
156 (with-current-buffer (find-file-literally full-file)
157 (unwind-protect
158 (progn
159 (require 'makeinfo)
160 (makeinfo-buffer)
161 ;; Give `makeinfo-buffer' a chance to finish
162 (while compilation-in-progress
163 (sit-for 0.1))
164 (call-process "ginstall-info" nil nil nil
165 (format "--info-dir=%s" default-directory)
166 (format "%s" info-file)))
167 (kill-buffer)
168 (setf (symbol-function 'Info-revert-find-node) old-info-defn)))))
169
170(defun package-test-strip-version (dir)
171 (replace-regexp-in-string "-pkg\\.el\\'" "" (package--description-file dir)))
172
173(defun package-test-suffix-matches (base suffix-list)
174 "Return file names matching BASE concatenated with each item in SUFFIX-LIST"
175 (cl-mapcan
176 '(lambda (item) (file-expand-wildcards (concat base item)))
177 suffix-list))
178
179(defun package-test-cleanup-built-files (dir)
180 "Remove files which were the result of creating a tar archive.
181
182DIR is the base name of the package directory, without the trailing slash"
183 (let* ((pkg-dirname (file-name-nondirectory dir)))
184 (dolist (file (package-test-suffix-matches dir package-test-built-file-suffixes))
185 (delete-file file))))
186
187(defun package-test-search-tar-file (filename)
188 "Search the current buffer's `tar-parse-info' variable for FILENAME.
189
190Must called from within a `tar-mode' buffer."
191 (cl-dolist (header tar-parse-info)
192 (let ((tar-name (tar-header-name header)))
193 (when (string= tar-name filename)
194 (cl-return t)))))
195
196(defun package-test-desc-version-string (desc)
197 "Return the package version as a string."
198 (package-version-join (package-desc-version desc)))
199
200(ert-deftest package-test-desc-from-buffer ()
201 "Parse an elisp buffer to get a `package-desc' object."
202 (with-package-test (:basedir "data/package" :file "simple-single-1.3.el")
203 (should (equal (package-buffer-info) simple-single-desc)))
204 (with-package-test (:basedir "data/package" :file "simple-depend-1.0.el")
205 (should (equal (package-buffer-info) simple-depend-desc)))
206 (with-package-test (:basedir "data/package"
207 :file "multi-file-0.2.3.tar")
208 (tar-mode)
209 (should (equal (package-tar-file-info) multi-file-desc))))
210
211(ert-deftest package-test-install-single ()
212 "Install a single file without using an archive."
213 (with-package-test (:basedir "data/package" :file "simple-single-1.3.el")
214 (should (package-install-from-buffer))
215 (package-initialize)
216 (should (package-installed-p 'simple-single))
217 (let* ((simple-pkg-dir (file-name-as-directory
218 (expand-file-name
219 "simple-single-1.3"
220 package-test-user-dir)))
221 (autoloads-file (expand-file-name "simple-single-autoloads.el"
222 simple-pkg-dir)))
223 (should (file-directory-p simple-pkg-dir))
224 (with-temp-buffer
225 (insert-file-contents (expand-file-name "simple-single-pkg.el"
226 simple-pkg-dir))
227 (should (string= (buffer-string)
228 (concat "(define-package \"simple-single\" \"1.3\" "
229 "\"A single-file package "
230 "with no dependencies\" 'nil)\n"))))
231 (should (file-exists-p autoloads-file))
232 (should-not (get-file-buffer autoloads-file)))))
233
234(ert-deftest package-test-install-dependency ()
235 "Install a package which includes a dependency."
236 (with-package-test ()
237 (package-initialize)
238 (package-refresh-contents)
239 (package-install 'simple-depend)
240 (should (package-installed-p 'simple-single))
241 (should (package-installed-p 'simple-depend))))
242
243(ert-deftest package-test-refresh-contents ()
244 "Parse an \"archive-contents\" file."
245 (with-package-test ()
246 (package-initialize)
247 (package-refresh-contents)
248 (should (eq 3 (length package-archive-contents)))))
249
250(ert-deftest package-test-install-single-from-archive ()
251 "Install a single package from a package archive."
252 (with-package-test ()
253 (package-initialize)
254 (package-refresh-contents)
255 (package-install 'simple-single)))
256
257(ert-deftest package-test-install-multifile ()
258 "Check properties of the installed multi-file package."
259 (with-package-test (:basedir "data/package" :install '(multi-file))
260 (let ((autoload-file
261 (expand-file-name "multi-file-autoloads.el"
262 (expand-file-name
263 "multi-file-0.2.3"
264 package-test-user-dir)))
265 (installed-files '("dir" "multi-file.info" "multi-file-sub.elc"
266 "multi-file-autoloads.el" "multi-file.elc"))
267 (autoload-forms '("^(defvar multi-file-custom-var"
268 "^(custom-autoload 'multi-file-custom-var"
269 "^(autoload 'multi-file-mode"))
270 (pkg-dir (file-name-as-directory
271 (expand-file-name
272 "multi-file-0.2.3"
273 package-test-user-dir))))
274 (package-refresh-contents)
275 (should (package-installed-p 'multi-file))
276 (with-temp-buffer
277 (insert-file-contents-literally autoload-file)
278 (dolist (fn installed-files)
279 (should (file-exists-p (expand-file-name fn pkg-dir))))
280 (dolist (re autoload-forms)
281 (goto-char (point-min))
282 (should (re-search-forward re nil t)))))))
283
284(ert-deftest package-test-update-listing ()
285 "Ensure installed package status is updated."
286 (with-package-test ()
287 (let ((buf (package-list-packages)))
288 (search-forward-regexp "^ +simple-single")
289 (package-menu-mark-install)
290 (package-menu-execute)
291 (should (package-installed-p 'simple-single))
292 (switch-to-buffer "*Packages*")
293 (goto-char (point-min))
294 (should (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+installed" nil t))
295 (goto-char (point-min))
296 (should-not (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+\\(available\\|new\\)" nil t))
297 (kill-buffer buf))))
298
299(ert-deftest package-test-update-archives ()
300 "Test updating package archives."
301 (with-package-test ()
302 (let ((buf (package-list-packages)))
303 (package-menu-refresh)
304 (search-forward-regexp "^ +simple-single")
305 (package-menu-mark-install)
306 (package-menu-execute)
307 (should (package-installed-p 'simple-single))
308 (let ((package-test-data-dir
309 (expand-file-name "data/package/newer-versions" package-test-file-dir)))
310 (setq package-archives `(("gnu" . ,package-test-data-dir)))
311 (package-menu-refresh)
312
313 ;; New version should be available and old version should be installed
314 (goto-char (point-min))
315 (should (re-search-forward "^\\s-+simple-single\\s-+1.4\\s-+new" nil t))
316 (should (re-search-forward "^\\s-+simple-single\\s-+1.3\\s-+installed" nil t))
317
318 (goto-char (point-min))
319 (should (re-search-forward "^\\s-+new-pkg\\s-+1.0\\s-+\\(available\\|new\\)" nil t))
320
321 (package-menu-mark-upgrades)
322 (package-menu-execute)
323 (package-menu-refresh)
324 (should (package-installed-p 'simple-single '(1 4)))))))
325
326(ert-deftest package-test-describe-package ()
327 "Test displaying help for a package."
328
329 (require 'finder-inf)
330 ;; Built-in
331 (with-fake-help-buffer
332 (describe-package '5x5)
333 (goto-char (point-min))
334 (should (search-forward "5x5 is a built-in package." nil t))
335 (should (search-forward "Status: Built-in." nil t))
336 (should (search-forward "Summary: simple little puzzle game" nil t))
337 (should (search-forward "The aim of 5x5" nil t)))
338
339 ;; Installed
340 (with-package-test ()
341 (package-initialize)
342 (package-refresh-contents)
343 (package-install 'simple-single)
344 (with-fake-help-buffer
345 (describe-package 'simple-single)
346 (goto-char (point-min))
347 (should (search-forward "simple-single is an installed package." nil t))
348 (should (search-forward
349 (format "Status: Installed in `%s/'."
350 (expand-file-name "simple-single-1.3" package-user-dir))
351 nil t))
352 (should (search-forward "Version: 1.3" nil t))
353 (should (search-forward "Summary: A single-file package with no dependencies"
354 nil t))
355 ;; No description, though. Because at this point we don't know
356 ;; what archive the package originated from, and we don't have
357 ;; its readme file saved.
358 )))
359
360(ert-deftest package-test-describe-not-installed-package ()
361 "Test displaying of the readme for not-installed package."
362
363 (with-package-test ()
364 (package-initialize)
365 (package-refresh-contents)
366 (with-fake-help-buffer
367 (describe-package 'simple-single)
368 (goto-char (point-min))
369 (should (search-forward "This package provides a minor mode to frobnicate"
370 nil t)))))
371
372(ert-deftest package-test-describe-non-installed-package ()
373 "Test displaying of the readme for non-installed package."
374
375 (with-package-test ()
376 (package-initialize)
377 (package-refresh-contents)
378 (with-fake-help-buffer
379 (describe-package 'simple-single)
380 (goto-char (point-min))
381 (should (search-forward "This package provides a minor mode to frobnicate"
382 nil t)))))
383
384(ert-deftest package-test-describe-non-installed-multi-file-package ()
385 "Test displaying of the readme for non-installed multi-file package."
386
387 (with-package-test ()
388 (package-initialize)
389 (package-refresh-contents)
390 (with-fake-help-buffer
391 (describe-package 'multi-file)
392 (goto-char (point-min))
393 (should (search-forward "This is a bare-bones readme file for the multi-file"
394 nil t)))))
395
396(provide 'package-test)
397
398;;; package-test.el ends here
diff --git a/test/automated/package-x-test.el b/test/automated/package-x-test.el
new file mode 100755
index 00000000000..c4923fc7d0a
--- /dev/null
+++ b/test/automated/package-x-test.el
@@ -0,0 +1,107 @@
1;;; package-test.el --- Tests for the Emacs package system
2
3;; Author: Daniel Hackney <dan@haxney.org>
4;; Version: 1.0
5
6;; This file is part of GNU Emacs.
7
8;; GNU Emacs is free software; you can redistribute it and/or modify
9;; it under the terms of the GNU General Public License as published by
10;; the Free Software Foundation; either version 3, or (at your option)
11;; any later version.
12
13;; GNU Emacs is distributed in the hope that it will be useful,
14;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;; GNU General Public License for more details.
17
18;; You should have received a copy of the GNU General Public License
19;; along with GNU Emacs; see the file COPYING. If not, write to the
20;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21;; Boston, MA 02110-1301, USA.
22
23;;; Commentary:
24
25;; Run this from a separate Emacs instance from your main one as it
26;; messes with the package archive files. In fact, it wouldn't be a
27;; bad idea to back up your whole package archive before testing!
28
29;; Run this in a clean Emacs session using:
30;;
31;; $ emacs -Q --batch -L . -l package-x-test.el -f ert-run-tests-batch-and-exit
32
33;;; Code:
34
35(require 'package-x)
36(require 'ert)
37(require 'cl-lib)
38
39;; package-test is not normally in `load-path', so temporarily set
40;; `load-path' to contain the current directory.
41(let ((load-path (append (list (file-name-directory (or load-file-name
42 buffer-file-name)))
43 load-path)))
44 (require 'package-test))
45
46(defvar package-x-test--single-archive-entry-1-3
47 (package-desc-create :name 'simple-single
48 :version '(1 3)
49 :summary "A single-file package with no dependencies"
50 :kind 'single)
51 "Expected contents of the archive entry from the \"simple-single\" package.")
52
53(defvar package-x-test--single-archive-entry-1-4
54 (package-desc-create :name 'simple-single
55 :version '(1 4)
56 :summary "A single-file package with no dependencies"
57 :kind 'single)
58 "Expected contents of the archive entry from the updated \"simple-single\" package.")
59
60(ert-deftest package-x-test-upload-buffer ()
61 "Test creating an \"archive-contents\" file"
62 (with-package-test (:basedir "data/package"
63 :file "simple-single-1.3.el"
64 :upload-base t)
65 (package-upload-buffer)
66 (should (file-exists-p (expand-file-name "archive-contents"
67 package-archive-upload-base)))
68 (should (file-exists-p (expand-file-name "simple-single-1.3.el"
69 package-archive-upload-base)))
70 (should (file-exists-p (expand-file-name "simple-single-readme.txt"
71 package-archive-upload-base)))
72
73 (let (archive-contents)
74 (with-temp-buffer
75 (insert-file-contents
76 (expand-file-name "archive-contents"
77 package-archive-upload-base))
78 (setq archive-contents
79 (package-read-from-string
80 (buffer-substring (point-min) (point-max)))))
81 (should (equal archive-contents
82 (list 1 package-x-test--single-archive-entry-1-3))))))
83
84(ert-deftest package-x-test-upload-new-version ()
85 "Test uploading a new version of a package"
86 (with-package-test (:basedir "data/package"
87 :file "simple-single-1.3.el"
88 :upload-base t)
89 (package-upload-buffer)
90 (with-temp-buffer
91 (insert-file-contents "newer-versions/simple-single-1.4.el")
92 (package-upload-buffer))
93
94 (let (archive-contents)
95 (with-temp-buffer
96 (insert-file-contents
97 (expand-file-name "archive-contents"
98 package-archive-upload-base))
99 (setq archive-contents
100 (package-read-from-string
101 (buffer-substring (point-min) (point-max)))))
102 (should (equal archive-contents
103 (list 1 package-x-test--single-archive-entry-1-4))))))
104
105(provide 'package-x-test)
106
107;;; package-x-test.el ends here