]> code.delx.au - gnu-emacs/blobdiff - test/automated/package-test.el
Merge from emacs-24
[gnu-emacs] / test / automated / package-test.el
old mode 100755 (executable)
new mode 100644 (file)
index 706ba95..a0c1359
@@ -1,6 +1,6 @@
 ;;; package-test.el --- Tests for the Emacs package system
 
-;; Copyright (C) 2013 Free Software Foundation, Inc.
+;; Copyright (C) 2013-2014 Free Software Foundation, Inc.
 
 ;; Author: Daniel Hackney <dan@haxney.org>
 ;; Version: 1.0
   (package-desc-create :name 'simple-single
                        :version '(1 3)
                        :summary "A single-file package with no dependencies"
-                       :kind 'single)
+                       :kind 'single
+                       :extras '((:url . "http://doodles.au")))
   "Expected `package-desc' parsed from simple-single-1.3.el.")
 
-(defvar simple-single-desc-1-4
-  (package-desc-create :name 'simple-single
-                       :version '(1 4)
-                       :summary "A single-file package with no dependencies"
-                       :kind 'single)
-  "Expected `package-desc' parsed from simple-single-1.4.el.")
-
 (defvar simple-depend-desc
   (package-desc-create :name 'simple-depend
                        :version '(1 0)
@@ -69,7 +63,8 @@
   (package-desc-create :name 'multi-file
                        :version '(0 2 3)
                        :summary "Example of a multi-file tar package"
-                       :kind 'tar)
+                       :kind 'tar
+                       :extras '((:url . "http://puddles.li")))
   "Expected `package-desc' from \"multi-file-0.2.3.tar\".")
 
 (defvar new-pkg-desc
@@ -85,9 +80,6 @@
   (expand-file-name "archive-contents" package-test-data-dir)
   "Path to a static copy of \"archive-contents\".")
 
-(defvar package-test-built-file-suffixes '(".tar" "/dir" "/*.info")
-  "Remove these files when cleaning up a built package.")
-
 (cl-defmacro with-package-test ((&optional &key file
                                            basedir
                                            install
   "Set up temporary locations and variables for testing."
   (declare (indent 1))
   `(let* ((package-test-user-dir (make-temp-file "pkg-test-user-dir-" t))
+          (process-environment (cons (format "HOME=%s" package-test-user-dir)
+                                     process-environment))
           (package-user-dir package-test-user-dir)
           (package-archives `(("gnu" . ,package-test-data-dir)))
           (old-yes-no-defn (symbol-function 'yes-or-no-p))
-          (old-pwd default-directory)
+          (default-directory package-test-file-dir)
           package--initialized
           package-alist
           ,@(if update-news
        (when (and (boundp 'package-test-archive-upload-base)
                   (file-directory-p package-test-archive-upload-base))
          (delete-directory package-test-archive-upload-base t))
-       (setf (symbol-function 'yes-or-no-p) old-yes-no-defn)
-       (cd old-pwd))))
+       (setf (symbol-function 'yes-or-no-p) old-yes-no-defn))))
 
 (defmacro with-fake-help-buffer (&rest body)
   "Execute BODY in a temp buffer which is treated as the \"*Help*\" buffer."
     (let ((help-xref-following t))
       ,@body)))
 
-(defun package-test-install-texinfo (file)
-  "Install from texinfo FILE.
-
-FILE should be a .texinfo file relative to the current
-`default-directory'"
-  (require 'info)
-  (let* ((full-file (expand-file-name file))
-         (info-file (replace-regexp-in-string "\\.texi\\'" ".info" full-file))
-         (old-info-defn (symbol-function 'Info-revert-find-node)))
-    (require 'info)
-    (setf (symbol-function 'Info-revert-find-node) #'ignore)
-    (with-current-buffer (find-file-literally full-file)
-      (unwind-protect
-          (progn
-            (require 'makeinfo)
-            (makeinfo-buffer)
-            ;; Give `makeinfo-buffer' a chance to finish
-            (while compilation-in-progress
-              (sit-for 0.1))
-            (call-process "ginstall-info" nil nil nil
-                          (format "--info-dir=%s" default-directory)
-                          (format "%s" info-file)))
-        (kill-buffer)
-        (setf (symbol-function 'Info-revert-find-node) old-info-defn)))))
-
 (defun package-test-strip-version (dir)
   (replace-regexp-in-string "-pkg\\.el\\'" "" (package--description-file dir)))
 
@@ -176,13 +144,8 @@ FILE should be a .texinfo file relative to the current
    '(lambda (item) (file-expand-wildcards (concat base item)))
    suffix-list))
 
-(defun package-test-cleanup-built-files (dir)
-  "Remove files which were the result of creating a tar archive.
-
-DIR is the base name of the package directory, without the trailing slash"
-  (let* ((pkg-dirname (file-name-nondirectory dir)))
-    (dolist (file (package-test-suffix-matches dir package-test-built-file-suffixes))
-      (delete-file file))))
+(defvar tar-parse-info)
+(declare-function tar-header-name "tar-mode" (cl-x) t) ; defstruct
 
 (defun package-test-search-tar-file (filename)
   "Search the current buffer's `tar-parse-info' variable for FILENAME.
@@ -225,9 +188,12 @@ Must called from within a `tar-mode' buffer."
         (insert-file-contents (expand-file-name "simple-single-pkg.el"
                                                 simple-pkg-dir))
         (should (string= (buffer-string)
-                         (concat "(define-package \"simple-single\" \"1.3\" "
+                         (concat ";;; -*- no-byte-compile: t -*-\n"
+                                 "(define-package \"simple-single\" \"1.3\" "
                                  "\"A single-file package "
-                                 "with no dependencies\" 'nil)\n"))))
+                                 "with no dependencies\" 'nil "
+                                 ":url \"http://doodles.au\""
+                                 ")\n"))))
       (should (file-exists-p autoloads-file))
       (should-not (get-file-buffer autoloads-file)))))
 
@@ -240,12 +206,22 @@ Must called from within a `tar-mode' buffer."
     (should (package-installed-p 'simple-single))
     (should (package-installed-p 'simple-depend))))
 
+(ert-deftest package-test-install-two-dependencies ()
+  "Install a package which includes a dependency."
+  (with-package-test ()
+    (package-initialize)
+    (package-refresh-contents)
+    (package-install 'simple-two-depend)
+    (should (package-installed-p 'simple-single))
+    (should (package-installed-p 'simple-depend))
+    (should (package-installed-p 'simple-two-depend))))
+
 (ert-deftest package-test-refresh-contents ()
   "Parse an \"archive-contents\" file."
   (with-package-test ()
     (package-initialize)
     (package-refresh-contents)
-    (should (eq 3 (length package-archive-contents)))))
+    (should (eq 4 (length package-archive-contents)))))
 
 (ert-deftest package-test-install-single-from-archive ()
   "Install a single package from a package archive."
@@ -346,29 +322,19 @@ Must called from within a `tar-mode' buffer."
      (goto-char (point-min))
      (should (search-forward "simple-single is an installed package." nil t))
      (should (search-forward
-              (format "Status: Installed in `%s/'."
+              (format "Status: Installed in `%s/' (unsigned)."
                       (expand-file-name "simple-single-1.3" package-user-dir))
               nil t))
      (should (search-forward "Version: 1.3" nil t))
      (should (search-forward "Summary: A single-file package with no dependencies"
                              nil t))
+     (should (search-forward "Homepage: http://doodles.au" nil t))
+     (should (re-search-forward "Keywords: \\[?frobnicate\\]?" nil t))
      ;; No description, though. Because at this point we don't know
      ;; what archive the package originated from, and we don't have
      ;; its readme file saved.
      )))
 
-(ert-deftest package-test-describe-not-installed-package ()
-  "Test displaying of the readme for not-installed package."
-
-  (with-package-test ()
-    (package-initialize)
-    (package-refresh-contents)
-    (with-fake-help-buffer
-     (describe-package 'simple-single)
-     (goto-char (point-min))
-     (should (search-forward "This package provides a minor mode to frobnicate"
-                             nil t)))))
-
 (ert-deftest package-test-describe-non-installed-package ()
   "Test displaying of the readme for non-installed package."
 
@@ -378,6 +344,7 @@ Must called from within a `tar-mode' buffer."
     (with-fake-help-buffer
      (describe-package 'simple-single)
      (goto-char (point-min))
+     (should (search-forward "Homepage: http://doodles.au" nil t))
      (should (search-forward "This package provides a minor mode to frobnicate"
                              nil t)))))
 
@@ -390,9 +357,45 @@ Must called from within a `tar-mode' buffer."
     (with-fake-help-buffer
      (describe-package 'multi-file)
      (goto-char (point-min))
+     (should (search-forward "Homepage: http://puddles.li" nil t))
      (should (search-forward "This is a bare-bones readme file for the multi-file"
                              nil t)))))
 
+(ert-deftest package-test-signed ()
+  "Test verifying package signature."
+  (skip-unless (ignore-errors
+                (let ((homedir (make-temp-file "package-test" t)))
+                  (unwind-protect
+                      (let ((process-environment
+                             (cons (format "HOME=%s" homedir)
+                                   process-environment)))
+                        (epg-check-configuration (epg-configuration))
+                        t)
+                    (delete-directory homedir t)))))
+  (let* ((keyring (expand-file-name "key.pub" package-test-data-dir))
+        (package-test-data-dir
+          (expand-file-name "data/package/signed" package-test-file-dir)))
+    (with-package-test ()
+      (package-initialize)
+      (package-import-keyring keyring)
+      (package-refresh-contents)
+      (should (package-install 'signed-good))
+      (should-error (package-install 'signed-bad))
+      ;; Check if the installed package status is updated.
+      (let ((buf (package-list-packages)))
+       (package-menu-refresh)
+       (should (re-search-forward "^\\s-+signed-good\\s-+1\\.0\\s-+installed"
+                                  nil t)))
+      ;; Check if the package description is updated.
+      (with-fake-help-buffer
+       (describe-package 'signed-good)
+       (goto-char (point-min))
+       (should (search-forward "signed-good is an installed package." nil t))
+       (should (search-forward
+               (format "Status: Installed in `%s/'."
+                       (expand-file-name "signed-good-1.0" package-user-dir))
+               nil t))))))
+
 (provide 'package-test)
 
 ;;; package-test.el ends here