diff options
| -rw-r--r-- | lisp/files.el | 22 | ||||
| -rw-r--r-- | test/lisp/files-tests.el | 401 |
2 files changed, 418 insertions, 5 deletions
diff --git a/lisp/files.el b/lisp/files.el index 75d3b7b1e72..e884a3acc18 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -6998,7 +6998,7 @@ only these files will be asked to be saved." | |||
| 6998 | ;; Bug#25949. | 6998 | ;; Bug#25949. |
| 6999 | (if (memq operation | 6999 | (if (memq operation |
| 7000 | '(insert-directory process-file start-file-process | 7000 | '(insert-directory process-file start-file-process |
| 7001 | shell-command)) | 7001 | shell-command temporary-file-directory)) |
| 7002 | (directory-file-name | 7002 | (directory-file-name |
| 7003 | (expand-file-name | 7003 | (expand-file-name |
| 7004 | (unhandled-file-name-directory default-directory))) | 7004 | (unhandled-file-name-directory default-directory))) |
| @@ -7022,15 +7022,23 @@ only these files will be asked to be saved." | |||
| 7022 | ;; temporarily to unquoted filename. | 7022 | ;; temporarily to unquoted filename. |
| 7023 | (verify-visited-file-modtime unquote-then-quote) | 7023 | (verify-visited-file-modtime unquote-then-quote) |
| 7024 | ;; List the arguments which are filenames. | 7024 | ;; List the arguments which are filenames. |
| 7025 | (file-name-completion 1) | 7025 | (file-name-completion 0 1) |
| 7026 | (file-name-all-completions 1) | 7026 | (file-name-all-completions 0 1) |
| 7027 | (file-equal-p 0 1) | ||
| 7028 | (file-newer-than-file-p 0 1) | ||
| 7027 | (write-region 2 5) | 7029 | (write-region 2 5) |
| 7028 | (rename-file 0 1) | 7030 | (rename-file 0 1) |
| 7029 | (copy-file 0 1) | 7031 | (copy-file 0 1) |
| 7030 | (copy-directory 0 1) | 7032 | (copy-directory 0 1) |
| 7031 | (file-in-directory-p 0 1) | 7033 | (file-in-directory-p 0 1) |
| 7032 | (make-symbolic-link 0 1) | 7034 | (make-symbolic-link 0 1) |
| 7033 | (add-name-to-file 0 1)))) | 7035 | (add-name-to-file 0 1) |
| 7036 | (make-auto-save-file-name buffer-file-name) | ||
| 7037 | (set-visited-file-modtime buffer-file-name) | ||
| 7038 | ;; These file-notify-* operations take a | ||
| 7039 | ;; descriptor. | ||
| 7040 | (file-notify-rm-watch . nil) | ||
| 7041 | (file-notify-valid-p . nil)))) | ||
| 7034 | ;; For all other operations, treat the first argument only | 7042 | ;; For all other operations, treat the first argument only |
| 7035 | ;; as the file name. | 7043 | ;; as the file name. |
| 7036 | '(nil 0)))) | 7044 | '(nil 0)))) |
| @@ -7053,6 +7061,12 @@ only these files will be asked to be saved." | |||
| 7053 | (pcase method | 7061 | (pcase method |
| 7054 | (`identity (car arguments)) | 7062 | (`identity (car arguments)) |
| 7055 | (`add (file-name-quote (apply operation arguments))) | 7063 | (`add (file-name-quote (apply operation arguments))) |
| 7064 | (`buffer-file-name | ||
| 7065 | (let ((buffer-file-name | ||
| 7066 | (if (string-match "\\`/:" buffer-file-name) | ||
| 7067 | (substring buffer-file-name (match-end 0)) | ||
| 7068 | buffer-file-name))) | ||
| 7069 | (apply operation arguments))) | ||
| 7056 | (`insert-file-contents | 7070 | (`insert-file-contents |
| 7057 | (let ((visit (nth 1 arguments))) | 7071 | (let ((visit (nth 1 arguments))) |
| 7058 | (unwind-protect | 7072 | (unwind-protect |
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 8dbfc2965ca..abd3155141b 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el | |||
| @@ -21,6 +21,10 @@ | |||
| 21 | 21 | ||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'nadvice) | 23 | (require 'nadvice) |
| 24 | (eval-when-compile (require 'cl-lib)) | ||
| 25 | (require 'bytecomp) ; `byte-compiler-base-file-name'. | ||
| 26 | (require 'dired) ; `dired-uncache'. | ||
| 27 | (require 'filenotify) ; `file-notify-add-watch'. | ||
| 24 | 28 | ||
| 25 | ;; Set to t if the local variable was set, `query' if the query was | 29 | ;; Set to t if the local variable was set, `query' if the query was |
| 26 | ;; triggered. | 30 | ;; triggered. |
| @@ -279,7 +283,7 @@ be $HOME." | |||
| 279 | (advice-remove #',symbol ,function))))) | 283 | (advice-remove #',symbol ,function))))) |
| 280 | 284 | ||
| 281 | (defmacro files-tests--with-temp-file (name &rest body) | 285 | (defmacro files-tests--with-temp-file (name &rest body) |
| 282 | (declare (indent 1)) | 286 | (declare (indent 1) (debug (symbolp body))) |
| 283 | (cl-check-type name symbol) | 287 | (cl-check-type name symbol) |
| 284 | `(let ((,name (make-temp-file "emacs"))) | 288 | `(let ((,name (make-temp-file "emacs"))) |
| 285 | (unwind-protect | 289 | (unwind-protect |
| @@ -327,6 +331,401 @@ be invoked with the right arguments." | |||
| 327 | `((verify-visited-file-modtime ,buffer-visiting-file) | 331 | `((verify-visited-file-modtime ,buffer-visiting-file) |
| 328 | (verify-visited-file-modtime nil)))))))) | 332 | (verify-visited-file-modtime nil)))))))) |
| 329 | 333 | ||
| 334 | (cl-defmacro files-tests--with-temp-non-special | ||
| 335 | ((name non-special-name &optional dir-flag) &rest body) | ||
| 336 | (declare (indent 1) (debug ((symbolp symbolp &optional form) body))) | ||
| 337 | (cl-check-type name symbol) | ||
| 338 | (cl-check-type non-special-name symbol) | ||
| 339 | `(let* ((,name (make-temp-file "files-tests" ,dir-flag)) | ||
| 340 | (,non-special-name (concat "/:" ,name))) | ||
| 341 | (unwind-protect | ||
| 342 | (progn ,@body) | ||
| 343 | (when (file-exists-p ,name) | ||
| 344 | (if ,dir-flag (delete-directory ,name t) | ||
| 345 | (delete-file ,name)))))) | ||
| 346 | |||
| 347 | (ert-deftest files-tests-file-name-non-special-access-file () | ||
| 348 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 349 | (should (null (access-file nospecial "test"))))) | ||
| 350 | |||
| 351 | (ert-deftest files-tests-file-name-non-special-add-name-to-file () | ||
| 352 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 353 | (let ((newname (concat nospecial "add-name"))) | ||
| 354 | (add-name-to-file nospecial newname) | ||
| 355 | (should (file-exists-p newname)) | ||
| 356 | (delete-file newname)))) | ||
| 357 | |||
| 358 | (ert-deftest files-tests-file-name-non-special-byte-compiler-base-file-name () | ||
| 359 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 360 | (should (equal (byte-compiler-base-file-name nospecial) | ||
| 361 | (byte-compiler-base-file-name tmpfile))))) | ||
| 362 | |||
| 363 | (ert-deftest files-tests-file-name-non-special-copy-directory () | ||
| 364 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 365 | (let ((newname (concat (directory-file-name nospecial-dir) | ||
| 366 | "copy-dir"))) | ||
| 367 | (copy-directory nospecial-dir newname) | ||
| 368 | (should (file-directory-p newname)) | ||
| 369 | (delete-directory newname) | ||
| 370 | (should-not (file-directory-p newname))))) | ||
| 371 | |||
| 372 | (ert-deftest files-tests-file-name-non-special-copy-file () | ||
| 373 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 374 | (let ((newname (concat (directory-file-name nospecial) | ||
| 375 | "copy-file"))) | ||
| 376 | (copy-file nospecial newname) | ||
| 377 | (should (file-exists-p newname)) | ||
| 378 | (delete-file newname) | ||
| 379 | (should-not (file-exists-p newname))))) | ||
| 380 | |||
| 381 | (ert-deftest files-tests-file-name-non-special-delete-directory () | ||
| 382 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 383 | (delete-directory nospecial-dir))) | ||
| 384 | |||
| 385 | (ert-deftest files-tests-file-name-non-special-delete-file () | ||
| 386 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 387 | (delete-file nospecial))) | ||
| 388 | |||
| 389 | (ert-deftest files-tests-file-name-non-special-diff-latest-backup-file () | ||
| 390 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 391 | (should (equal (diff-latest-backup-file nospecial) | ||
| 392 | (diff-latest-backup-file tmpfile))))) | ||
| 393 | |||
| 394 | (ert-deftest files-tests-file-name-non-special-directory-file-name () | ||
| 395 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 396 | (should (equal (directory-file-name nospecial-dir) | ||
| 397 | (concat "/:" (directory-file-name tmpdir)))))) | ||
| 398 | |||
| 399 | (ert-deftest files-tests-file-name-non-special-directory-files () | ||
| 400 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 401 | (should (equal (directory-files nospecial-dir) | ||
| 402 | (directory-files tmpdir))))) | ||
| 403 | |||
| 404 | (ert-deftest files-tests-file-name-non-special-directory-files-and-attributes () | ||
| 405 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 406 | (should (equal (directory-files-and-attributes nospecial-dir) | ||
| 407 | (directory-files-and-attributes tmpdir))))) | ||
| 408 | |||
| 409 | (ert-deftest files-tests-file-name-non-special-dired-compress-handler () | ||
| 410 | ;; `dired-compress-file' can get confused by filenames with ":" in | ||
| 411 | ;; them, which causes this to fail on `windows-nt' systems. | ||
| 412 | (when (string-match-p ":" (expand-file-name temporary-file-directory)) | ||
| 413 | (ert-skip "FIXME: `dired-compress-file' unreliable when filenames contain `:'.")) | ||
| 414 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 415 | (let ((compressed (dired-compress-file nospecial))) | ||
| 416 | (when compressed | ||
| 417 | ;; FIXME: Should it return a still-quoted name? | ||
| 418 | (should (file-equal-p nospecial (dired-compress-file compressed))))))) | ||
| 419 | |||
| 420 | (ert-deftest files-tests-file-name-non-special-dired-uncache () | ||
| 421 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 422 | (dired-uncache nospecial-dir))) | ||
| 423 | |||
| 424 | (ert-deftest files-tests-file-name-non-special-expand-file-name () | ||
| 425 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 426 | (should (equal (expand-file-name nospecial) nospecial)))) | ||
| 427 | |||
| 428 | (ert-deftest files-tests-file-name-non-special-file-accessible-directory-p () | ||
| 429 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 430 | (should (file-accessible-directory-p nospecial-dir)))) | ||
| 431 | |||
| 432 | (ert-deftest files-tests-file-name-non-special-file-acl () | ||
| 433 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 434 | (should (equal (file-acl nospecial) (file-acl tmpfile))))) | ||
| 435 | |||
| 436 | (ert-deftest files-tests-file-name-non-special-file-attributes () | ||
| 437 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 438 | (should (equal (file-attributes nospecial) (file-attributes tmpfile))))) | ||
| 439 | |||
| 440 | (ert-deftest files-tests-file-name-non-special-file-directory-p () | ||
| 441 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 442 | (should (file-directory-p nospecial-dir)))) | ||
| 443 | |||
| 444 | (ert-deftest files-tests-file-name-non-special-file-equal-p () | ||
| 445 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 446 | (should (file-equal-p nospecial tmpfile)) | ||
| 447 | (should (file-equal-p tmpfile nospecial)) | ||
| 448 | (should (file-equal-p nospecial nospecial)))) | ||
| 449 | |||
| 450 | (ert-deftest files-tests-file-name-non-special-file-executable-p () | ||
| 451 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 452 | (should-not (file-executable-p nospecial)))) | ||
| 453 | |||
| 454 | (ert-deftest files-tests-file-name-non-special-file-exists-p () | ||
| 455 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 456 | (should (file-exists-p nospecial)))) | ||
| 457 | |||
| 458 | (ert-deftest files-tests-file-name-non-special-file-in-directory-p () | ||
| 459 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 460 | (let ((nospecial-tempdir (concat "/:" temporary-file-directory))) | ||
| 461 | (should (file-in-directory-p nospecial temporary-file-directory)) | ||
| 462 | (should (file-in-directory-p tmpfile nospecial-tempdir)) | ||
| 463 | (should (file-in-directory-p nospecial nospecial-tempdir))))) | ||
| 464 | |||
| 465 | (ert-deftest files-tests-file-name-non-special-file-local-copy () | ||
| 466 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 467 | (should-not (file-local-copy nospecial)))) ; Already local. | ||
| 468 | |||
| 469 | (ert-deftest files-tests-file-name-non-special-file-modes () | ||
| 470 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 471 | (should (equal (file-modes nospecial) (file-modes tmpfile))))) | ||
| 472 | |||
| 473 | (ert-deftest files-tests-file-name-non-special-file-name-all-completions () | ||
| 474 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 475 | (let ((nospecial-tempdir (concat "/:" temporary-file-directory)) | ||
| 476 | (tmpdir temporary-file-directory)) | ||
| 477 | (should (equal (file-name-all-completions nospecial nospecial-tempdir) | ||
| 478 | (file-name-all-completions tmpfile tmpdir))) | ||
| 479 | (should (equal (file-name-all-completions tmpfile nospecial-tempdir) | ||
| 480 | (file-name-all-completions tmpfile tmpdir))) | ||
| 481 | (should (equal (file-name-all-completions nospecial tmpdir) | ||
| 482 | (file-name-all-completions tmpfile tmpdir)))))) | ||
| 483 | |||
| 484 | (ert-deftest files-tests-file-name-non-special-file-name-as-directory () | ||
| 485 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 486 | (should (equal (file-name-as-directory nospecial-dir) | ||
| 487 | (concat "/:" (file-name-as-directory tmpdir)))))) | ||
| 488 | |||
| 489 | (ert-deftest files-tests-file-name-non-special-file-name-case-insensitive-p () | ||
| 490 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 491 | (should (equal (file-name-case-insensitive-p nospecial) | ||
| 492 | (file-name-case-insensitive-p tmpfile))))) | ||
| 493 | |||
| 494 | (ert-deftest files-tests-file-name-non-special-file-name-completion () | ||
| 495 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 496 | (let ((nospecial-tempdir (concat "/:" temporary-file-directory)) | ||
| 497 | (tmpdir temporary-file-directory)) | ||
| 498 | (should (equal (file-name-completion nospecial nospecial-tempdir) | ||
| 499 | (file-name-completion tmpfile tmpdir))) | ||
| 500 | (should (equal (file-name-completion tmpfile nospecial-tempdir) | ||
| 501 | (file-name-completion tmpfile tmpdir))) | ||
| 502 | (should (equal (file-name-completion nospecial tmpdir) | ||
| 503 | (file-name-completion tmpfile tmpdir)))))) | ||
| 504 | |||
| 505 | (ert-deftest files-tests-file-name-non-special-file-name-directory () | ||
| 506 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 507 | (should (equal (file-name-directory nospecial) | ||
| 508 | (concat "/:" temporary-file-directory))))) | ||
| 509 | |||
| 510 | (ert-deftest files-tests-file-name-non-special-file-name-nondirectory () | ||
| 511 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 512 | (should (equal (file-name-nondirectory nospecial) | ||
| 513 | (file-name-nondirectory tmpfile))))) | ||
| 514 | |||
| 515 | (ert-deftest files-tests-file-name-non-special-file-name-sans-versions () | ||
| 516 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 517 | (should (equal (file-name-sans-versions nospecial) nospecial)))) | ||
| 518 | |||
| 519 | (ert-deftest files-tests-file-name-non-special-file-newer-than-file-p () | ||
| 520 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 521 | (should-not (file-newer-than-file-p nospecial tmpfile)) | ||
| 522 | (should-not (file-newer-than-file-p tmpfile nospecial)) | ||
| 523 | (should-not (file-newer-than-file-p nospecial nospecial)))) | ||
| 524 | |||
| 525 | (ert-deftest files-file-name-non-special-notify-handlers () | ||
| 526 | :expected-result :failed | ||
| 527 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 528 | (let ((watch (file-notify-add-watch nospecial '(change) #'ignore))) | ||
| 529 | (should (file-notify-valid-p watch)) | ||
| 530 | (file-notify-rm-watch watch) | ||
| 531 | (should-not (file-notify-valid-p watch))))) | ||
| 532 | |||
| 533 | (ert-deftest files-tests-file-name-non-special-file-ownership-preserved-p () | ||
| 534 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 535 | (should (equal (file-ownership-preserved-p nospecial) | ||
| 536 | (file-ownership-preserved-p tmpfile))))) | ||
| 537 | |||
| 538 | (ert-deftest files-tests-file-name-non-special-file-readable-p () | ||
| 539 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 540 | (should (file-readable-p nospecial)))) | ||
| 541 | |||
| 542 | (ert-deftest files-tests-file-name-non-special-file-regular-p () | ||
| 543 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 544 | (should (file-regular-p nospecial)))) | ||
| 545 | |||
| 546 | (ert-deftest files-tests-file-name-non-special-file-remote-p () | ||
| 547 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 548 | (should-not (file-remote-p nospecial)))) | ||
| 549 | |||
| 550 | (ert-deftest files-tests-file-name-non-special-file-selinux-context () | ||
| 551 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 552 | (should (equal (file-selinux-context nospecial) | ||
| 553 | (file-selinux-context tmpfile))))) | ||
| 554 | |||
| 555 | (ert-deftest files-tests-file-name-non-special-file-symlink-p () | ||
| 556 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 557 | (should-not (file-symlink-p nospecial)))) | ||
| 558 | |||
| 559 | (ert-deftest files-tests-file-name-non-special-file-truename () | ||
| 560 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 561 | (should (equal nospecial (file-truename nospecial))))) | ||
| 562 | |||
| 563 | (ert-deftest files-tests-file-name-non-special-file-writable-p () | ||
| 564 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 565 | (should (file-writable-p nospecial)))) | ||
| 566 | |||
| 567 | (ert-deftest files-tests-file-name-non-special-find-backup-file-name () | ||
| 568 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 569 | (should (equal (find-backup-file-name nospecial) | ||
| 570 | (mapcar (lambda (f) (concat "/:" f)) | ||
| 571 | (find-backup-file-name tmpfile)))))) | ||
| 572 | |||
| 573 | (ert-deftest files-tests-file-name-non-special-get-file-buffer () | ||
| 574 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 575 | (should-not (get-file-buffer nospecial)))) | ||
| 576 | |||
| 577 | (ert-deftest files-tests-file-name-non-special-insert-directory () | ||
| 578 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 579 | (should (equal (with-temp-buffer | ||
| 580 | (insert-directory nospecial-dir "") | ||
| 581 | (buffer-string)) | ||
| 582 | (with-temp-buffer | ||
| 583 | (insert-directory tmpdir "") | ||
| 584 | (buffer-string)))))) | ||
| 585 | |||
| 586 | (ert-deftest files-tests-file-name-non-special-insert-file-contents () | ||
| 587 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 588 | (with-temp-buffer | ||
| 589 | (insert-file-contents nospecial) | ||
| 590 | (should (zerop (buffer-size)))))) | ||
| 591 | |||
| 592 | (ert-deftest files-tests-file-name-non-special-load () | ||
| 593 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 594 | (should (load nospecial nil t)))) | ||
| 595 | |||
| 596 | (ert-deftest files-tests-file-name-non-special-make-auto-save-file-name () | ||
| 597 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 598 | (save-current-buffer | ||
| 599 | (should (equal (prog2 (set-buffer (find-file-noselect nospecial)) | ||
| 600 | (make-auto-save-file-name) | ||
| 601 | (kill-buffer)) | ||
| 602 | (prog2 (set-buffer (find-file-noselect tmpfile)) | ||
| 603 | (make-auto-save-file-name) | ||
| 604 | (kill-buffer))))))) | ||
| 605 | |||
| 606 | (ert-deftest files-tests-file-name-non-special-make-directory () | ||
| 607 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 608 | (let ((default-directory nospecial-dir)) | ||
| 609 | (make-directory "dir") | ||
| 610 | (should (file-directory-p "dir")) | ||
| 611 | (delete-directory "dir")))) | ||
| 612 | |||
| 613 | (ert-deftest files-tests-file-name-non-special-make-directory-internal () | ||
| 614 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 615 | (let ((default-directory nospecial-dir)) | ||
| 616 | (make-directory-internal "dir") | ||
| 617 | (should (file-directory-p "dir")) | ||
| 618 | (delete-directory "dir")))) | ||
| 619 | |||
| 620 | (ert-deftest files-tests-file-name-non-special-make-nearby-temp-file () | ||
| 621 | (let* ((default-directory (concat "/:" temporary-file-directory)) | ||
| 622 | (near-tmpfile (make-nearby-temp-file "file"))) | ||
| 623 | (should (file-exists-p near-tmpfile)) | ||
| 624 | (delete-file near-tmpfile))) | ||
| 625 | |||
| 626 | (ert-deftest files-tests-file-name-non-special-make-symbolic-link () | ||
| 627 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 628 | (files-tests--with-temp-non-special (tmpfile _nospecial) | ||
| 629 | (let* ((linkname (expand-file-name "link" tmpdir)) | ||
| 630 | (may-symlink (ignore-errors (make-symbolic-link tmpfile linkname) | ||
| 631 | t))) | ||
| 632 | (when may-symlink | ||
| 633 | (should (file-symlink-p linkname)) | ||
| 634 | (delete-file linkname) | ||
| 635 | (let ((linkname (expand-file-name "link" nospecial-dir))) | ||
| 636 | (make-symbolic-link tmpfile linkname) | ||
| 637 | (should (file-symlink-p linkname)) | ||
| 638 | (delete-file linkname))))))) | ||
| 639 | |||
| 640 | ;; See `files-tests--file-name-non-special--subprocess'. | ||
| 641 | ;; (ert-deftest files-tests-file-name-non-special-process-file ()) | ||
| 642 | |||
| 643 | (ert-deftest files-tests-file-name-non-special-rename-file () | ||
| 644 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 645 | (rename-file nospecial (concat nospecial "x")) | ||
| 646 | (rename-file (concat nospecial "x") nospecial) | ||
| 647 | (rename-file tmpfile (concat nospecial "x")) | ||
| 648 | (rename-file (concat nospecial "x") nospecial) | ||
| 649 | (rename-file nospecial (concat tmpfile "x")) | ||
| 650 | (rename-file (concat nospecial "x") nospecial))) | ||
| 651 | |||
| 652 | (ert-deftest files-tests-file-name-non-special-set-file-acl () | ||
| 653 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 654 | (set-file-acl nospecial (file-acl nospecial)))) | ||
| 655 | |||
| 656 | (ert-deftest files-tests-file-name-non-special-set-file-modes () | ||
| 657 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 658 | (set-file-modes nospecial (file-modes nospecial)))) | ||
| 659 | |||
| 660 | (ert-deftest files-tests-file-name-non-special-set-file-selinux-context () | ||
| 661 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 662 | (set-file-selinux-context nospecial (file-selinux-context nospecial)))) | ||
| 663 | |||
| 664 | (ert-deftest files-tests-file-name-non-special-set-file-times () | ||
| 665 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 666 | (set-file-times nospecial))) | ||
| 667 | |||
| 668 | (ert-deftest files-tests-file-name-non-special-set-visited-file-modtime () | ||
| 669 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 670 | (save-current-buffer | ||
| 671 | (set-buffer (find-file-noselect nospecial)) | ||
| 672 | (set-visited-file-modtime) | ||
| 673 | (kill-buffer)))) | ||
| 674 | |||
| 675 | (ert-deftest files-tests-file-name-non-special-shell-command () | ||
| 676 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 677 | (with-temp-buffer | ||
| 678 | (let ((default-directory nospecial-dir)) | ||
| 679 | (shell-command (concat (shell-quote-argument | ||
| 680 | (concat invocation-directory invocation-name)) | ||
| 681 | " --version") | ||
| 682 | (current-buffer)) | ||
| 683 | (goto-char (point-min)) | ||
| 684 | (should (search-forward emacs-version nil t)))))) | ||
| 685 | |||
| 686 | (ert-deftest files-tests-file-name-non-special-start-file-process () | ||
| 687 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 688 | (with-temp-buffer | ||
| 689 | (let ((default-directory nospecial-dir)) | ||
| 690 | (let ((proc (start-file-process | ||
| 691 | "emacs" (current-buffer) | ||
| 692 | (concat invocation-directory invocation-name) | ||
| 693 | "--version"))) | ||
| 694 | (accept-process-output proc) | ||
| 695 | (goto-char (point-min)) | ||
| 696 | (should (search-forward emacs-version nil t)) | ||
| 697 | ;; Don't stop the test run with a query, as the subprocess | ||
| 698 | ;; may or may not be dead by the time we reach here. | ||
| 699 | (set-process-query-on-exit-flag proc nil)))))) | ||
| 700 | |||
| 701 | (ert-deftest files-tests-file-name-non-special-substitute-in-file-name () | ||
| 702 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 703 | (let ((process-environment (cons "FOO=foo" process-environment)) | ||
| 704 | (nospecial-foo (concat nospecial "$FOO"))) | ||
| 705 | ;; The "/:" prevents substitution. | ||
| 706 | (equal (substitute-in-file-name nospecial-foo) nospecial-foo)))) | ||
| 707 | (ert-deftest files-tests-file-name-non-special-temporary-file-directory () | ||
| 708 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 709 | (let ((default-directory nospecial-dir)) | ||
| 710 | (equal (temporary-file-directory) temporary-file-directory)))) | ||
| 711 | |||
| 712 | (ert-deftest files-tests-file-name-non-special-unhandled-file-name-directory () | ||
| 713 | (files-tests--with-temp-non-special (tmpdir nospecial-dir t) | ||
| 714 | (equal (unhandled-file-name-directory nospecial-dir) | ||
| 715 | (file-name-as-directory tmpdir)))) | ||
| 716 | |||
| 717 | (ert-deftest files-tests-file-name-non-special-vc-registered () | ||
| 718 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 719 | (should (equal (vc-registered nospecial) (vc-registered tmpfile))))) | ||
| 720 | |||
| 721 | ;; See test `files-tests--file-name-non-special--buffers'. | ||
| 722 | ;; (ert-deftest files-tests-file-name-non-special-verify-visited-file-modtime ()) | ||
| 723 | |||
| 724 | (ert-deftest files-tests-file-name-non-special-write-region () | ||
| 725 | (files-tests--with-temp-non-special (tmpfile nospecial) | ||
| 726 | (with-temp-buffer | ||
| 727 | (write-region nil nil nospecial nil :visit)))) | ||
| 728 | |||
| 330 | (ert-deftest files-tests--insert-directory-wildcard-in-dir-p () | 729 | (ert-deftest files-tests--insert-directory-wildcard-in-dir-p () |
| 331 | (let ((alist (list (cons "/home/user/*/.txt" (cons "/home/user/" "*/.txt")) | 730 | (let ((alist (list (cons "/home/user/*/.txt" (cons "/home/user/" "*/.txt")) |
| 332 | (cons "/home/user/.txt" nil) | 731 | (cons "/home/user/.txt" nil) |