;;; vc-bzr.el --- tests for vc/vc-bzr.el
-;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
+;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
;; Author: Glenn Morris <rgm@gnu.org>
+;; Maintainer: emacs-devel@gnu.org
;; This file is part of GNU Emacs.
(require 'vc-bzr)
(require 'vc-dir)
-;; FIXME it would be better to skip all these tests if there is no
-;; bzr installed. We could just put everything inside an IF
-;; statement, but it would be nice if ERT had a "skipped" facility (?).
-
(ert-deftest vc-bzr-test-bug9726 ()
"Test for http://debbugs.gnu.org/9726 ."
- :expected-result (if (executable-find vc-bzr-program) :passed :failed)
- (should (executable-find vc-bzr-program))
- (let* ((tempdir (make-temp-file "vc-bzr-test" t))
- (ignored-dir (expand-file-name "ignored-dir" tempdir))
- (default-directory (file-name-as-directory tempdir)))
+ (skip-unless (executable-find vc-bzr-program))
+ ;; Bzr wants to access HOME, e.g. to write ~/.bzr.log.
+ ;; This is a problem on hydra, where HOME is non-existent.
+ ;; You can disable logging with BZR_LOG=/dev/null, but then some
+ ;; commands (eg `bzr status') want to access ~/.bazaar, and will
+ ;; abort if they cannot. I could not figure out how to stop bzr
+ ;; doing that, so just give it a temporary homedir for the duration.
+ ;; http://bugs.launchpad.net/bzr/+bug/137407 ?
+ (let* ((homedir (make-temp-file "vc-bzr-test" t))
+ (bzrdir (expand-file-name "bzr" homedir))
+ (ignored-dir (progn
+ (make-directory bzrdir)
+ (expand-file-name "ignored-dir" bzrdir)))
+ (default-directory (file-name-as-directory bzrdir))
+ (process-environment (cons (format "BZR_HOME=%s" homedir)
+ process-environment)))
(unwind-protect
(progn
(make-directory ignored-dir)
(with-temp-buffer
(insert (file-name-nondirectory ignored-dir))
- (write-region nil nil (expand-file-name ".bzrignore" tempdir)
+ (write-region nil nil (expand-file-name ".bzrignore" bzrdir)
nil 'silent))
(call-process vc-bzr-program nil nil nil "init")
(call-process vc-bzr-program nil nil nil "add")
(with-current-buffer "*vc-dir*"
(goto-char (point-min))
(should (search-forward "unregistered" nil t))))
- (delete-directory tempdir t))))
+ (delete-directory homedir t))))
;; Not specific to bzr.
(ert-deftest vc-bzr-test-bug9781 ()
"Test for http://debbugs.gnu.org/9781 ."
- :expected-result (if (executable-find vc-bzr-program) :passed :failed)
- (should (executable-find vc-bzr-program))
- (let* ((tempdir (make-temp-file "vc-bzr-test" t))
- (subdir (expand-file-name "subdir" tempdir))
- (file (expand-file-name "file" tempdir))
- (default-directory (file-name-as-directory tempdir)))
+ (skip-unless (executable-find vc-bzr-program))
+ (let* ((homedir (make-temp-file "vc-bzr-test" t))
+ (bzrdir (expand-file-name "bzr" homedir))
+ (subdir (progn
+ (make-directory bzrdir)
+ (expand-file-name "subdir" bzrdir)))
+ (file (expand-file-name "file" bzrdir))
+ (default-directory (file-name-as-directory bzrdir))
+ (process-environment (cons (format "BZR_HOME=%s" homedir)
+ process-environment)))
(unwind-protect
(progn
(call-process vc-bzr-program nil nil nil "init")
(with-temp-buffer
(insert "different text")
(write-region nil nil file nil 'silent))
- (vc-dir tempdir)
+ (vc-dir bzrdir)
(while (vc-dir-busy)
(sit-for 0.1))
(vc-dir-mark-all-files t)
(vc-next-action nil))
(fset 'y-or-n-p f)))
(should (get-buffer "*vc-log*")))
- (delete-directory tempdir t))))
+ (delete-directory homedir t))))
+
+;; http://lists.gnu.org/archive/html/help-gnu-emacs/2012-04/msg00145.html
+(ert-deftest vc-bzr-test-faulty-bzr-autoloads ()
+ "Test we can generate autoloads in a bzr directory when bzr is faulty."
+ (skip-unless (executable-find vc-bzr-program))
+ (let* ((homedir (make-temp-file "vc-bzr-test" t))
+ (bzrdir (expand-file-name "bzr" homedir))
+ (file (progn
+ (make-directory bzrdir)
+ (expand-file-name "foo.el" bzrdir)))
+ (default-directory (file-name-as-directory bzrdir))
+ (generated-autoload-file (expand-file-name "loaddefs.el" bzrdir))
+ (process-environment (cons (format "BZR_HOME=%s" homedir)
+ process-environment)))
+ (unwind-protect
+ (progn
+ (call-process vc-bzr-program nil nil nil "init")
+ (with-temp-buffer
+ (insert ";;;###autoload
+\(defun foo () \"foo\" (interactive) (message \"foo!\"))")
+ (write-region nil nil file nil 'silent))
+ (call-process vc-bzr-program nil nil nil "add")
+ (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
+ ;; Deleting dirstate ensures both that vc-bzr's status heuristic
+ ;; fails, so it has to call the external bzr status, and
+ ;; causes bzr status to fail. This simulates a broken bzr
+ ;; installation.
+ (delete-file ".bzr/checkout/dirstate")
+ (should (progn (update-directory-autoloads default-directory)
+ t)))
+ (delete-directory homedir t))))
;;; vc-bzr.el ends here