1 ;;; vc-bzr.el --- tests for vc/vc-bzr.el
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 ;; Author: Glenn Morris <rgm@gnu.org>
6 ;; Maintainer: emacs-devel@gnu.org
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/>.
31 (ert-deftest vc-bzr-test-bug9726 ()
32 "Test for http://debbugs.gnu.org/9726 ."
33 (skip-unless (executable-find vc-bzr-program))
34 ;; Bzr wants to access HOME, e.g. to write ~/.bzr.log.
35 ;; This is a problem on hydra, where HOME is non-existent.
36 ;; You can disable logging with BZR_LOG=/dev/null, but then some
37 ;; commands (eg `bzr status') want to access ~/.bazaar, and will
38 ;; abort if they cannot. I could not figure out how to stop bzr
39 ;; doing that, so just give it a temporary homedir for the duration.
40 ;; http://bugs.launchpad.net/bzr/+bug/137407 ?
41 (let* ((homedir (make-temp-file "vc-bzr-test" t))
42 (bzrdir (expand-file-name "bzr" homedir))
44 (make-directory bzrdir)
45 (expand-file-name "ignored-dir" bzrdir)))
46 (default-directory (file-name-as-directory bzrdir))
47 (process-environment (cons (format "BZR_HOME=%s" homedir)
48 process-environment)))
51 (make-directory ignored-dir)
53 (insert (file-name-nondirectory ignored-dir))
54 (write-region nil nil (expand-file-name ".bzrignore" bzrdir)
56 (call-process vc-bzr-program nil nil nil "init")
57 (call-process vc-bzr-program nil nil nil "add")
58 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
60 (insert "unregistered file")
61 (write-region nil nil (expand-file-name "testfile2" ignored-dir)
66 ;; FIXME better to explicitly test for error from process sentinel.
67 (with-current-buffer "*vc-dir*"
68 (goto-char (point-min))
69 (should (search-forward "unregistered" nil t))))
70 (delete-directory homedir t))))
72 ;; Not specific to bzr.
73 (ert-deftest vc-bzr-test-bug9781 ()
74 "Test for http://debbugs.gnu.org/9781 ."
75 (skip-unless (executable-find vc-bzr-program))
76 (let* ((homedir (make-temp-file "vc-bzr-test" t))
77 (bzrdir (expand-file-name "bzr" homedir))
79 (make-directory bzrdir)
80 (expand-file-name "subdir" bzrdir)))
81 (file (expand-file-name "file" bzrdir))
82 (default-directory (file-name-as-directory bzrdir))
83 (process-environment (cons (format "BZR_HOME=%s" homedir)
84 process-environment)))
87 (call-process vc-bzr-program nil nil nil "init")
88 (make-directory subdir)
91 (write-region nil nil file nil 'silent)
92 (write-region nil nil (expand-file-name "subfile" subdir)
94 (call-process vc-bzr-program nil nil nil "add")
95 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
96 (call-process vc-bzr-program nil nil nil "remove" subdir)
98 (insert "different text")
99 (write-region nil nil file nil 'silent))
103 (vc-dir-mark-all-files t)
104 (cl-letf (((symbol-function 'y-or-n-p) (lambda (_) t)))
105 (vc-next-action nil))
106 (should (get-buffer "*vc-log*")))
107 (delete-directory homedir t))))
109 ;; http://lists.gnu.org/archive/html/help-gnu-emacs/2012-04/msg00145.html
110 (ert-deftest vc-bzr-test-faulty-bzr-autoloads ()
111 "Test we can generate autoloads in a bzr directory when bzr is faulty."
112 (skip-unless (executable-find vc-bzr-program))
113 (let* ((homedir (make-temp-file "vc-bzr-test" t))
114 (bzrdir (expand-file-name "bzr" homedir))
116 (make-directory bzrdir)
117 (expand-file-name "foo.el" bzrdir)))
118 (default-directory (file-name-as-directory bzrdir))
119 (generated-autoload-file (expand-file-name "loaddefs.el" bzrdir))
120 (process-environment (cons (format "BZR_HOME=%s" homedir)
121 process-environment)))
124 (call-process vc-bzr-program nil nil nil "init")
126 (insert ";;;###autoload
127 \(defun foo () \"foo\" (interactive) (message \"foo!\"))")
128 (write-region nil nil file nil 'silent))
129 (call-process vc-bzr-program nil nil nil "add")
130 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
131 ;; Deleting dirstate ensures both that vc-bzr's status heuristic
132 ;; fails, so it has to call the external bzr status, and
133 ;; causes bzr status to fail. This simulates a broken bzr
135 (delete-file ".bzr/checkout/dirstate")
136 (should (progn (update-directory-autoloads default-directory)
138 (delete-directory homedir t))))
140 ;;; vc-bzr.el ends here