* configure.ac (EMACS_CHECK_MODULES): Fix typo in previous change.
[bpt/emacs.git] / test / automated / vc-bzr.el
1 ;;; vc-bzr.el --- tests for vc/vc-bzr.el
2
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
4
5 ;; Author: Glenn Morris <rgm@gnu.org>
6 ;; Maintainer: emacs-devel@gnu.org
7
8 ;; This file is part of GNU Emacs.
9
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.
14
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.
19
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/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (require 'ert)
28 (require 'vc-bzr)
29 (require 'vc-dir)
30
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
37 ;; some commands (eg `bzr status') want to access ~/.bazaar,
38 ;; and will abort if they cannot. I could not figure out how to
39 ;; stop bzr doing that, so just set HOME to a tempir for the duration.
40 (let* ((homedir (make-temp-file "vc-bzr-test" t))
41 (bzrdir (expand-file-name "bzr" homedir))
42 (ignored-dir (progn
43 (make-directory bzrdir)
44 (expand-file-name "ignored-dir" bzrdir)))
45 (default-directory (file-name-as-directory bzrdir))
46 (process-environment (cons (format "HOME=%s" homedir)
47 process-environment)))
48 (unwind-protect
49 (progn
50 (make-directory ignored-dir)
51 (with-temp-buffer
52 (insert (file-name-nondirectory ignored-dir))
53 (write-region nil nil (expand-file-name ".bzrignore" bzrdir)
54 nil 'silent))
55 (call-process vc-bzr-program nil nil nil "init")
56 (call-process vc-bzr-program nil nil nil "add")
57 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
58 (with-temp-buffer
59 (insert "unregistered file")
60 (write-region nil nil (expand-file-name "testfile2" ignored-dir)
61 nil 'silent))
62 (vc-dir ignored-dir)
63 (while (vc-dir-busy)
64 (sit-for 0.1))
65 ;; FIXME better to explicitly test for error from process sentinel.
66 (with-current-buffer "*vc-dir*"
67 (goto-char (point-min))
68 (should (search-forward "unregistered" nil t))))
69 (delete-directory homedir t))))
70
71 ;; Not specific to bzr.
72 (ert-deftest vc-bzr-test-bug9781 ()
73 "Test for http://debbugs.gnu.org/9781 ."
74 (skip-unless (executable-find vc-bzr-program))
75 (let* ((homedir (make-temp-file "vc-bzr-test" t))
76 (bzrdir (expand-file-name "bzr" homedir))
77 (subdir (progn
78 (make-directory bzrdir)
79 (expand-file-name "subdir" bzrdir)))
80 (file (expand-file-name "file" bzrdir))
81 (default-directory (file-name-as-directory bzrdir))
82 (process-environment (cons (format "HOME=%s" homedir)
83 process-environment)))
84 (unwind-protect
85 (progn
86 (call-process vc-bzr-program nil nil nil "init")
87 (make-directory subdir)
88 (with-temp-buffer
89 (insert "text")
90 (write-region nil nil file nil 'silent)
91 (write-region nil nil (expand-file-name "subfile" subdir)
92 nil 'silent))
93 (call-process vc-bzr-program nil nil nil "add")
94 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
95 (call-process vc-bzr-program nil nil nil "remove" subdir)
96 (with-temp-buffer
97 (insert "different text")
98 (write-region nil nil file nil 'silent))
99 (vc-dir bzrdir)
100 (while (vc-dir-busy)
101 (sit-for 0.1))
102 (vc-dir-mark-all-files t)
103 (let ((f (symbol-function 'y-or-n-p)))
104 (unwind-protect
105 (progn
106 (fset 'y-or-n-p (lambda (prompt) t))
107 (vc-next-action nil))
108 (fset 'y-or-n-p f)))
109 (should (get-buffer "*vc-log*")))
110 (delete-directory homedir t))))
111
112 ;; http://lists.gnu.org/archive/html/help-gnu-emacs/2012-04/msg00145.html
113 (ert-deftest vc-bzr-test-faulty-bzr-autoloads ()
114 "Test we can generate autoloads in a bzr directory when bzr is faulty."
115 (skip-unless (executable-find vc-bzr-program))
116 (let* ((homedir (make-temp-file "vc-bzr-test" t))
117 (bzrdir (expand-file-name "bzr" homedir))
118 (file (progn
119 (make-directory bzrdir)
120 (expand-file-name "foo.el" bzrdir)))
121 (default-directory (file-name-as-directory bzrdir))
122 (generated-autoload-file (expand-file-name "loaddefs.el" bzrdir))
123 (process-environment (cons (format "HOME=%s" homedir)
124 process-environment)))
125 (unwind-protect
126 (progn
127 (call-process vc-bzr-program nil nil nil "init")
128 (with-temp-buffer
129 (insert ";;;###autoload
130 \(defun foo () \"foo\" (interactive) (message \"foo!\"))")
131 (write-region nil nil file nil 'silent))
132 (call-process vc-bzr-program nil nil nil "add")
133 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
134 ;; Deleting dirstate ensures both that vc-bzr's status heuristic
135 ;; fails, so it has to call the external bzr status, and
136 ;; causes bzr status to fail. This simulates a broken bzr
137 ;; installation.
138 (delete-file ".bzr/checkout/dirstate")
139 (should (progn (update-directory-autoloads default-directory)
140 t)))
141 (delete-directory homedir t))))
142
143 ;;; vc-bzr.el ends here