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/>.
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"))
31 (cl-letf (((symbol-function 'y-or-n-p
) 'error
))
32 (dired temporary-file-directory
)
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
)))
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"))
55 "foo-cp" (file-name-as-directory (expand-file-name "bar" ,foo
))))
58 "foo-mv" (file-name-as-directory (expand-file-name "qux" ,foo
))))
61 (cl-letf (((symbol-function 'yes-or-no-p
)
62 (lambda (_prompt) (eq ,yes-or-no
'yes
))))
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
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
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
)))))
97 (provide 'dired-aux-tests
)
98 ;; dired-aux-tests.el ends here