Remove call to string-to-multibyte from nndoc.el
[emacs.git] / test / lisp / dired-aux-tests.el
blobdaf60f760e03706a671a99c953205faeb726b9b6
1 ;;; dired-aux-tests.el --- Test suite for dired-aux. -*- lexical-binding: t -*-
3 ;; Copyright (C) 2017-2018 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20 ;;; Code:
21 (require 'ert)
22 (require 'dired-aux)
23 (eval-when-compile (require 'cl-lib))
25 (ert-deftest dired-test-bug27496 ()
26 "Test for https://debbugs.gnu.org/27496 ."
27 (skip-unless (executable-find shell-file-name))
28 (let* ((foo (make-temp-file "foo"))
29 (files (list foo)))
30 (unwind-protect
31 (cl-letf (((symbol-function 'y-or-n-p) 'error))
32 (dired temporary-file-directory)
33 (dired-goto-file foo)
34 ;; `dired-do-shell-command' returns nil on success.
35 (should-error (dired-do-shell-command "ls ? ./?" nil files))
36 (should-error (dired-do-shell-command "ls ./? ?" nil files))
37 (should-not (dired-do-shell-command "ls ? ?" nil files))
38 (should-error (dired-do-shell-command "ls * ./*" nil files))
39 (should-not (dired-do-shell-command "ls * *" nil files))
40 (should-not (dired-do-shell-command "ls ? ./`?`" nil files)))
41 (delete-file foo))))
43 ;; Auxiliar macro for `dired-test-bug28834': it binds
44 ;; `dired-create-destination-dirs' to CREATE-DIRS and execute BODY.
45 ;; If YES-OR-NO is non-nil, it binds `yes-or-no-p' to
46 ;; to avoid the prompt.
47 (defmacro with-dired-bug28834-test (create-dirs yes-or-no &rest body)
48 (declare (debug (form symbolp body)))
49 (let ((foo (make-symbol "foo")))
50 `(let* ((,foo (make-temp-file "foo" 'dir))
51 (dired-create-destination-dirs ,create-dirs))
52 (setq from (make-temp-file "from"))
53 (setq to-cp
54 (expand-file-name
55 "foo-cp" (file-name-as-directory (expand-file-name "bar" ,foo))))
56 (setq to-mv
57 (expand-file-name
58 "foo-mv" (file-name-as-directory (expand-file-name "qux" ,foo))))
59 (unwind-protect
60 (if ,yes-or-no
61 (cl-letf (((symbol-function 'yes-or-no-p)
62 (lambda (_prompt) (eq ,yes-or-no 'yes))))
63 ,@body)
64 ,@body)
65 ;; clean up
66 (delete-directory ,foo 'recursive)
67 (delete-file from)))))
69 (ert-deftest dired-test-bug28834 ()
70 "test for https://debbugs.gnu.org/28834 ."
71 (let (from to-cp to-mv)
72 ;; `dired-create-destination-dirs' set to 'always.
73 (with-dired-bug28834-test
74 'always nil
75 (dired-copy-file-recursive from to-cp nil)
76 (should (file-exists-p to-cp))
77 (dired-rename-file from to-mv nil)
78 (should (file-exists-p to-mv)))
79 ;; `dired-create-destination-dirs' set to nil.
80 (with-dired-bug28834-test
81 nil nil
82 (should-error (dired-copy-file-recursive from to-cp nil))
83 (should-error (dired-rename-file from to-mv nil)))
84 ;; `dired-create-destination-dirs' set to 'ask.
85 (with-dired-bug28834-test
86 'ask 'yes ; Answer `yes'
87 (dired-copy-file-recursive from to-cp nil)
88 (should (file-exists-p to-cp))
89 (dired-rename-file from to-mv nil)
90 (should (file-exists-p to-mv)))
91 (with-dired-bug28834-test
92 'ask 'no ; Answer `no'
93 (should-error (dired-copy-file-recursive from to-cp nil))
94 (should-error (dired-rename-file from to-mv nil)))))
96 (ert-deftest dired-test-bug30624 ()
97 "test for https://debbugs.gnu.org/30624 ."
98 (cl-letf* ((target-dir (make-temp-file "target" 'dir))
99 ((symbol-function 'dired-mark-read-file-name)
100 (lambda (&rest _) target-dir))
101 (inhibit-message t))
102 ;; Delete target-dir: `dired-do-create-files' must recreate it.
103 (delete-directory target-dir)
104 (let ((file1 (make-temp-file "bug30624_file1"))
105 (file2 (make-temp-file "bug30624_file2"))
106 (dired-create-destination-dirs 'always)
107 (buf (dired temporary-file-directory)))
108 (unwind-protect
109 (progn
110 (dired-revert)
111 (dired-mark-files-regexp "bug30624_file")
112 (should (dired-do-create-files 'copy 'dired-copy-file "Copy" nil)))
113 (delete-directory target-dir 'recursive)
114 (mapc #'delete-file `(,file1 ,file2))
115 (kill-buffer buf)))))
118 (provide 'dired-aux-tests)
119 ;; dired-aux-tests.el ends here