* test/automated/package-x-test.el: Change the commentary.
[bpt/emacs.git] / test / automated / package-x-test.el
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-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