vc-bzr-tests.el 6.24 KB
Newer Older
1 2
;;; vc-bzr.el --- tests for vc/vc-bzr.el

Paul Eggert's avatar
Paul Eggert committed
3
;; Copyright (C) 2011-2018 Free Software Foundation, Inc.
4 5

;; Author: Glenn Morris <rgm@gnu.org>
6
;; Maintainer: emacs-devel@gnu.org
7 8 9 10 11 12 13 14 15 16 17 18 19 20

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
21
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
22 23 24 25 26 27 28 29 30 31

;;; Commentary:

;;; Code:

(require 'ert)
(require 'vc-bzr)
(require 'vc-dir)

(ert-deftest vc-bzr-test-bug9726 ()
32
  "Test for https://debbugs.gnu.org/9726 ."
33
  (skip-unless (executable-find vc-bzr-program))
34 35
  ;; Bzr wants to access HOME, e.g. to write ~/.bzr.log.
  ;; This is a problem on hydra, where HOME is non-existent.
36 37 38 39 40
  ;; You can disable logging with BZR_LOG=/dev/null, but then some
  ;; commands (eg `bzr status') want to access ~/.bazaar, and will
  ;; abort if they cannot.  I could not figure out how to stop bzr
  ;; doing that, so just give it a temporary homedir for the duration.
  ;; http://bugs.launchpad.net/bzr/+bug/137407 ?
41 42 43 44 45 46
  (let* ((homedir (make-temp-file "vc-bzr-test" t))
         (bzrdir (expand-file-name "bzr" homedir))
         (ignored-dir (progn
                        (make-directory bzrdir)
                        (expand-file-name "ignored-dir" bzrdir)))
         (default-directory (file-name-as-directory bzrdir))
47
         (process-environment (cons (format "BZR_HOME=%s" homedir)
48
                                    process-environment)))
49 50 51 52 53
    (unwind-protect
        (progn
          (make-directory ignored-dir)
          (with-temp-buffer
            (insert (file-name-nondirectory ignored-dir))
54
            (write-region nil nil (expand-file-name ".bzrignore" bzrdir)
55
                          nil 'silent))
Glenn Morris's avatar
Glenn Morris committed
56 57
          (skip-unless (eq 0            ; some internal bzr error
                           (call-process vc-bzr-program nil nil nil "init")))
58 59 60 61 62 63 64 65 66 67 68 69 70
          (call-process vc-bzr-program nil nil nil "add")
          (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
          (with-temp-buffer
            (insert "unregistered file")
            (write-region nil nil (expand-file-name "testfile2" ignored-dir)
                          nil 'silent))
          (vc-dir ignored-dir)
          (while (vc-dir-busy)
            (sit-for 0.1))
          ;; FIXME better to explicitly test for error from process sentinel.
          (with-current-buffer "*vc-dir*"
            (goto-char (point-min))
            (should (search-forward "unregistered" nil t))))
71
      (delete-directory homedir t))))
72

73 74
;; Not specific to bzr.
(ert-deftest vc-bzr-test-bug9781 ()
75
  "Test for https://debbugs.gnu.org/9781 ."
76
  (skip-unless (executable-find vc-bzr-program))
77 78 79 80 81 82 83
  (let* ((homedir (make-temp-file "vc-bzr-test" t))
         (bzrdir (expand-file-name "bzr" homedir))
         (subdir (progn
                   (make-directory bzrdir)
                   (expand-file-name "subdir" bzrdir)))
         (file (expand-file-name "file" bzrdir))
         (default-directory (file-name-as-directory bzrdir))
84
         (process-environment (cons (format "BZR_HOME=%s" homedir)
85
                                    process-environment)))
86 87
    (unwind-protect
        (progn
Glenn Morris's avatar
Glenn Morris committed
88 89
          (skip-unless (eq 0            ; some internal bzr error
                           (call-process vc-bzr-program nil nil nil "init")))
90 91 92 93 94 95 96 97 98 99 100 101
          (make-directory subdir)
          (with-temp-buffer
            (insert "text")
            (write-region nil nil file nil 'silent)
            (write-region nil nil (expand-file-name "subfile" subdir)
                          nil 'silent))
          (call-process vc-bzr-program nil nil nil "add")
          (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
          (call-process vc-bzr-program nil nil nil "remove" subdir)
          (with-temp-buffer
            (insert "different text")
            (write-region nil nil file nil 'silent))
102
          (vc-dir bzrdir)
103 104 105
          (while (vc-dir-busy)
            (sit-for 0.1))
          (vc-dir-mark-all-files t)
106
          (cl-letf (((symbol-function 'y-or-n-p) (lambda (_) t)))
107
            (vc-next-action nil))
108
          (should (get-buffer "*vc-log*")))
109
      (delete-directory homedir t))))
110

111
;; https://lists.gnu.org/r/help-gnu-emacs/2012-04/msg00145.html
Glenn Morris's avatar
Glenn Morris committed
112 113
(ert-deftest vc-bzr-test-faulty-bzr-autoloads ()
  "Test we can generate autoloads in a bzr directory when bzr is faulty."
114
  (skip-unless (executable-find vc-bzr-program))
115 116 117
  ;; Avoid vc-mode-line bug;
  ;; http://lists.gnu.org/r/emacs-devel/2018-12/msg00368.html
  (skip-unless (not (eq 0 (user-real-uid))))
118 119 120 121 122 123 124
  (let* ((homedir (make-temp-file "vc-bzr-test" t))
         (bzrdir (expand-file-name "bzr" homedir))
         (file (progn
                 (make-directory bzrdir)
                 (expand-file-name "foo.el" bzrdir)))
         (default-directory (file-name-as-directory bzrdir))
         (generated-autoload-file (expand-file-name "loaddefs.el" bzrdir))
125
         (process-environment (cons (format "BZR_HOME=%s" homedir)
126
                                    process-environment)))
Glenn Morris's avatar
Glenn Morris committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    (unwind-protect
        (progn
          (call-process vc-bzr-program nil nil nil "init")
          (with-temp-buffer
            (insert ";;;###autoload
\(defun foo () \"foo\" (interactive) (message \"foo!\"))")
            (write-region nil nil file nil 'silent))
          (call-process vc-bzr-program nil nil nil "add")
          (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
          ;; Deleting dirstate ensures both that vc-bzr's status heuristic
          ;; fails, so it has to call the external bzr status, and
          ;; causes bzr status to fail.  This simulates a broken bzr
          ;; installation.
          (delete-file ".bzr/checkout/dirstate")
          (should (progn (update-directory-autoloads default-directory)
                         t)))
143
      (delete-directory homedir t))))
Glenn Morris's avatar
Glenn Morris committed
144

145
;;; vc-bzr.el ends here