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