]> code.delx.au - gnu-emacs/blob - test/lisp/vc/vc-bzr-tests.el
; Merge from origin/emacs-25
[gnu-emacs] / test / lisp / vc / vc-bzr-tests.el
1 ;;; vc-bzr.el --- tests for vc/vc-bzr.el
2
3 ;; Copyright (C) 2011-2016 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 'ert-x)
29 (require 'vc-bzr)
30 (require 'vc-dir)
31
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))
44 (ignored-dir (progn
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)))
50 (unwind-protect
51 (progn
52 (make-directory ignored-dir)
53 (with-temp-buffer
54 (insert (file-name-nondirectory ignored-dir))
55 (write-region nil nil (expand-file-name ".bzrignore" bzrdir)
56 nil 'silent))
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")
60 (with-temp-buffer
61 (insert "unregistered file")
62 (write-region nil nil (expand-file-name "testfile2" ignored-dir)
63 nil 'silent))
64 (vc-dir ignored-dir)
65 (while (vc-dir-busy)
66 (sit-for 0.1))
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))))
72
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))
79 (subdir (progn
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)))
86 (unwind-protect
87 (progn
88 (call-process vc-bzr-program nil nil nil "init")
89 (make-directory subdir)
90 (with-temp-buffer
91 (insert "text")
92 (write-region nil nil file nil 'silent)
93 (write-region nil nil (expand-file-name "subfile" subdir)
94 nil 'silent))
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)
98 (with-temp-buffer
99 (insert "different text")
100 (write-region nil nil file nil 'silent))
101 (vc-dir bzrdir)
102 (while (vc-dir-busy)
103 (sit-for 0.1))
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))))
109
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))
116 (file (progn
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)))
123 (unwind-protect
124 (progn
125 (call-process vc-bzr-program nil nil nil "init")
126 (with-temp-buffer
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
135 ;; installation.
136 (delete-file ".bzr/checkout/dirstate")
137 (should (progn (update-directory-autoloads default-directory)
138 t)))
139 (delete-directory homedir t))))
140
141 ;;; vc-bzr.el ends here