aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-01-28 20:12:25 +0100
committerNoam Postavsky2018-02-01 20:15:11 -0500
commit00c65bcf4ee8ca4ce04ad46907de29c832b8310b (patch)
treed1652135f37bef801735bb5a959d0eb0777e3bcf
parent65da409e411a0cdfa1932d21ce8a7f87ceae9e25 (diff)
downloademacs-00c65bcf4ee8ca4ce04ad46907de29c832b8310b.tar.gz
emacs-00c65bcf4ee8ca4ce04ad46907de29c832b8310b.zip
Use file-name-quote{,d-p} in files-tests.el
* test/lisp/files-tests.el (files-tests-file-name-non-special-quote-unquote): New test. (files-tests--file-name-non-special--subprocess): Simplify. (files-tests--file-name-non-special--buffers) (files-tests--with-temp-non-special) (files-tests-file-name-non-special-directory-file-name) (files-tests-file-name-non-special-file-in-directory-p) (files-tests-file-name-non-special-file-name-all-completions) (files-tests-file-name-non-special-file-name-as-directory) (files-tests-file-name-non-special-file-name-completion) (files-tests-file-name-non-special-file-name-directory) (files-tests-file-name-non-special-find-backup-file-name) (files-tests-file-name-non-special-make-nearby-temp-file): Use `file-name-quote' and `file-name-quoted-p', respectively.
-rw-r--r--test/lisp/files-tests.el40
1 files changed, 25 insertions, 15 deletions
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index abd3155141b..a72f5754aa6 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -261,14 +261,22 @@ be $HOME."
261 (concat "/:/:" subdir))))) 261 (concat "/:/:" subdir)))))
262 (delete-directory dir 'recursive)))) 262 (delete-directory dir 'recursive))))
263 263
264(ert-deftest files-tests-file-name-non-special-quote-unquote ()
265 (let (;; Just in case it is quoted, who knows.
266 (temporary-file-directory (file-name-unquote temporary-file-directory)))
267 (should-not (file-name-quoted-p temporary-file-directory))
268 (should (file-name-quoted-p (file-name-quote temporary-file-directory)))
269 (should (equal temporary-file-directory
270 (file-name-unquote
271 (file-name-quote temporary-file-directory))))))
272
264(ert-deftest files-tests--file-name-non-special--subprocess () 273(ert-deftest files-tests--file-name-non-special--subprocess ()
265 "Check that Bug#25949 is fixed." 274 "Check that Bug#25949 is fixed."
266 (skip-unless (executable-find "true")) 275 (skip-unless (executable-find "true"))
267 (let ((defdir (if (memq system-type '(ms-dos windows-nt)) "/:c:/" "/:/"))) 276 (let ((default-directory (file-name-quote temporary-file-directory)))
268 (should (eq (let ((default-directory defdir)) (process-file "true")) 0)) 277 (should (zerop (process-file "true")))
269 (should (processp (let ((default-directory defdir)) 278 (should (processp (start-file-process "foo" nil "true")))
270 (start-file-process "foo" nil "true")))) 279 (should (zerop (shell-command "true")))))
271 (should (eq (let ((default-directory defdir)) (shell-command "true")) 0))))
272 280
273(defmacro files-tests--with-advice (symbol where function &rest body) 281(defmacro files-tests--with-advice (symbol where function &rest body)
274 (declare (indent 3)) 282 (declare (indent 3))
@@ -303,8 +311,10 @@ be invoked with the right arguments."
303 (let* ((buffer-visiting-file (current-buffer)) 311 (let* ((buffer-visiting-file (current-buffer))
304 (actual-args ()) 312 (actual-args ())
305 (log (lambda (&rest args) (push args actual-args)))) 313 (log (lambda (&rest args) (push args actual-args))))
306 (insert-file-contents (concat "/:" temp-file-name) :visit) 314 (insert-file-contents (file-name-quote temp-file-name) :visit)
307 (should (stringp buffer-file-name)) 315 (should (stringp buffer-file-name))
316 (should (file-name-quoted-p buffer-file-name))
317 ;; The following is not true for remote files.
308 (should (string-prefix-p "/:" buffer-file-name)) 318 (should (string-prefix-p "/:" buffer-file-name))
309 (should (consp (visited-file-modtime))) 319 (should (consp (visited-file-modtime)))
310 (should (equal (find-file-name-handler buffer-file-name 320 (should (equal (find-file-name-handler buffer-file-name
@@ -337,7 +347,7 @@ be invoked with the right arguments."
337 (cl-check-type name symbol) 347 (cl-check-type name symbol)
338 (cl-check-type non-special-name symbol) 348 (cl-check-type non-special-name symbol)
339 `(let* ((,name (make-temp-file "files-tests" ,dir-flag)) 349 `(let* ((,name (make-temp-file "files-tests" ,dir-flag))
340 (,non-special-name (concat "/:" ,name))) 350 (,non-special-name (file-name-quote ,name)))
341 (unwind-protect 351 (unwind-protect
342 (progn ,@body) 352 (progn ,@body)
343 (when (file-exists-p ,name) 353 (when (file-exists-p ,name)
@@ -394,7 +404,7 @@ be invoked with the right arguments."
394(ert-deftest files-tests-file-name-non-special-directory-file-name () 404(ert-deftest files-tests-file-name-non-special-directory-file-name ()
395 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 405 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
396 (should (equal (directory-file-name nospecial-dir) 406 (should (equal (directory-file-name nospecial-dir)
397 (concat "/:" (directory-file-name tmpdir)))))) 407 (file-name-quote (directory-file-name tmpdir))))))
398 408
399(ert-deftest files-tests-file-name-non-special-directory-files () 409(ert-deftest files-tests-file-name-non-special-directory-files ()
400 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 410 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
@@ -457,7 +467,7 @@ be invoked with the right arguments."
457 467
458(ert-deftest files-tests-file-name-non-special-file-in-directory-p () 468(ert-deftest files-tests-file-name-non-special-file-in-directory-p ()
459 (files-tests--with-temp-non-special (tmpfile nospecial) 469 (files-tests--with-temp-non-special (tmpfile nospecial)
460 (let ((nospecial-tempdir (concat "/:" temporary-file-directory))) 470 (let ((nospecial-tempdir (file-name-quote temporary-file-directory)))
461 (should (file-in-directory-p nospecial temporary-file-directory)) 471 (should (file-in-directory-p nospecial temporary-file-directory))
462 (should (file-in-directory-p tmpfile nospecial-tempdir)) 472 (should (file-in-directory-p tmpfile nospecial-tempdir))
463 (should (file-in-directory-p nospecial nospecial-tempdir))))) 473 (should (file-in-directory-p nospecial nospecial-tempdir)))))
@@ -472,7 +482,7 @@ be invoked with the right arguments."
472 482
473(ert-deftest files-tests-file-name-non-special-file-name-all-completions () 483(ert-deftest files-tests-file-name-non-special-file-name-all-completions ()
474 (files-tests--with-temp-non-special (tmpfile nospecial) 484 (files-tests--with-temp-non-special (tmpfile nospecial)
475 (let ((nospecial-tempdir (concat "/:" temporary-file-directory)) 485 (let ((nospecial-tempdir (file-name-quote temporary-file-directory))
476 (tmpdir temporary-file-directory)) 486 (tmpdir temporary-file-directory))
477 (should (equal (file-name-all-completions nospecial nospecial-tempdir) 487 (should (equal (file-name-all-completions nospecial nospecial-tempdir)
478 (file-name-all-completions tmpfile tmpdir))) 488 (file-name-all-completions tmpfile tmpdir)))
@@ -484,7 +494,7 @@ be invoked with the right arguments."
484(ert-deftest files-tests-file-name-non-special-file-name-as-directory () 494(ert-deftest files-tests-file-name-non-special-file-name-as-directory ()
485 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 495 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
486 (should (equal (file-name-as-directory nospecial-dir) 496 (should (equal (file-name-as-directory nospecial-dir)
487 (concat "/:" (file-name-as-directory tmpdir)))))) 497 (file-name-quote (file-name-as-directory tmpdir))))))
488 498
489(ert-deftest files-tests-file-name-non-special-file-name-case-insensitive-p () 499(ert-deftest files-tests-file-name-non-special-file-name-case-insensitive-p ()
490 (files-tests--with-temp-non-special (tmpfile nospecial) 500 (files-tests--with-temp-non-special (tmpfile nospecial)
@@ -493,7 +503,7 @@ be invoked with the right arguments."
493 503
494(ert-deftest files-tests-file-name-non-special-file-name-completion () 504(ert-deftest files-tests-file-name-non-special-file-name-completion ()
495 (files-tests--with-temp-non-special (tmpfile nospecial) 505 (files-tests--with-temp-non-special (tmpfile nospecial)
496 (let ((nospecial-tempdir (concat "/:" temporary-file-directory)) 506 (let ((nospecial-tempdir (file-name-quote temporary-file-directory))
497 (tmpdir temporary-file-directory)) 507 (tmpdir temporary-file-directory))
498 (should (equal (file-name-completion nospecial nospecial-tempdir) 508 (should (equal (file-name-completion nospecial nospecial-tempdir)
499 (file-name-completion tmpfile tmpdir))) 509 (file-name-completion tmpfile tmpdir)))
@@ -505,7 +515,7 @@ be invoked with the right arguments."
505(ert-deftest files-tests-file-name-non-special-file-name-directory () 515(ert-deftest files-tests-file-name-non-special-file-name-directory ()
506 (files-tests--with-temp-non-special (tmpfile nospecial) 516 (files-tests--with-temp-non-special (tmpfile nospecial)
507 (should (equal (file-name-directory nospecial) 517 (should (equal (file-name-directory nospecial)
508 (concat "/:" temporary-file-directory))))) 518 (file-name-quote temporary-file-directory)))))
509 519
510(ert-deftest files-tests-file-name-non-special-file-name-nondirectory () 520(ert-deftest files-tests-file-name-non-special-file-name-nondirectory ()
511 (files-tests--with-temp-non-special (tmpfile nospecial) 521 (files-tests--with-temp-non-special (tmpfile nospecial)
@@ -567,7 +577,7 @@ be invoked with the right arguments."
567(ert-deftest files-tests-file-name-non-special-find-backup-file-name () 577(ert-deftest files-tests-file-name-non-special-find-backup-file-name ()
568 (files-tests--with-temp-non-special (tmpfile nospecial) 578 (files-tests--with-temp-non-special (tmpfile nospecial)
569 (should (equal (find-backup-file-name nospecial) 579 (should (equal (find-backup-file-name nospecial)
570 (mapcar (lambda (f) (concat "/:" f)) 580 (mapcar #'file-name-quote
571 (find-backup-file-name tmpfile)))))) 581 (find-backup-file-name tmpfile))))))
572 582
573(ert-deftest files-tests-file-name-non-special-get-file-buffer () 583(ert-deftest files-tests-file-name-non-special-get-file-buffer ()
@@ -618,7 +628,7 @@ be invoked with the right arguments."
618 (delete-directory "dir")))) 628 (delete-directory "dir"))))
619 629
620(ert-deftest files-tests-file-name-non-special-make-nearby-temp-file () 630(ert-deftest files-tests-file-name-non-special-make-nearby-temp-file ()
621 (let* ((default-directory (concat "/:" temporary-file-directory)) 631 (let* ((default-directory (file-name-quote temporary-file-directory))
622 (near-tmpfile (make-nearby-temp-file "file"))) 632 (near-tmpfile (make-nearby-temp-file "file")))
623 (should (file-exists-p near-tmpfile)) 633 (should (file-exists-p near-tmpfile))
624 (delete-file near-tmpfile))) 634 (delete-file near-tmpfile)))