vc-bzr-tests.el 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ;;; vc-bzr.el --- tests for vc/vc-bzr.el
  2. ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
  3. ;; Author: Glenn Morris <rgm@gnu.org>
  4. ;; Maintainer: emacs-devel@gnu.org
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. (require 'ert)
  19. (require 'ert-x)
  20. (require 'vc-bzr)
  21. (require 'vc-dir)
  22. (ert-deftest vc-bzr-test-bug9726 ()
  23. "Test for http://debbugs.gnu.org/9726 ."
  24. (skip-unless (executable-find vc-bzr-program))
  25. ;; Bzr wants to access HOME, e.g. to write ~/.bzr.log.
  26. ;; This is a problem on hydra, where HOME is non-existent.
  27. ;; You can disable logging with BZR_LOG=/dev/null, but then some
  28. ;; commands (eg `bzr status') want to access ~/.bazaar, and will
  29. ;; abort if they cannot. I could not figure out how to stop bzr
  30. ;; doing that, so just give it a temporary homedir for the duration.
  31. ;; http://bugs.launchpad.net/bzr/+bug/137407 ?
  32. (let* ((homedir (make-temp-file "vc-bzr-test" t))
  33. (bzrdir (expand-file-name "bzr" homedir))
  34. (ignored-dir (progn
  35. (make-directory bzrdir)
  36. (expand-file-name "ignored-dir" bzrdir)))
  37. (default-directory (file-name-as-directory bzrdir))
  38. (process-environment (cons (format "BZR_HOME=%s" homedir)
  39. process-environment)))
  40. (unwind-protect
  41. (progn
  42. (make-directory ignored-dir)
  43. (with-temp-buffer
  44. (insert (file-name-nondirectory ignored-dir))
  45. (write-region nil nil (expand-file-name ".bzrignore" bzrdir)
  46. nil 'silent))
  47. (call-process vc-bzr-program nil nil nil "init")
  48. (call-process vc-bzr-program nil nil nil "add")
  49. (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
  50. (with-temp-buffer
  51. (insert "unregistered file")
  52. (write-region nil nil (expand-file-name "testfile2" ignored-dir)
  53. nil 'silent))
  54. (vc-dir ignored-dir)
  55. (while (vc-dir-busy)
  56. (sit-for 0.1))
  57. ;; FIXME better to explicitly test for error from process sentinel.
  58. (with-current-buffer "*vc-dir*"
  59. (goto-char (point-min))
  60. (should (search-forward "unregistered" nil t))))
  61. (delete-directory homedir t))))
  62. ;; Not specific to bzr.
  63. (ert-deftest vc-bzr-test-bug9781 ()
  64. "Test for http://debbugs.gnu.org/9781 ."
  65. (skip-unless (executable-find vc-bzr-program))
  66. (let* ((homedir (make-temp-file "vc-bzr-test" t))
  67. (bzrdir (expand-file-name "bzr" homedir))
  68. (subdir (progn
  69. (make-directory bzrdir)
  70. (expand-file-name "subdir" bzrdir)))
  71. (file (expand-file-name "file" bzrdir))
  72. (default-directory (file-name-as-directory bzrdir))
  73. (process-environment (cons (format "BZR_HOME=%s" homedir)
  74. process-environment)))
  75. (unwind-protect
  76. (progn
  77. (call-process vc-bzr-program nil nil nil "init")
  78. (make-directory subdir)
  79. (with-temp-buffer
  80. (insert "text")
  81. (write-region nil nil file nil 'silent)
  82. (write-region nil nil (expand-file-name "subfile" subdir)
  83. nil 'silent))
  84. (call-process vc-bzr-program nil nil nil "add")
  85. (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
  86. (call-process vc-bzr-program nil nil nil "remove" subdir)
  87. (with-temp-buffer
  88. (insert "different text")
  89. (write-region nil nil file nil 'silent))
  90. (vc-dir bzrdir)
  91. (while (vc-dir-busy)
  92. (sit-for 0.1))
  93. (vc-dir-mark-all-files t)
  94. (ert-with-function-mocked y-or-n-p (lambda (_) t)
  95. (vc-next-action nil))
  96. (should (get-buffer "*vc-log*")))
  97. (delete-directory homedir t))))
  98. ;; http://lists.gnu.org/archive/html/help-gnu-emacs/2012-04/msg00145.html
  99. (ert-deftest vc-bzr-test-faulty-bzr-autoloads ()
  100. "Test we can generate autoloads in a bzr directory when bzr is faulty."
  101. (skip-unless (executable-find vc-bzr-program))
  102. (let* ((homedir (make-temp-file "vc-bzr-test" t))
  103. (bzrdir (expand-file-name "bzr" homedir))
  104. (file (progn
  105. (make-directory bzrdir)
  106. (expand-file-name "foo.el" bzrdir)))
  107. (default-directory (file-name-as-directory bzrdir))
  108. (generated-autoload-file (expand-file-name "loaddefs.el" bzrdir))
  109. (process-environment (cons (format "BZR_HOME=%s" homedir)
  110. process-environment)))
  111. (unwind-protect
  112. (progn
  113. (call-process vc-bzr-program nil nil nil "init")
  114. (with-temp-buffer
  115. (insert ";;;###autoload
  116. \(defun foo () \"foo\" (interactive) (message \"foo!\"))")
  117. (write-region nil nil file nil 'silent))
  118. (call-process vc-bzr-program nil nil nil "add")
  119. (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
  120. ;; Deleting dirstate ensures both that vc-bzr's status heuristic
  121. ;; fails, so it has to call the external bzr status, and
  122. ;; causes bzr status to fail. This simulates a broken bzr
  123. ;; installation.
  124. (delete-file ".bzr/checkout/dirstate")
  125. (should (progn (update-directory-autoloads default-directory)
  126. t)))
  127. (delete-directory homedir t))))
  128. ;;; vc-bzr.el ends here