94f8502b88298a52cee0bc05eb73cc9a836c9437
[bpt/emacs.git] / test / automated / vc-bzr.el
1 ;;; vc-bzr.el --- tests for vc/vc-bzr.el
2
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
4
5 ;; Author: Glenn Morris <rgm@gnu.org>
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24 ;;; Code:
25
26 (require 'ert)
27 (require 'vc-bzr)
28 (require 'vc-dir)
29
30 ;; FIXME it would be better to skip all these tests if there is no
31 ;; bzr installed. We could just put everything inside an IF
32 ;; statement, but it would be nice if ERT had a "skipped" facility (?).
33
34 (ert-deftest vc-bzr-test-bug9726 ()
35 "Test for http://debbugs.gnu.org/9726 ."
36 :expected-result (if (executable-find vc-bzr-program) :passed :failed)
37 (should (executable-find vc-bzr-program))
38 (let* ((tempdir (make-temp-file "vc-bzr-test" t))
39 (ignored-dir (expand-file-name "ignored-dir" tempdir))
40 (default-directory (file-name-as-directory tempdir)))
41 (unwind-protect
42 (progn
43 (make-directory ignored-dir)
44 (with-temp-buffer
45 (insert (file-name-nondirectory ignored-dir))
46 (write-region nil nil (expand-file-name ".bzrignore" tempdir)
47 nil 'silent))
48 (call-process vc-bzr-program nil nil nil "init")
49 (call-process vc-bzr-program nil nil nil "add")
50 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
51 (with-temp-buffer
52 (insert "unregistered file")
53 (write-region nil nil (expand-file-name "testfile2" ignored-dir)
54 nil 'silent))
55 (vc-dir ignored-dir)
56 (while (vc-dir-busy)
57 (sit-for 0.1))
58 ;; FIXME better to explicitly test for error from process sentinel.
59 (with-current-buffer "*vc-dir*"
60 (goto-char (point-min))
61 (should (search-forward "unregistered" nil t))))
62 (delete-directory tempdir t))))
63
64 ;; Not specific to bzr.
65 (ert-deftest vc-bzr-test-bug9781 ()
66 "Test for http://debbugs.gnu.org/9781 ."
67 :expected-result (if (executable-find vc-bzr-program) :passed :failed)
68 (should (executable-find vc-bzr-program))
69 (let* ((tempdir (make-temp-file "vc-bzr-test" t))
70 (subdir (expand-file-name "subdir" tempdir))
71 (file (expand-file-name "file" tempdir))
72 (default-directory (file-name-as-directory tempdir)))
73 (unwind-protect
74 (progn
75 (call-process vc-bzr-program nil nil nil "init")
76 (make-directory subdir)
77 (with-temp-buffer
78 (insert "text")
79 (write-region nil nil file nil 'silent)
80 (write-region nil nil (expand-file-name "subfile" subdir)
81 nil 'silent))
82 (call-process vc-bzr-program nil nil nil "add")
83 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
84 (call-process vc-bzr-program nil nil nil "remove" subdir)
85 (with-temp-buffer
86 (insert "different text")
87 (write-region nil nil file nil 'silent))
88 (vc-dir tempdir)
89 (while (vc-dir-busy)
90 (sit-for 0.1))
91 (vc-dir-mark-all-files t)
92 (let ((f (symbol-function 'y-or-n-p)))
93 (unwind-protect
94 (progn
95 (fset 'y-or-n-p (lambda (prompt) t))
96 (vc-next-action nil))
97 (fset 'y-or-n-p f)))
98 (should (get-buffer "*vc-log*")))
99 (delete-directory tempdir t))))
100
101 ;; http://lists.gnu.org/archive/html/help-gnu-emacs/2012-04/msg00145.html
102 (ert-deftest vc-bzr-test-faulty-bzr-autoloads ()
103 "Test we can generate autoloads in a bzr directory when bzr is faulty."
104 :expected-result (if (executable-find vc-bzr-program) :passed :failed)
105 (should (executable-find vc-bzr-program))
106 (let* ((tempdir (make-temp-file "vc-bzr-test" t))
107 (file (expand-file-name "foo.el" tempdir))
108 (default-directory (file-name-as-directory tempdir))
109 (generated-autoload-file (expand-file-name "loaddefs.el" tempdir)))
110 (unwind-protect
111 (progn
112 (call-process vc-bzr-program nil nil nil "init")
113 (with-temp-buffer
114 (insert ";;;###autoload
115 \(defun foo () \"foo\" (interactive) (message \"foo!\"))")
116 (write-region nil nil file nil 'silent))
117 (call-process vc-bzr-program nil nil nil "add")
118 (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
119 ;; Deleting dirstate ensures both that vc-bzr's status heuristic
120 ;; fails, so it has to call the external bzr status, and
121 ;; causes bzr status to fail. This simulates a broken bzr
122 ;; installation.
123 (delete-file ".bzr/checkout/dirstate")
124 (should (progn (update-directory-autoloads default-directory)
125 t)))
126 (delete-directory tempdir t))))
127
128 ;;; vc-bzr.el ends here