]> git.eshelyaron.com Git - emacs.git/commitdiff
; Don't keep temporary buffers alive after a dired test
authorTino Calancha <tino.calancha@gmail.com>
Mon, 24 Jul 2017 02:58:35 +0000 (11:58 +0900)
committerTino Calancha <tino.calancha@gmail.com>
Mon, 24 Jul 2017 03:05:32 +0000 (12:05 +0900)
* test/lisp/dired-tests.el (dired-test-bug22694)
(dired-test-bug25609, dired-test-bug27243)
Delete all temporary dired buffers at the end.

test/lisp/dired-tests.el

index bd1816172e74af5f180e3f2d9106270a90723bb4..69331457c0ee9c9c9648ad024241879b26773d79 100644 (file)
          (file      "test")
          (full-name (expand-file-name file dir))
          (regexp    "bar")
-         (dired-always-read-filesystem t))
+         (dired-always-read-filesystem t) buffers)
     (if (file-exists-p dir)
         (delete-directory dir 'recursive))
     (make-directory dir)
     (with-temp-file full-name (insert "foo"))
-    (find-file-noselect full-name)
-    (dired dir)
+    (push (find-file-noselect full-name) buffers)
+    (push (dired dir) buffers)
     (with-temp-file full-name (insert "bar"))
     (dired-mark-files-containing-regexp regexp)
     (unwind-protect
         (should (equal (dired-get-marked-files nil nil nil 'distinguish-1-mark)
                        `(t ,full-name)))
       ;; Clean up
+      (dolist (buf buffers)
+        (when (buffer-live-p buf) (kill-buffer buf)))
       (delete-directory dir 'recursive))))
 
 (ert-deftest dired-test-bug25609 ()
@@ -60,7 +62,8 @@
          (target (expand-file-name (file-name-nondirectory from) to))
          (nested (expand-file-name (file-name-nondirectory from) target))
          (dired-dwim-target t)
-         (dired-recursive-copies 'always)) ; Don't prompt me.
+         (dired-recursive-copies 'always) ; Don't prompt me.
+         buffers)
     (advice-add 'dired-query ; Don't ask confirmation to overwrite a file.
                 :override
                 (lambda (_sym _prompt &rest _args) (setq dired-query t))
@@ -70,8 +73,8 @@
                 (lambda (_prompt _coll &optional _pred _match init _hist _def _inherit _keymap)
                   init)
                 '((name . "advice-completing-read")))
-    (dired to)
-    (dired-other-window temporary-file-directory)
+    (push (dired to) buffers)
+    (push (dired-other-window temporary-file-directory) buffers)
     (dired-goto-file from)
     (dired-do-copy)
     (dired-do-copy); Again.
@@ -79,6 +82,8 @@
         (progn
           (should (file-exists-p target))
           (should-not (file-exists-p nested)))
+      (dolist (buf buffers)
+        (when (buffer-live-p buf) (kill-buffer buf)))
       (delete-directory from 'recursive)
       (delete-directory to 'recursive)
       (advice-remove 'dired-query "advice-dired-query")
 (ert-deftest dired-test-bug27243 ()
   "Test for http://debbugs.gnu.org/27243 ."
   (let ((test-dir (make-temp-file "test-dir-" t))
-        (dired-auto-revert-buffer t))
+        (dired-auto-revert-buffer t) buffers)
     (with-current-buffer (find-file-noselect test-dir)
       (make-directory "test-subdir"))
-    (dired test-dir)
+    (push (dired test-dir) buffers)
     (unwind-protect
         (let ((buf (current-buffer))
               (pt1 (point))
           (should (equal (dired-file-name-at-point)
                          (concat (file-name-as-directory test-dir)
                                  (file-name-as-directory "test-subdir"))))
-          (dired-find-file)
+          (push (dired-find-file) buffers)
           (let ((pt2 (point)))          ; Point is on test-file.
             (switch-to-buffer buf)
             ;; Sanity check: point should now be back on the subdirectory.
             (should (eq (point) pt1))
             ;; Case 1: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#5
-            (dired-find-file)
+            (push (dired-find-file) buffers)
             (should (eq (point) pt2))
             ;; Case 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#28
-            (dired test-dir)
+            (push (dired test-dir) buffers)
             (should (eq (point) pt1))))
+      (dolist (buf buffers)
+        (when (buffer-live-p buf) (kill-buffer buf)))
       (delete-directory test-dir t))))
 
 (ert-deftest dired-test-bug27693 ()