Merge from emacs-24; up to 2012-12-29T12:57:49Z!fgallina@gnu.org
[bpt/emacs.git] / test / automated / package-x-test.el
1 ;;; package-test.el --- Tests for the Emacs package system
2
3 ;; Copyright (C) 2013 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-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 (cons 'simple-single
48 (package-make-ac-desc '(1 3) nil
49 "A single-file package with no dependencies"
50 '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 (cons 'simple-single
55 (package-make-ac-desc '(1 4) nil
56 "A single-file package with no dependencies"
57 '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