Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / test / automated / package-x-test.el
blobcce51b63561331850ed2528a9baae9d4648eee0a
1 ;;; package-test.el --- Tests for the Emacs package system
3 ;; Copyright (C) 2013-2014 Free Software Foundation, Inc.
5 ;; Author: Daniel Hackney <dan@haxney.org>
6 ;; Version: 1.0
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
23 ;;; Commentary:
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.
29 ;; Run this in a clean Emacs session using:
31 ;; $ emacs -Q --batch -L . -l package-x-test.el -f ert-run-tests-batch-and-exit
33 ;;; Code:
35 (require 'package-x)
36 (require 'ert)
37 (require 'cl-lib)
38 (eval-when-compile (require 'package-test))
40 ;; package-test is not normally in `load-path', so temporarily set
41 ;; `load-path' to contain the current directory.
42 (let ((load-path (append (list (file-name-directory (or load-file-name
43 buffer-file-name)))
44 load-path)))
45 (require 'package-test))
47 (defvar package-x-test--single-archive-entry-1-3
48 (cons 'simple-single
49 (package-make-ac-desc '(1 3) nil
50 "A single-file package with no dependencies"
51 'single
52 '((:url . "http://doodles.au"))))
53 "Expected contents of the archive entry from the \"simple-single\" package.")
55 (defvar package-x-test--single-archive-entry-1-4
56 (cons 'simple-single
57 (package-make-ac-desc '(1 4) nil
58 "A single-file package with no dependencies"
59 'single
60 nil))
61 "Expected contents of the archive entry from the updated \"simple-single\" package.")
63 (ert-deftest package-x-test-upload-buffer ()
64 "Test creating an \"archive-contents\" file"
65 (with-package-test (:basedir "data/package"
66 :file "simple-single-1.3.el"
67 :upload-base t)
68 (package-upload-buffer)
69 (should (file-exists-p (expand-file-name "archive-contents"
70 package-archive-upload-base)))
71 (should (file-exists-p (expand-file-name "simple-single-1.3.el"
72 package-archive-upload-base)))
73 (should (file-exists-p (expand-file-name "simple-single-readme.txt"
74 package-archive-upload-base)))
76 (let (archive-contents)
77 (with-temp-buffer
78 (insert-file-contents
79 (expand-file-name "archive-contents"
80 package-archive-upload-base))
81 (setq archive-contents
82 (package-read-from-string
83 (buffer-substring (point-min) (point-max)))))
84 (should (equal archive-contents
85 (list 1 package-x-test--single-archive-entry-1-3))))))
87 (ert-deftest package-x-test-upload-new-version ()
88 "Test uploading a new version of a package"
89 (with-package-test (:basedir "data/package"
90 :file "simple-single-1.3.el"
91 :upload-base t)
92 (package-upload-buffer)
93 (with-temp-buffer
94 (insert-file-contents "newer-versions/simple-single-1.4.el")
95 (package-upload-buffer))
97 (let (archive-contents)
98 (with-temp-buffer
99 (insert-file-contents
100 (expand-file-name "archive-contents"
101 package-archive-upload-base))
102 (setq archive-contents
103 (package-read-from-string
104 (buffer-substring (point-min) (point-max)))))
105 (should (equal archive-contents
106 (list 1 package-x-test--single-archive-entry-1-4))))))
108 (provide 'package-x-test)
110 ;;; package-x-test.el ends here