aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2018-06-03 14:30:41 +0200
committerMichael Albinus2018-06-03 14:30:41 +0200
commite75c57f10ee9418599398361b0676f48d265fb12 (patch)
treef4ec1a51cbbb4d4bc8f2360f23877b1b85bc11b4 /test
parentcb8b5f860cc11f8738796ced20e16763a6ff4123 (diff)
downloademacs-e75c57f10ee9418599398361b0676f48d265fb12.tar.gz
emacs-e75c57f10ee9418599398361b0676f48d265fb12.zip
Extend file-name-non-special
* lisp/files.el (insert-file-contents-literally): Bind `inhibit-file-name-handlers' the default way. (file-name-non-special): Rework, mainly for operations with two file name arguments. (file-name-unquote-non-special): New defsubst. (file-name-unquote): Use it. * test/lisp/files-tests.el (files-test-bug-18141): Skip if needed. (files-tests--with-temp-non-special): Add docstring. Delete also `non-special-name' if the file/directory exists. (files-tests--special-file-name-extension) (files-tests--special-file-name-regexp): New defconst. (files-tests--special-file-name-handler, files-tests--new-name): New defuns. (files-tests--with-temp-non-special-and-file-name-handler): New macro. (files-tests-file-name-non-special-access-file) (files-tests-file-name-non-special-add-name-to-file) (files-tests-file-name-non-special-byte-compiler-base-file-name) (files-tests-file-name-non-special-copy-directory) (files-tests-file-name-non-special-copy-file) (files-tests-file-name-non-special-delete-directory) (files-tests-file-name-non-special-delete-file) (files-tests-file-name-non-special-diff-latest-backup-file) (files-tests-file-name-non-special-directory-file-name) (files-tests-file-name-non-special-directory-files) (files-tests-file-name-non-special-directory-files-and-attributes) (files-tests-file-name-non-special-dired-compress-handler) (files-tests-file-name-non-special-dired-uncache) (files-tests-file-name-non-special-expand-file-name) (files-tests-file-name-non-special-file-accessible-directory-p) (files-tests-file-name-non-special-file-acl) (files-tests-file-name-non-special-file-attributes) (files-tests-file-name-non-special-file-directory-p) (files-tests-file-name-non-special-file-equal-p) (files-tests-file-name-non-special-file-executable-p) (files-tests-file-name-non-special-file-exists-p) (files-tests-file-name-non-special-file-in-directory-p) (files-tests-file-name-non-special-file-local-copy) (files-tests-file-name-non-special-file-modes) (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-case-insensitive-p) (files-tests-file-name-non-special-file-name-completion) (files-tests-file-name-non-special-file-name-directory) (files-tests-file-name-non-special-file-name-nondirectory) (files-tests-file-name-non-special-file-name-sans-versions) (files-tests-file-name-non-special-file-newer-than-file-p) (files-tests-file-name-non-special-notify-handlers) (files-tests-file-name-non-special-file-ownership-preserved-p) (files-tests-file-name-non-special-file-readable-p) (files-tests-file-name-non-special-file-regular-p) (files-tests-file-name-non-special-file-remote-p) (files-tests-file-name-non-special-file-selinux-context) (files-tests-file-name-non-special-file-symlink-p) (files-tests-file-name-non-special-file-truename) (files-tests-file-name-non-special-file-writable-p) (files-tests-file-name-non-special-find-backup-file-name) (files-tests-file-name-non-special-get-file-buffer) (files-tests-file-name-non-special-insert-directory) (files-tests-file-name-non-special-insert-file-contents) (files-tests-file-name-non-special-load) (files-tests-file-name-non-special-make-auto-save-file-name) (files-tests-file-name-non-special-make-directory) (files-tests-file-name-non-special-make-directory-internal) (files-tests-file-name-non-special-make-symbolic-link) (files-tests-file-name-non-special-rename-file) (files-tests-file-name-non-special-set-file-acl) (files-tests-file-name-non-special-set-file-modes) (files-tests-file-name-non-special-set-file-selinux-context) (files-tests-file-name-non-special-set-file-times) (files-tests-file-name-non-special-set-visited-file-modtime) (files-tests-file-name-non-special-shell-command) (files-tests-file-name-non-special-start-file-process) (files-tests-file-name-non-special-substitute-in-file-name) (files-tests-file-name-non-special-temporary-file-directory) (files-tests-file-name-non-special-unhandled-file-name-directory) (files-tests-file-name-non-special-vc-registered) (files-tests-file-name-non-special-write-region): Extends tests to quoted file names, which would require a file name handler if unquoted. (files-test-no-file-write-contents): Make test more robust. * test/lisp/net/tramp-tests.el (tramp-test21-file-links): Adapt test. (tramp--test-emacs25-p): New defun. (tramp-test34-vc-registered): Use it.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/files-tests.el489
-rw-r--r--test/lisp/net/tramp-tests.el13
2 files changed, 429 insertions, 73 deletions
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 1e6cd5eaba7..30a09c796e8 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -157,6 +157,9 @@ form.")
157(ert-deftest files-test-bug-18141 () 157(ert-deftest files-test-bug-18141 ()
158 "Test for https://debbugs.gnu.org/18141 ." 158 "Test for https://debbugs.gnu.org/18141 ."
159 (skip-unless (executable-find "gzip")) 159 (skip-unless (executable-find "gzip"))
160 ;; If called interactively, environment variable
161 ;; $EMACS_TEST_DIRECTORY does not exist.
162 (skip-unless (file-exists-p files-test-bug-18141-file))
160 (let ((tempfile (make-temp-file "files-test-bug-18141" nil ".gz"))) 163 (let ((tempfile (make-temp-file "files-test-bug-18141" nil ".gz")))
161 (unwind-protect 164 (unwind-protect
162 (progn 165 (progn
@@ -348,6 +351,12 @@ be invoked with the right arguments."
348 351
349(cl-defmacro files-tests--with-temp-non-special 352(cl-defmacro files-tests--with-temp-non-special
350 ((name non-special-name &optional dir-flag) &rest body) 353 ((name non-special-name &optional dir-flag) &rest body)
354 "Run tests with quoted file name.
355NAME is the symbol which contains the name of a created temporary
356file. NON-SPECIAL-NAME is another symbol, which contains the
357temporary file name with quoted file name syntax. If DIR-FLAG is
358non-nil, a temporary directory is created instead.
359After evaluating BODY, the temporary file or directory is deleted."
351 (declare (indent 1) (debug ((symbolp symbolp &optional form) body))) 360 (declare (indent 1) (debug ((symbolp symbolp &optional form) body)))
352 (cl-check-type name symbol) 361 (cl-check-type name symbol)
353 (cl-check-type non-special-name symbol) 362 (cl-check-type non-special-name symbol)
@@ -358,64 +367,183 @@ be invoked with the right arguments."
358 (progn ,@body) 367 (progn ,@body)
359 (when (file-exists-p ,name) 368 (when (file-exists-p ,name)
360 (if ,dir-flag (delete-directory ,name t) 369 (if ,dir-flag (delete-directory ,name t)
361 (delete-file ,name)))))) 370 (delete-file ,name)))
371 (when (file-exists-p ,non-special-name)
372 (if ,dir-flag (delete-directory ,non-special-name t)
373 (delete-file ,non-special-name))))))
374
375(defconst files-tests--special-file-name-extension ".special"
376 "Trailing string for test file name handler.")
377
378(defconst files-tests--special-file-name-regexp
379 (concat (regexp-quote files-tests--special-file-name-extension) "\\'")
380 "Regular expression for test file name handler.")
381
382(defun files-tests--special-file-name-handler (operation &rest args)
383 "File name handler for files with extension \".special\"."
384 (let ((arg args)
385 ;; Avoid cyclic call.
386 (file-name-handler-alist
387 (delete
388 (rassoc
389 'files-tests--special-file-name-handler file-name-handler-alist)
390 file-name-handler-alist)))
391 ;; Remove trailing "\\.special\\'" from arguments, if they are not quoted.
392 (while arg
393 (when (and (stringp (car arg))
394 (not (file-name-quoted-p (car arg)))
395 (string-match files-tests--special-file-name-regexp (car arg)))
396 (setcar arg (replace-match "" nil nil (car arg))))
397 (setq arg (cdr arg)))
398 ;; Call it.
399 (apply operation args)))
400
401(cl-defmacro files-tests--with-temp-non-special-and-file-name-handler
402 ((name non-special-name &optional dir-flag) &rest body)
403 "Run tests with quoted file name, see `files-tests--with-temp-non-special'.
404Both file names in NAME and NON-SPECIAL-NAME have the extension
405\".special\". The created temporary file or directory does not have
406that extension.
407A file name handler is added which is activated for files with
408that extension. It simply removes the extension from file names.
409It is expected, that this file name handler works only for
410unquoted file names."
411 (declare (indent 1) (debug ((symbolp symbolp &optional form) body)))
412 (cl-check-type name symbol)
413 (cl-check-type non-special-name symbol)
414 `(let* ((temporary-file-directory (file-truename temporary-file-directory))
415 (file-name-handler-alist
416 `((,files-tests--special-file-name-regexp
417 . files-tests--special-file-name-handler)
418 . ,file-name-handler-alist))
419 (,name (concat
420 (make-temp-file "files-tests" ,dir-flag)
421 files-tests--special-file-name-extension))
422 (,non-special-name (file-name-quote ,name)))
423 (unwind-protect
424 (progn ,@body)
425 (when (file-exists-p ,name)
426 (if ,dir-flag (delete-directory ,name t)
427 (delete-file ,name)))
428 (when (file-exists-p ,non-special-name)
429 (if ,dir-flag (delete-directory ,non-special-name t)
430 (delete-file ,non-special-name))))))
431
432(defun files-tests--new-name (name part)
433 (let (file-name-handler-alist)
434 (concat (file-name-sans-extension name) part (file-name-extension name t))))
362 435
363(ert-deftest files-tests-file-name-non-special-access-file () 436(ert-deftest files-tests-file-name-non-special-access-file ()
364 (files-tests--with-temp-non-special (tmpfile nospecial) 437 (files-tests--with-temp-non-special (tmpfile nospecial)
365 (should (null (access-file nospecial "test"))))) 438 ;; Both versions of the file name work.
439 (should-not (access-file tmpfile "test"))
440 (should-not (access-file nospecial "test")))
441 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
442 (should-not (access-file tmpfile "test"))
443 ;; The quoted file name does not work.
444 (should-error (access-file nospecial "test"))))
366 445
367(ert-deftest files-tests-file-name-non-special-add-name-to-file () 446(ert-deftest files-tests-file-name-non-special-add-name-to-file ()
368 (files-tests--with-temp-non-special (tmpfile nospecial) 447 (files-tests--with-temp-non-special (tmpfile nospecial)
369 (let ((newname (concat nospecial "add-name"))) 448 (let ((newname (files-tests--new-name nospecial "add-name")))
449 ;; Both versions work.
450 (add-name-to-file tmpfile newname)
451 (should (file-exists-p newname))
452 (delete-file newname)
370 (add-name-to-file nospecial newname) 453 (add-name-to-file nospecial newname)
371 (should (file-exists-p newname)) 454 (should (file-exists-p newname))
372 (delete-file newname)))) 455 (delete-file newname)))
456 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
457 (let ((newname (files-tests--new-name tmpfile "add-name")))
458 ;; Using an unquoted file name works.
459 (add-name-to-file tmpfile newname)
460 (should (file-exists-p newname))
461 (delete-file newname))
462 (let ((newname (files-tests--new-name nospecial "add-name")))
463 (add-name-to-file tmpfile newname)
464 (should (file-exists-p newname))
465 (delete-file newname)
466 ;; The quoted special file name does not work.
467 (should-error (add-name-to-file nospecial newname)))))
373 468
374(ert-deftest files-tests-file-name-non-special-byte-compiler-base-file-name () 469(ert-deftest files-tests-file-name-non-special-byte-compiler-base-file-name ()
375 (files-tests--with-temp-non-special (tmpfile nospecial) 470 (files-tests--with-temp-non-special (tmpfile nospecial)
376 (should (equal (byte-compiler-base-file-name nospecial) 471 (should (equal (byte-compiler-base-file-name nospecial)
377 (byte-compiler-base-file-name tmpfile))))) 472 (byte-compiler-base-file-name tmpfile))))
473 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
474 (should (equal (byte-compiler-base-file-name nospecial) tmpfile))
475 (should-not (equal (byte-compiler-base-file-name tmpfile) tmpfile))))
378 476
379(ert-deftest files-tests-file-name-non-special-copy-directory () 477(ert-deftest files-tests-file-name-non-special-copy-directory ()
380 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 478 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
381 (let ((newname (concat (directory-file-name nospecial-dir) 479 (let ((newname (files-tests--new-name
382 "copy-dir"))) 480 (directory-file-name nospecial-dir) "copy-dir")))
383 (copy-directory nospecial-dir newname) 481 (copy-directory nospecial-dir newname)
384 (should (file-directory-p newname)) 482 (should (file-directory-p newname))
385 (delete-directory newname) 483 (delete-directory newname)
386 (should-not (file-directory-p newname))))) 484 (should-not (file-directory-p newname))))
485 (files-tests--with-temp-non-special-and-file-name-handler
486 (tmpdir nospecial-dir t)
487 (let ((newname (files-tests--new-name
488 (directory-file-name nospecial-dir) "copy-dir")))
489 (should-error (copy-directory nospecial-dir newname))
490 (delete-directory newname))))
387 491
388(ert-deftest files-tests-file-name-non-special-copy-file () 492(ert-deftest files-tests-file-name-non-special-copy-file ()
389 (files-tests--with-temp-non-special (tmpfile nospecial) 493 (files-tests--with-temp-non-special (tmpfile nospecial)
390 (let ((newname (concat (directory-file-name nospecial) 494 (let ((newname
391 "copy-file"))) 495 (files-tests--new-name (directory-file-name nospecial) "copy-file")))
392 (copy-file nospecial newname) 496 (copy-file nospecial newname)
393 (should (file-exists-p newname)) 497 (should (file-exists-p newname))
394 (delete-file newname) 498 (delete-file newname)
395 (should-not (file-exists-p newname))))) 499 (should-not (file-exists-p newname))))
500 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
501 (let ((newname
502 (files-tests--new-name (directory-file-name nospecial) "copy-file")))
503 (should-error (copy-file nospecial newname)))))
396 504
397(ert-deftest files-tests-file-name-non-special-delete-directory () 505(ert-deftest files-tests-file-name-non-special-delete-directory ()
398 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 506 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
399 (delete-directory nospecial-dir))) 507 (delete-directory nospecial-dir))
508 (files-tests--with-temp-non-special-and-file-name-handler
509 (tmpdir nospecial-dir t)
510 (should-error (delete-directory nospecial-dir))))
400 511
401(ert-deftest files-tests-file-name-non-special-delete-file () 512(ert-deftest files-tests-file-name-non-special-delete-file ()
402 (files-tests--with-temp-non-special (tmpfile nospecial) 513 (files-tests--with-temp-non-special (tmpfile nospecial)
403 (delete-file nospecial))) 514 (delete-file nospecial))
515 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
516 (delete-file nospecial)
517 (should (file-exists-p tmpfile))))
404 518
405(ert-deftest files-tests-file-name-non-special-diff-latest-backup-file () 519(ert-deftest files-tests-file-name-non-special-diff-latest-backup-file ()
406 (files-tests--with-temp-non-special (tmpfile nospecial) 520 (files-tests--with-temp-non-special (tmpfile nospecial)
521 (write-region "foo" nil (make-backup-file-name tmpfile))
407 (should (equal (diff-latest-backup-file nospecial) 522 (should (equal (diff-latest-backup-file nospecial)
408 (diff-latest-backup-file tmpfile))))) 523 (diff-latest-backup-file tmpfile)))
524 (delete-file (diff-latest-backup-file nospecial)))
525 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
526 (write-region "foo" nil (make-backup-file-name tmpfile))
527 (should-not (equal (diff-latest-backup-file nospecial)
528 (diff-latest-backup-file tmpfile)))
529 (delete-file (diff-latest-backup-file nospecial))))
409 530
410(ert-deftest files-tests-file-name-non-special-directory-file-name () 531(ert-deftest files-tests-file-name-non-special-directory-file-name ()
411 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 532 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
412 (should (equal (directory-file-name nospecial-dir) 533 (should (equal (directory-file-name nospecial-dir)
413 (file-name-quote (directory-file-name tmpdir)))))) 534 (file-name-quote (directory-file-name tmpdir)))))
535 (files-tests--with-temp-non-special-and-file-name-handler
536 (tmpdir nospecial-dir t)
537 (should-not (equal (directory-file-name nospecial-dir)
538 (file-name-quote (directory-file-name tmpdir))))))
414 539
415(ert-deftest files-tests-file-name-non-special-directory-files () 540(ert-deftest files-tests-file-name-non-special-directory-files ()
416 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 541 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
417 (should (equal (directory-files nospecial-dir) 542 (should (equal (directory-files nospecial-dir)
418 (directory-files tmpdir))))) 543 (directory-files tmpdir))))
544 (files-tests--with-temp-non-special-and-file-name-handler
545 (tmpdir nospecial-dir t)
546 (should-error (directory-files nospecial-dir))))
419 547
420(defun files-tests-file-attributes-equal (attr1 attr2) 548(defun files-tests-file-attributes-equal (attr1 attr2)
421 ;; Element 4 is access time, which may be changed by the act of 549 ;; Element 4 is access time, which may be changed by the act of
@@ -433,7 +561,10 @@ be invoked with the right arguments."
433 for (file2 . attr2) in (directory-files-and-attributes tmpdir) 561 for (file2 . attr2) in (directory-files-and-attributes tmpdir)
434 do 562 do
435 (should (equal file1 file2)) 563 (should (equal file1 file2))
436 (should (files-tests-file-attributes-equal attr1 attr2))))) 564 (should (files-tests-file-attributes-equal attr1 attr2))))
565 (files-tests--with-temp-non-special-and-file-name-handler
566 (tmpdir nospecial-dir t)
567 (should-error (directory-files-and-attributes nospecial-dir))))
437 568
438(ert-deftest files-tests-file-name-non-special-dired-compress-handler () 569(ert-deftest files-tests-file-name-non-special-dired-compress-handler ()
439 ;; `dired-compress-file' can get confused by filenames with ":" in 570 ;; `dired-compress-file' can get confused by filenames with ":" in
@@ -444,164 +575,291 @@ be invoked with the right arguments."
444 (let ((compressed (dired-compress-file nospecial))) 575 (let ((compressed (dired-compress-file nospecial)))
445 (when compressed 576 (when compressed
446 ;; FIXME: Should it return a still-quoted name? 577 ;; FIXME: Should it return a still-quoted name?
447 (should (file-equal-p nospecial (dired-compress-file compressed))))))) 578 (should (file-equal-p nospecial (dired-compress-file compressed))))))
579 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
580 (should-not (dired-compress-file nospecial))))
448 581
449(ert-deftest files-tests-file-name-non-special-dired-uncache () 582(ert-deftest files-tests-file-name-non-special-dired-uncache ()
583 ;; FIXME: This is not a real test. We need cached values, and check
584 ;; whether they disappear.
450 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 585 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
586 (dired-uncache nospecial-dir))
587 (files-tests--with-temp-non-special-and-file-name-handler
588 (tmpdir nospecial-dir t)
451 (dired-uncache nospecial-dir))) 589 (dired-uncache nospecial-dir)))
452 590
453(ert-deftest files-tests-file-name-non-special-expand-file-name () 591(ert-deftest files-tests-file-name-non-special-expand-file-name ()
454 (files-tests--with-temp-non-special (tmpfile nospecial) 592 (files-tests--with-temp-non-special (tmpfile nospecial)
593 (should (equal (expand-file-name nospecial) nospecial)))
594 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
455 (should (equal (expand-file-name nospecial) nospecial)))) 595 (should (equal (expand-file-name nospecial) nospecial))))
456 596
457(ert-deftest files-tests-file-name-non-special-file-accessible-directory-p () 597(ert-deftest files-tests-file-name-non-special-file-accessible-directory-p ()
458 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 598 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
459 (should (file-accessible-directory-p nospecial-dir)))) 599 (should (file-accessible-directory-p nospecial-dir)))
600 (files-tests--with-temp-non-special-and-file-name-handler
601 (tmpdir nospecial-dir t)
602 (should-not (file-accessible-directory-p nospecial-dir))))
460 603
461(ert-deftest files-tests-file-name-non-special-file-acl () 604(ert-deftest files-tests-file-name-non-special-file-acl ()
462 (files-tests--with-temp-non-special (tmpfile nospecial) 605 (files-tests--with-temp-non-special (tmpfile nospecial)
463 (should (equal (file-acl nospecial) (file-acl tmpfile))))) 606 (should (equal (file-acl nospecial) (file-acl tmpfile))))
607 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
608 (should-not (file-acl nospecial))))
464 609
465(ert-deftest files-tests-file-name-non-special-file-attributes () 610(ert-deftest files-tests-file-name-non-special-file-attributes ()
466 (files-tests--with-temp-non-special (tmpfile nospecial) 611 (files-tests--with-temp-non-special (tmpfile nospecial)
467 (should (files-tests-file-attributes-equal 612 (should (files-tests-file-attributes-equal
468 (file-attributes nospecial) (file-attributes tmpfile))))) 613 (file-attributes nospecial) (file-attributes tmpfile))))
614 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
615 (should-not (file-attributes nospecial))))
469 616
470(ert-deftest files-tests-file-name-non-special-file-directory-p () 617(ert-deftest files-tests-file-name-non-special-file-directory-p ()
471 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 618 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
472 (should (file-directory-p nospecial-dir)))) 619 (should (file-directory-p nospecial-dir)))
620 (files-tests--with-temp-non-special-and-file-name-handler
621 (tmpdir nospecial-dir t)
622 (should-not (file-directory-p nospecial-dir))))
473 623
474(ert-deftest files-tests-file-name-non-special-file-equal-p () 624(ert-deftest files-tests-file-name-non-special-file-equal-p ()
475 (files-tests--with-temp-non-special (tmpfile nospecial) 625 (files-tests--with-temp-non-special (tmpfile nospecial)
476 (should (file-equal-p nospecial tmpfile)) 626 (should (file-equal-p nospecial tmpfile))
477 (should (file-equal-p tmpfile nospecial)) 627 (should (file-equal-p tmpfile nospecial))
628 (should (file-equal-p nospecial nospecial)))
629 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
630 (should (file-equal-p (file-name-unquote nospecial) tmpfile))
631 (should (file-equal-p tmpfile (file-name-unquote nospecial)))
632 ;; File `nospecial' does not exist, so it cannot be compared.
633 (should-not (file-equal-p nospecial nospecial))
634 (write-region "foo" nil nospecial)
478 (should (file-equal-p nospecial nospecial)))) 635 (should (file-equal-p nospecial nospecial))))
479 636
480(ert-deftest files-tests-file-name-non-special-file-executable-p () 637(ert-deftest files-tests-file-name-non-special-file-executable-p ()
481 (files-tests--with-temp-non-special (tmpfile nospecial) 638 (files-tests--with-temp-non-special (tmpfile nospecial)
639 (should-not (file-executable-p nospecial)))
640 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
482 (should-not (file-executable-p nospecial)))) 641 (should-not (file-executable-p nospecial))))
483 642
484(ert-deftest files-tests-file-name-non-special-file-exists-p () 643(ert-deftest files-tests-file-name-non-special-file-exists-p ()
485 (files-tests--with-temp-non-special (tmpfile nospecial) 644 (files-tests--with-temp-non-special (tmpfile nospecial)
486 (should (file-exists-p nospecial)))) 645 (should (file-exists-p tmpfile))
646 (should (file-exists-p nospecial)))
647 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
648 (should (file-exists-p tmpfile))
649 (should-not (file-exists-p nospecial))))
487 650
488(ert-deftest files-tests-file-name-non-special-file-in-directory-p () 651(ert-deftest files-tests-file-name-non-special-file-in-directory-p ()
489 (files-tests--with-temp-non-special (tmpfile nospecial) 652 (files-tests--with-temp-non-special (tmpfile nospecial)
490 (let ((nospecial-tempdir (file-name-quote temporary-file-directory))) 653 (let ((nospecial-tempdir (file-name-quote temporary-file-directory)))
491 (should (file-in-directory-p nospecial temporary-file-directory)) 654 (should (file-in-directory-p nospecial temporary-file-directory))
492 (should (file-in-directory-p tmpfile nospecial-tempdir)) 655 (should (file-in-directory-p tmpfile nospecial-tempdir))
656 (should (file-in-directory-p nospecial nospecial-tempdir))))
657 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
658 (let ((nospecial-tempdir (file-name-quote temporary-file-directory)))
659 (should (file-in-directory-p nospecial temporary-file-directory))
660 (should (file-in-directory-p tmpfile nospecial-tempdir))
493 (should (file-in-directory-p nospecial nospecial-tempdir))))) 661 (should (file-in-directory-p nospecial nospecial-tempdir)))))
494 662
495(ert-deftest files-tests-file-name-non-special-file-local-copy () 663(ert-deftest files-tests-file-name-non-special-file-local-copy ()
496 (files-tests--with-temp-non-special (tmpfile nospecial) 664 (files-tests--with-temp-non-special (tmpfile nospecial)
665 (should-not (file-local-copy nospecial))) ; Already local.
666 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
497 (should-not (file-local-copy nospecial)))) ; Already local. 667 (should-not (file-local-copy nospecial)))) ; Already local.
498 668
499(ert-deftest files-tests-file-name-non-special-file-modes () 669(ert-deftest files-tests-file-name-non-special-file-modes ()
500 (files-tests--with-temp-non-special (tmpfile nospecial) 670 (files-tests--with-temp-non-special (tmpfile nospecial)
501 (should (equal (file-modes nospecial) (file-modes tmpfile))))) 671 (should (equal (file-modes nospecial) (file-modes tmpfile))))
672 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
673 (should-not (equal (file-modes nospecial) (file-modes tmpfile)))))
502 674
503(ert-deftest files-tests-file-name-non-special-file-name-all-completions () 675(ert-deftest files-tests-file-name-non-special-file-name-all-completions ()
504 (files-tests--with-temp-non-special (tmpfile nospecial) 676 (files-tests--with-temp-non-special (tmpfile nospecial)
505 (let ((nospecial-tempdir (file-name-quote temporary-file-directory)) 677 (let ((nospecial-tempdir (file-name-quote temporary-file-directory))
506 (tmpdir temporary-file-directory)) 678 (tmpdir temporary-file-directory)
507 (should (equal (file-name-all-completions nospecial nospecial-tempdir) 679 (file (file-name-nondirectory tmpfile))
508 (file-name-all-completions tmpfile tmpdir))) 680 (nospecial-file (file-name-nondirectory nospecial)))
509 (should (equal (file-name-all-completions tmpfile nospecial-tempdir) 681 (should (string-equal file nospecial-file))
510 (file-name-all-completions tmpfile tmpdir))) 682 (should (equal (file-name-all-completions
511 (should (equal (file-name-all-completions nospecial tmpdir) 683 nospecial-file nospecial-tempdir)
512 (file-name-all-completions tmpfile tmpdir)))))) 684 (file-name-all-completions file tmpdir)))
685 (should (equal (file-name-all-completions file nospecial-tempdir)
686 (file-name-all-completions file tmpdir)))
687 (should (equal (file-name-all-completions nospecial-file tmpdir)
688 (file-name-all-completions file tmpdir)))))
689 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
690 (let ((nospecial-tempdir (file-name-quote temporary-file-directory))
691 (tmpdir temporary-file-directory)
692 (file (file-name-nondirectory tmpfile))
693 (nospecial-file (file-name-nondirectory nospecial)))
694 (should-not (string-equal file nospecial-file))
695 (should-not (equal (file-name-all-completions
696 nospecial-file nospecial-tempdir)
697 (file-name-all-completions file tmpdir)))
698 (should (equal (file-name-all-completions file nospecial-tempdir)
699 (file-name-all-completions file tmpdir)))
700 (should (equal (file-name-all-completions nospecial-file tmpdir)
701 (file-name-all-completions file tmpdir))))))
513 702
514(ert-deftest files-tests-file-name-non-special-file-name-as-directory () 703(ert-deftest files-tests-file-name-non-special-file-name-as-directory ()
515 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 704 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
516 (should (equal (file-name-as-directory nospecial-dir) 705 (should (equal (file-name-as-directory nospecial-dir)
706 (file-name-quote (file-name-as-directory tmpdir)))))
707 (files-tests--with-temp-non-special-and-file-name-handler
708 (tmpdir nospecial-dir t)
709 (should-not (equal (file-name-as-directory nospecial-dir)
517 (file-name-quote (file-name-as-directory tmpdir)))))) 710 (file-name-quote (file-name-as-directory tmpdir))))))
518 711
519(ert-deftest files-tests-file-name-non-special-file-name-case-insensitive-p () 712(ert-deftest files-tests-file-name-non-special-file-name-case-insensitive-p ()
520 (files-tests--with-temp-non-special (tmpfile nospecial) 713 (files-tests--with-temp-non-special (tmpfile nospecial)
521 (should (equal (file-name-case-insensitive-p nospecial) 714 (should (equal (file-name-case-insensitive-p nospecial)
715 (file-name-case-insensitive-p tmpfile))))
716 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
717 (should (equal (file-name-case-insensitive-p nospecial)
522 (file-name-case-insensitive-p tmpfile))))) 718 (file-name-case-insensitive-p tmpfile)))))
523 719
524(ert-deftest files-tests-file-name-non-special-file-name-completion () 720(ert-deftest files-tests-file-name-non-special-file-name-completion ()
525 (files-tests--with-temp-non-special (tmpfile nospecial) 721 (files-tests--with-temp-non-special (tmpfile nospecial)
526 (let ((nospecial-tempdir (file-name-quote temporary-file-directory)) 722 (let ((nospecial-tempdir (file-name-quote temporary-file-directory))
527 (tmpdir temporary-file-directory)) 723 (tmpdir temporary-file-directory)
528 (should (equal (file-name-completion nospecial nospecial-tempdir) 724 (file (file-name-nondirectory tmpfile))
529 (file-name-completion tmpfile tmpdir))) 725 (nospecial-file (file-name-nondirectory nospecial)))
530 (should (equal (file-name-completion tmpfile nospecial-tempdir) 726 (should (string-equal file nospecial-file))
531 (file-name-completion tmpfile tmpdir))) 727 (should (equal (file-name-completion nospecial-file nospecial-tempdir)
532 (should (equal (file-name-completion nospecial tmpdir) 728 (file-name-completion file tmpdir)))
533 (file-name-completion tmpfile tmpdir)))))) 729 (should (equal (file-name-completion file nospecial-tempdir)
730 (file-name-completion file tmpdir)))
731 (should (equal (file-name-completion nospecial-file tmpdir)
732 (file-name-completion file tmpdir)))))
733 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
734 (let ((nospecial-tempdir (file-name-quote temporary-file-directory))
735 (tmpdir temporary-file-directory)
736 (file (file-name-nondirectory tmpfile))
737 (nospecial-file (file-name-nondirectory nospecial)))
738 (should-not (string-equal file nospecial-file))
739 (should-not (equal (file-name-completion nospecial-file nospecial-tempdir)
740 (file-name-completion file tmpdir)))
741 (should (equal (file-name-completion file nospecial-tempdir)
742 (file-name-completion file tmpdir)))
743 (should (equal (file-name-completion nospecial-file tmpdir)
744 (file-name-completion file tmpdir))))))
534 745
535(ert-deftest files-tests-file-name-non-special-file-name-directory () 746(ert-deftest files-tests-file-name-non-special-file-name-directory ()
536 (files-tests--with-temp-non-special (tmpfile nospecial) 747 (files-tests--with-temp-non-special (tmpfile nospecial)
537 (should (equal (file-name-directory nospecial) 748 (should (equal (file-name-directory nospecial)
749 (file-name-quote temporary-file-directory))))
750 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
751 (should (equal (file-name-directory nospecial)
538 (file-name-quote temporary-file-directory))))) 752 (file-name-quote temporary-file-directory)))))
539 753
540(ert-deftest files-tests-file-name-non-special-file-name-nondirectory () 754(ert-deftest files-tests-file-name-non-special-file-name-nondirectory ()
541 (files-tests--with-temp-non-special (tmpfile nospecial) 755 (files-tests--with-temp-non-special (tmpfile nospecial)
542 (should (equal (file-name-nondirectory nospecial) 756 (should (equal (file-name-nondirectory nospecial)
543 (file-name-nondirectory tmpfile))))) 757 (file-name-nondirectory tmpfile))))
758 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
759 (should-not (equal (file-name-nondirectory nospecial)
760 (file-name-nondirectory tmpfile)))))
544 761
545(ert-deftest files-tests-file-name-non-special-file-name-sans-versions () 762(ert-deftest files-tests-file-name-non-special-file-name-sans-versions ()
546 (files-tests--with-temp-non-special (tmpfile nospecial) 763 (files-tests--with-temp-non-special (tmpfile nospecial)
764 (should (equal (file-name-sans-versions nospecial) nospecial)))
765 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
547 (should (equal (file-name-sans-versions nospecial) nospecial)))) 766 (should (equal (file-name-sans-versions nospecial) nospecial))))
548 767
549(ert-deftest files-tests-file-name-non-special-file-newer-than-file-p () 768(ert-deftest files-tests-file-name-non-special-file-newer-than-file-p ()
550 (files-tests--with-temp-non-special (tmpfile nospecial) 769 (files-tests--with-temp-non-special (tmpfile nospecial)
551 (should-not (file-newer-than-file-p nospecial tmpfile)) 770 (should-not (file-newer-than-file-p nospecial tmpfile))
552 (should-not (file-newer-than-file-p tmpfile nospecial)) 771 (should-not (file-newer-than-file-p tmpfile nospecial))
772 (should-not (file-newer-than-file-p nospecial nospecial)))
773 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
774 (should-not (file-newer-than-file-p nospecial tmpfile))
775 (should (file-newer-than-file-p tmpfile nospecial))
553 (should-not (file-newer-than-file-p nospecial nospecial)))) 776 (should-not (file-newer-than-file-p nospecial nospecial))))
554 777
555(ert-deftest files-file-name-non-special-notify-handlers () 778(ert-deftest files-tests-file-name-non-special-notify-handlers ()
556 (skip-unless file-notify--library) 779 (skip-unless file-notify--library)
557 (files-tests--with-temp-non-special (tmpfile nospecial) 780 (files-tests--with-temp-non-special (tmpfile nospecial)
558 (let ((watch (file-notify-add-watch nospecial '(change) #'ignore))) 781 (let ((watch (file-notify-add-watch nospecial '(change) #'ignore)))
559 (should (file-notify-valid-p watch)) 782 (should (file-notify-valid-p watch))
560 (file-notify-rm-watch watch) 783 (file-notify-rm-watch watch)
784 (should-not (file-notify-valid-p watch))))
785 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
786 (let ((watch (file-notify-add-watch nospecial '(change) #'ignore)))
787 (should (file-notify-valid-p watch))
788 (file-notify-rm-watch watch)
561 (should-not (file-notify-valid-p watch))))) 789 (should-not (file-notify-valid-p watch)))))
562 790
563(ert-deftest files-tests-file-name-non-special-file-ownership-preserved-p () 791(ert-deftest files-tests-file-name-non-special-file-ownership-preserved-p ()
564 (files-tests--with-temp-non-special (tmpfile nospecial) 792 (files-tests--with-temp-non-special (tmpfile nospecial)
565 (should (equal (file-ownership-preserved-p nospecial) 793 (should (equal (file-ownership-preserved-p nospecial)
794 (file-ownership-preserved-p tmpfile))))
795 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
796 (should (equal (file-ownership-preserved-p nospecial)
566 (file-ownership-preserved-p tmpfile))))) 797 (file-ownership-preserved-p tmpfile)))))
567 798
568(ert-deftest files-tests-file-name-non-special-file-readable-p () 799(ert-deftest files-tests-file-name-non-special-file-readable-p ()
569 (files-tests--with-temp-non-special (tmpfile nospecial) 800 (files-tests--with-temp-non-special (tmpfile nospecial)
570 (should (file-readable-p nospecial)))) 801 (should (file-readable-p nospecial)))
802 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
803 (should-not (file-readable-p nospecial))))
571 804
572(ert-deftest files-tests-file-name-non-special-file-regular-p () 805(ert-deftest files-tests-file-name-non-special-file-regular-p ()
573 (files-tests--with-temp-non-special (tmpfile nospecial) 806 (files-tests--with-temp-non-special (tmpfile nospecial)
574 (should (file-regular-p nospecial)))) 807 (should (file-regular-p nospecial)))
808 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
809 (should-not (file-regular-p nospecial))))
575 810
576(ert-deftest files-tests-file-name-non-special-file-remote-p () 811(ert-deftest files-tests-file-name-non-special-file-remote-p ()
577 (files-tests--with-temp-non-special (tmpfile nospecial) 812 (files-tests--with-temp-non-special (tmpfile nospecial)
813 (should-not (file-remote-p nospecial)))
814 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
578 (should-not (file-remote-p nospecial)))) 815 (should-not (file-remote-p nospecial))))
579 816
580(ert-deftest files-tests-file-name-non-special-file-selinux-context () 817(ert-deftest files-tests-file-name-non-special-file-selinux-context ()
581 (files-tests--with-temp-non-special (tmpfile nospecial) 818 (files-tests--with-temp-non-special (tmpfile nospecial)
582 (should (equal (file-selinux-context nospecial) 819 (unless (equal (file-selinux-context tmpfile) '(nil nil nil nil))
583 (file-selinux-context tmpfile))))) 820 (should (equal (file-selinux-context nospecial)
821 (file-selinux-context tmpfile)))))
822 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
823 (unless (equal (file-selinux-context tmpfile) '(nil nil nil nil))
824 (should-not (equal (file-selinux-context nospecial)
825 (file-selinux-context tmpfile))))))
584 826
585(ert-deftest files-tests-file-name-non-special-file-symlink-p () 827(ert-deftest files-tests-file-name-non-special-file-symlink-p ()
586 (files-tests--with-temp-non-special (tmpfile nospecial) 828 (files-tests--with-temp-non-special (tmpfile nospecial)
829 (should-not (file-symlink-p nospecial)))
830 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
587 (should-not (file-symlink-p nospecial)))) 831 (should-not (file-symlink-p nospecial))))
588 832
589(ert-deftest files-tests-file-name-non-special-file-truename () 833(ert-deftest files-tests-file-name-non-special-file-truename ()
590 (files-tests--with-temp-non-special (tmpfile nospecial) 834 (files-tests--with-temp-non-special (tmpfile nospecial)
835 (should (equal nospecial (file-truename nospecial))))
836 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
591 (should (equal nospecial (file-truename nospecial))))) 837 (should (equal nospecial (file-truename nospecial)))))
592 838
593(ert-deftest files-tests-file-name-non-special-file-writable-p () 839(ert-deftest files-tests-file-name-non-special-file-writable-p ()
594 (files-tests--with-temp-non-special (tmpfile nospecial) 840 (files-tests--with-temp-non-special (tmpfile nospecial)
841 (should (file-writable-p nospecial)))
842 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
595 (should (file-writable-p nospecial)))) 843 (should (file-writable-p nospecial))))
596 844
597(ert-deftest files-tests-file-name-non-special-find-backup-file-name () 845(ert-deftest files-tests-file-name-non-special-find-backup-file-name ()
598 (files-tests--with-temp-non-special (tmpfile nospecial) 846 (let (version-control delete-old-versions
599 (should (equal (find-backup-file-name nospecial) 847 (kept-old-versions (default-toplevel-value 'kept-old-versions))
600 (mapcar #'file-name-quote 848 (kept-new-versions (default-toplevel-value 'kept-new-versions)))
601 (find-backup-file-name tmpfile)))))) 849 (files-tests--with-temp-non-special (tmpfile nospecial)
850 (should (equal (find-backup-file-name nospecial)
851 (mapcar #'file-name-quote
852 (find-backup-file-name tmpfile)))))
853 (files-tests--with-temp-non-special-and-file-name-handler
854 (tmpfile nospecial)
855 (should-not (equal (find-backup-file-name nospecial)
856 (mapcar #'file-name-quote
857 (find-backup-file-name tmpfile)))))))
602 858
603(ert-deftest files-tests-file-name-non-special-get-file-buffer () 859(ert-deftest files-tests-file-name-non-special-get-file-buffer ()
604 (files-tests--with-temp-non-special (tmpfile nospecial) 860 (files-tests--with-temp-non-special (tmpfile nospecial)
861 (should-not (get-file-buffer nospecial)))
862 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
605 (should-not (get-file-buffer nospecial)))) 863 (should-not (get-file-buffer nospecial))))
606 864
607(ert-deftest files-tests-file-name-non-special-insert-directory () 865(ert-deftest files-tests-file-name-non-special-insert-directory ()
@@ -611,16 +869,23 @@ be invoked with the right arguments."
611 (buffer-string)) 869 (buffer-string))
612 (with-temp-buffer 870 (with-temp-buffer
613 (insert-directory tmpdir "") 871 (insert-directory tmpdir "")
614 (buffer-string)))))) 872 (buffer-string)))))
873 (files-tests--with-temp-non-special-and-file-name-handler
874 (tmpdir nospecial-dir t)
875 (should-error (with-temp-buffer (insert-directory nospecial-dir "")))))
615 876
616(ert-deftest files-tests-file-name-non-special-insert-file-contents () 877(ert-deftest files-tests-file-name-non-special-insert-file-contents ()
617 (files-tests--with-temp-non-special (tmpfile nospecial) 878 (files-tests--with-temp-non-special (tmpfile nospecial)
618 (with-temp-buffer 879 (with-temp-buffer
619 (insert-file-contents nospecial) 880 (insert-file-contents nospecial)
620 (should (zerop (buffer-size)))))) 881 (should (zerop (buffer-size)))))
882 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
883 (should-error (with-temp-buffer (insert-file-contents nospecial)))))
621 884
622(ert-deftest files-tests-file-name-non-special-load () 885(ert-deftest files-tests-file-name-non-special-load ()
623 (files-tests--with-temp-non-special (tmpfile nospecial) 886 (files-tests--with-temp-non-special (tmpfile nospecial)
887 (should (load nospecial nil t)))
888 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
624 (should (load nospecial nil t)))) 889 (should (load nospecial nil t))))
625 890
626(ert-deftest files-tests-file-name-non-special-make-auto-save-file-name () 891(ert-deftest files-tests-file-name-non-special-make-auto-save-file-name ()
@@ -631,21 +896,37 @@ be invoked with the right arguments."
631 (kill-buffer)) 896 (kill-buffer))
632 (prog2 (set-buffer (find-file-noselect tmpfile)) 897 (prog2 (set-buffer (find-file-noselect tmpfile))
633 (make-auto-save-file-name) 898 (make-auto-save-file-name)
634 (kill-buffer))))))) 899 (kill-buffer))))))
900 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
901 (save-current-buffer
902 (should-not (equal (prog2 (set-buffer (find-file-noselect nospecial))
903 (make-auto-save-file-name)
904 (kill-buffer))
905 (prog2 (set-buffer (find-file-noselect tmpfile))
906 (make-auto-save-file-name)
907 (kill-buffer)))))))
635 908
636(ert-deftest files-tests-file-name-non-special-make-directory () 909(ert-deftest files-tests-file-name-non-special-make-directory ()
637 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 910 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
638 (let ((default-directory nospecial-dir)) 911 (let ((default-directory nospecial-dir))
639 (make-directory "dir") 912 (make-directory "dir")
640 (should (file-directory-p "dir")) 913 (should (file-directory-p "dir"))
641 (delete-directory "dir")))) 914 (delete-directory "dir")))
915 (files-tests--with-temp-non-special-and-file-name-handler
916 (tmpdir nospecial-dir t)
917 (let ((default-directory nospecial-dir))
918 (should-error (make-directory "dir")))))
642 919
643(ert-deftest files-tests-file-name-non-special-make-directory-internal () 920(ert-deftest files-tests-file-name-non-special-make-directory-internal ()
644 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 921 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
645 (let ((default-directory nospecial-dir)) 922 (let ((default-directory nospecial-dir))
646 (make-directory-internal "dir") 923 (make-directory-internal "dir")
647 (should (file-directory-p "dir")) 924 (should (file-directory-p "dir"))
648 (delete-directory "dir")))) 925 (delete-directory "dir")))
926 (files-tests--with-temp-non-special-and-file-name-handler
927 (tmpdir nospecial-dir t)
928 (let ((default-directory nospecial-dir))
929 (should-error (make-directory-internal "dir")))))
649 930
650(ert-deftest files-tests-file-name-non-special-make-nearby-temp-file () 931(ert-deftest files-tests-file-name-non-special-make-nearby-temp-file ()
651 (let* ((default-directory (file-name-quote temporary-file-directory)) 932 (let* ((default-directory (file-name-quote temporary-file-directory))
@@ -655,7 +936,7 @@ be invoked with the right arguments."
655 936
656(ert-deftest files-tests-file-name-non-special-make-symbolic-link () 937(ert-deftest files-tests-file-name-non-special-make-symbolic-link ()
657 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 938 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
658 (files-tests--with-temp-non-special (tmpfile _nospecial) 939 (files-tests--with-temp-non-special (tmpfile nospecial)
659 (let* ((linkname (expand-file-name "link" tmpdir)) 940 (let* ((linkname (expand-file-name "link" tmpdir))
660 (may-symlink (ignore-errors (make-symbolic-link tmpfile linkname) 941 (may-symlink (ignore-errors (make-symbolic-link tmpfile linkname)
661 t))) 942 t)))
@@ -665,41 +946,76 @@ be invoked with the right arguments."
665 (let ((linkname (expand-file-name "link" nospecial-dir))) 946 (let ((linkname (expand-file-name "link" nospecial-dir)))
666 (make-symbolic-link tmpfile linkname) 947 (make-symbolic-link tmpfile linkname)
667 (should (file-symlink-p linkname)) 948 (should (file-symlink-p linkname))
668 (delete-file linkname))))))) 949 (delete-file linkname))))))
950 (files-tests--with-temp-non-special-and-file-name-handler
951 (tmpdir nospecial-dir t)
952 (files-tests--with-temp-non-special-and-file-name-handler
953 (tmpfile nospecial)
954 (let* ((linkname (expand-file-name "link" tmpdir))
955 (may-symlink (ignore-errors (make-symbolic-link tmpfile linkname)
956 t)))
957 (when may-symlink
958 (should (file-symlink-p linkname))
959 (delete-file linkname)
960 (let ((linkname (expand-file-name "link" nospecial-dir)))
961 (should-error (make-symbolic-link tmpfile linkname))))))))
669 962
670;; See `files-tests--file-name-non-special--subprocess'. 963;; See `files-tests--file-name-non-special--subprocess'.
671;; (ert-deftest files-tests-file-name-non-special-process-file ()) 964;; (ert-deftest files-tests-file-name-non-special-process-file ())
672 965
673(ert-deftest files-tests-file-name-non-special-rename-file () 966(ert-deftest files-tests-file-name-non-special-rename-file ()
674 (files-tests--with-temp-non-special (tmpfile nospecial) 967 (files-tests--with-temp-non-special (tmpfile nospecial)
675 (rename-file nospecial (concat nospecial "x")) 968 (rename-file nospecial (files-tests--new-name nospecial "x"))
676 (rename-file (concat nospecial "x") nospecial) 969 (rename-file (files-tests--new-name nospecial "x") nospecial)
677 (rename-file tmpfile (concat nospecial "x")) 970 (rename-file tmpfile (files-tests--new-name nospecial "x"))
678 (rename-file (concat nospecial "x") nospecial) 971 (rename-file (files-tests--new-name nospecial "x") nospecial)
679 (rename-file nospecial (concat tmpfile "x")) 972 (rename-file nospecial (files-tests--new-name tmpfile "x"))
680 (rename-file (concat nospecial "x") nospecial))) 973 (rename-file (files-tests--new-name nospecial "x") nospecial))
974 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
975 (should-error (rename-file nospecial (files-tests--new-name nospecial "x")))
976 (rename-file tmpfile (files-tests--new-name nospecial "x"))
977 (rename-file (files-tests--new-name nospecial "x") nospecial)
978 (rename-file nospecial (files-tests--new-name tmpfile "x"))
979 (should-error (rename-file (files-tests--new-name nospecial "x") nospecial))
980 (delete-file (files-tests--new-name tmpfile "x"))
981 (delete-file (files-tests--new-name nospecial "x"))))
681 982
682(ert-deftest files-tests-file-name-non-special-set-file-acl () 983(ert-deftest files-tests-file-name-non-special-set-file-acl ()
683 (files-tests--with-temp-non-special (tmpfile nospecial) 984 (files-tests--with-temp-non-special (tmpfile nospecial)
985 (set-file-acl nospecial (file-acl nospecial)))
986 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
684 (set-file-acl nospecial (file-acl nospecial)))) 987 (set-file-acl nospecial (file-acl nospecial))))
685 988
686(ert-deftest files-tests-file-name-non-special-set-file-modes () 989(ert-deftest files-tests-file-name-non-special-set-file-modes ()
687 (files-tests--with-temp-non-special (tmpfile nospecial) 990 (files-tests--with-temp-non-special (tmpfile nospecial)
688 (set-file-modes nospecial (file-modes nospecial)))) 991 (set-file-modes nospecial (file-modes nospecial)))
992 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
993 (should-error (set-file-modes nospecial (file-modes nospecial)))))
689 994
690(ert-deftest files-tests-file-name-non-special-set-file-selinux-context () 995(ert-deftest files-tests-file-name-non-special-set-file-selinux-context ()
691 (files-tests--with-temp-non-special (tmpfile nospecial) 996 (files-tests--with-temp-non-special (tmpfile nospecial)
692 (set-file-selinux-context nospecial (file-selinux-context nospecial)))) 997 (unless (equal (file-selinux-context tmpfile) '(nil nil nil nil))
998 (set-file-selinux-context nospecial (file-selinux-context nospecial))))
999 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
1000 (unless (equal (file-selinux-context tmpfile) '(nil nil nil nil))
1001 (set-file-selinux-context nospecial (file-selinux-context nospecial)))))
693 1002
694(ert-deftest files-tests-file-name-non-special-set-file-times () 1003(ert-deftest files-tests-file-name-non-special-set-file-times ()
695 (files-tests--with-temp-non-special (tmpfile nospecial) 1004 (files-tests--with-temp-non-special (tmpfile nospecial)
696 (set-file-times nospecial))) 1005 (set-file-times nospecial))
1006 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
1007 (should-error (set-file-times nospecial))))
697 1008
698(ert-deftest files-tests-file-name-non-special-set-visited-file-modtime () 1009(ert-deftest files-tests-file-name-non-special-set-visited-file-modtime ()
699 (files-tests--with-temp-non-special (tmpfile nospecial) 1010 (files-tests--with-temp-non-special (tmpfile nospecial)
700 (save-current-buffer 1011 (save-current-buffer
701 (set-buffer (find-file-noselect nospecial)) 1012 (set-buffer (find-file-noselect nospecial))
702 (set-visited-file-modtime) 1013 (set-visited-file-modtime)
1014 (kill-buffer)))
1015 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
1016 (save-current-buffer
1017 (set-buffer (find-file-noselect nospecial))
1018 (set-visited-file-modtime)
703 (kill-buffer)))) 1019 (kill-buffer))))
704 1020
705(ert-deftest files-tests-file-name-non-special-shell-command () 1021(ert-deftest files-tests-file-name-non-special-shell-command ()
@@ -711,7 +1027,16 @@ be invoked with the right arguments."
711 " --version") 1027 " --version")
712 (current-buffer)) 1028 (current-buffer))
713 (goto-char (point-min)) 1029 (goto-char (point-min))
714 (should (search-forward emacs-version nil t)))))) 1030 (should (search-forward emacs-version nil t)))))
1031 (files-tests--with-temp-non-special-and-file-name-handler
1032 (tmpdir nospecial-dir t)
1033 (with-temp-buffer
1034 (let ((default-directory nospecial-dir))
1035 (should-error
1036 (shell-command (concat (shell-quote-argument
1037 (concat invocation-directory invocation-name))
1038 " --version")
1039 (current-buffer)))))))
715 1040
716(ert-deftest files-tests-file-name-non-special-start-file-process () 1041(ert-deftest files-tests-file-name-non-special-start-file-process ()
717 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 1042 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
@@ -726,26 +1051,50 @@ be invoked with the right arguments."
726 (should (search-forward emacs-version nil t)) 1051 (should (search-forward emacs-version nil t))
727 ;; Don't stop the test run with a query, as the subprocess 1052 ;; Don't stop the test run with a query, as the subprocess
728 ;; may or may not be dead by the time we reach here. 1053 ;; may or may not be dead by the time we reach here.
729 (set-process-query-on-exit-flag proc nil)))))) 1054 (set-process-query-on-exit-flag proc nil)))))
1055 (files-tests--with-temp-non-special-and-file-name-handler
1056 (tmpdir nospecial-dir t)
1057 (with-temp-buffer
1058 (let ((default-directory nospecial-dir))
1059 (should-error (start-file-process
1060 "emacs" (current-buffer)
1061 (concat invocation-directory invocation-name)
1062 "--version"))))))
730 1063
731(ert-deftest files-tests-file-name-non-special-substitute-in-file-name () 1064(ert-deftest files-tests-file-name-non-special-substitute-in-file-name ()
732 (files-tests--with-temp-non-special (tmpfile nospecial) 1065 (files-tests--with-temp-non-special (tmpfile nospecial)
733 (let ((process-environment (cons "FOO=foo" process-environment)) 1066 (let ((process-environment (cons "FOO=foo" process-environment))
734 (nospecial-foo (concat nospecial "$FOO"))) 1067 (nospecial-foo (files-tests--new-name nospecial "$FOO")))
1068 ;; The "/:" prevents substitution.
1069 (equal (substitute-in-file-name nospecial-foo) nospecial-foo)))
1070 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
1071 (let ((process-environment (cons "FOO=foo" process-environment))
1072 (nospecial-foo (files-tests--new-name nospecial "$FOO")))
735 ;; The "/:" prevents substitution. 1073 ;; The "/:" prevents substitution.
736 (equal (substitute-in-file-name nospecial-foo) nospecial-foo)))) 1074 (equal (substitute-in-file-name nospecial-foo) nospecial-foo))))
1075
737(ert-deftest files-tests-file-name-non-special-temporary-file-directory () 1076(ert-deftest files-tests-file-name-non-special-temporary-file-directory ()
738 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 1077 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
739 (let ((default-directory nospecial-dir)) 1078 (let ((default-directory nospecial-dir))
1079 (equal (temporary-file-directory) temporary-file-directory)))
1080 (files-tests--with-temp-non-special-and-file-name-handler
1081 (tmpdir nospecial-dir t)
1082 (let ((default-directory nospecial-dir))
740 (equal (temporary-file-directory) temporary-file-directory)))) 1083 (equal (temporary-file-directory) temporary-file-directory))))
741 1084
742(ert-deftest files-tests-file-name-non-special-unhandled-file-name-directory () 1085(ert-deftest files-tests-file-name-non-special-unhandled-file-name-directory ()
743 (files-tests--with-temp-non-special (tmpdir nospecial-dir t) 1086 (files-tests--with-temp-non-special (tmpdir nospecial-dir t)
744 (equal (unhandled-file-name-directory nospecial-dir) 1087 (equal (unhandled-file-name-directory nospecial-dir)
1088 (file-name-as-directory tmpdir)))
1089 (files-tests--with-temp-non-special-and-file-name-handler
1090 (tmpdir nospecial-dir t)
1091 (equal (unhandled-file-name-directory nospecial-dir)
745 (file-name-as-directory tmpdir)))) 1092 (file-name-as-directory tmpdir))))
746 1093
747(ert-deftest files-tests-file-name-non-special-vc-registered () 1094(ert-deftest files-tests-file-name-non-special-vc-registered ()
748 (files-tests--with-temp-non-special (tmpfile nospecial) 1095 (files-tests--with-temp-non-special (tmpfile nospecial)
1096 (should (equal (vc-registered nospecial) (vc-registered tmpfile))))
1097 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
749 (should (equal (vc-registered nospecial) (vc-registered tmpfile))))) 1098 (should (equal (vc-registered nospecial) (vc-registered tmpfile)))))
750 1099
751;; See test `files-tests--file-name-non-special--buffers'. 1100;; See test `files-tests--file-name-non-special--buffers'.
@@ -754,6 +1103,9 @@ be invoked with the right arguments."
754(ert-deftest files-tests-file-name-non-special-write-region () 1103(ert-deftest files-tests-file-name-non-special-write-region ()
755 (files-tests--with-temp-non-special (tmpfile nospecial) 1104 (files-tests--with-temp-non-special (tmpfile nospecial)
756 (with-temp-buffer 1105 (with-temp-buffer
1106 (write-region nil nil nospecial nil :visit)))
1107 (files-tests--with-temp-non-special-and-file-name-handler (tmpfile nospecial)
1108 (with-temp-buffer
757 (write-region nil nil nospecial nil :visit)))) 1109 (write-region nil nil nospecial nil :visit))))
758 1110
759(ert-deftest files-tests--insert-directory-wildcard-in-dir-p () 1111(ert-deftest files-tests--insert-directory-wildcard-in-dir-p ()
@@ -804,7 +1156,8 @@ consider the buffer saved, without prompting for a file
804name (Bug#28412)." 1156name (Bug#28412)."
805 (let ((read-file-name-function 1157 (let ((read-file-name-function
806 (lambda (&rest _ignore) 1158 (lambda (&rest _ignore)
807 (error "Prompting for file name")))) 1159 (error "Prompting for file name")))
1160 require-final-newline)
808 ;; With contents function, and no file. 1161 ;; With contents function, and no file.
809 (with-temp-buffer 1162 (with-temp-buffer
810 (setq write-contents-functions (lambda () t)) 1163 (setq write-contents-functions (lambda () t))
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 09e9bac9e5c..c5cb4cb43eb 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -3125,10 +3125,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
3125 ;; We must unquote it. 3125 ;; We must unquote it.
3126 (should 3126 (should
3127 (string-equal 3127 (string-equal
3128 (funcall 3128 (file-truename tmp-name1)
3129 (if (tramp--test-emacs27-p)
3130 'tramp-compat-file-name-unquote 'identity)
3131 (file-truename tmp-name1))
3132 (tramp-compat-file-name-unquote (file-truename tmp-name3)))))) 3129 (tramp-compat-file-name-unquote (file-truename tmp-name3))))))
3133 3130
3134 ;; Cleanup. 3131 ;; Cleanup.
@@ -4085,7 +4082,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4085 (list (file-name-nondirectory tmp-name2)))) 4082 (list (file-name-nondirectory tmp-name2))))
4086 ;; `vc-register' has changed its arguments in Emacs 4083 ;; `vc-register' has changed its arguments in Emacs
4087 ;; 25.1. Let's skip it for older Emacsen. 4084 ;; 25.1. Let's skip it for older Emacsen.
4088 (error (skip-unless (>= emacs-major-version 25)))) 4085 (error (skip-unless (tramp--test-emacs25-p))))
4089 ;; vc-git uses an own process sentinel, Tramp's sentinel 4086 ;; vc-git uses an own process sentinel, Tramp's sentinel
4090 ;; for flushing the cache isn't used. 4087 ;; for flushing the cache isn't used.
4091 (dired-uncache (concat (file-remote-p default-directory) "/")) 4088 (dired-uncache (concat (file-remote-p default-directory) "/"))
@@ -4332,6 +4329,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4332 (delete-directory tmp-file) 4329 (delete-directory tmp-file)
4333 (should-not (file-exists-p tmp-file)))) 4330 (should-not (file-exists-p tmp-file))))
4334 4331
4332(defun tramp--test-emacs25-p ()
4333 "Check for Emacs version >= 25.1.
4334Some semantics has been changed for there, w/o new functions or
4335variables, so we check the Emacs version directly."
4336 (>= emacs-major-version 25))
4337
4335(defun tramp--test-emacs26-p () 4338(defun tramp--test-emacs26-p ()
4336 "Check for Emacs version >= 26.1. 4339 "Check for Emacs version >= 26.1.
4337Some semantics has been changed for there, w/o new functions or 4340Some semantics has been changed for there, w/o new functions or