1 ;;; tramp-archive-tests.el --- Tests of file archive access -*- lexical-binding:t -*-
3 ;; Copyright (C) 2017-2018 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `https://www.gnu.org/licenses/'.
22 ;; The `tramp-archive-testnn-*' tests correspond to the respective
23 ;; tests in tramp-tests.el.
26 (require 'tramp-archive
)
28 (defconst tramp-archive-test-resource-directory
29 (let ((default-directory
31 (file-name-directory load-file-name
)
34 ((file-accessible-directory-p (expand-file-name "resources"))
35 (expand-file-name "resources"))
36 ((file-accessible-directory-p (expand-file-name "tramp-archive-resources"))
37 (expand-file-name "tramp-archive-resources"))))
38 "The resources directory test files are located in.")
40 (defconst tramp-archive-test-file-archive
42 (expand-file-name "foo.tar.gz" tramp-archive-test-resource-directory
))
43 "The test file archive.")
45 (defconst tramp-archive-test-archive
46 (file-name-as-directory tramp-archive-test-file-archive
)
49 (defconst tramp-archive-test-directory
51 (expand-file-name "foo.iso" tramp-archive-test-resource-directory
))
52 "A directory file name, which looks like an archive.")
54 (setq password-cache-expiry nil
56 tramp-cache-read-persistent-data t
;; For auth-sources.
57 tramp-copy-size-limit nil
58 tramp-message-show-message nil
59 tramp-persistency-file-name nil
)
61 (defun tramp-archive--test-make-temp-name ()
62 "Return a temporary file name for test.
63 The temporary file is not created."
65 (make-temp-name "tramp-archive-test") temporary-file-directory
))
67 (defun tramp-archive--test-delete (tmpfile)
68 "Delete temporary file or directory TMPFILE.
69 This needs special support, because archive file names, which are
70 the origin of the temporary TMPFILE, have no write permissions."
71 (unless (file-writable-p (file-name-directory tmpfile
))
73 (file-name-directory tmpfile
)
74 (logior (file-modes (file-name-directory tmpfile
)) #o0700
)))
75 (set-file-modes tmpfile
#o0700
)
76 (if (file-regular-p tmpfile
)
79 'tramp-archive--test-delete
80 (directory-files tmpfile
'full directory-files-no-dot-files-regexp
))
81 (delete-directory tmpfile
)))
83 (defun tramp-archive--test-emacs26-p ()
84 "Check for Emacs version >= 26.1.
85 Some semantics has been changed for there, w/o new functions or
86 variables, so we check the Emacs version directly."
87 (>= emacs-major-version
26))
89 (defun tramp-archive--test-emacs27-p ()
90 "Check for Emacs version >= 27.1.
91 Some semantics has been changed for there, w/o new functions or
92 variables, so we check the Emacs version directly."
93 (>= emacs-major-version
27))
95 (ert-deftest tramp-archive-test00-availability
()
96 "Test availability of archive file name functions."
97 :expected-result
(if tramp-archive-enabled
:passed
:failed
)
100 tramp-archive-enabled
101 (file-exists-p tramp-archive-test-file-archive
)
102 (tramp-archive-file-name-p tramp-archive-test-archive
))))
104 (ert-deftest tramp-archive-test01-file-name-syntax
()
105 "Check archive file name syntax."
106 (should-not (tramp-archive-file-name-p tramp-archive-test-file-archive
))
107 (should (tramp-archive-file-name-p tramp-archive-test-archive
))
110 (tramp-archive-file-name-archive tramp-archive-test-archive
)
111 tramp-archive-test-file-archive
))
114 (tramp-archive-file-name-localname tramp-archive-test-archive
) "/"))
115 (should (tramp-archive-file-name-p (concat tramp-archive-test-archive
"foo")))
118 (tramp-archive-file-name-localname
119 (concat tramp-archive-test-archive
"foo"))
122 (tramp-archive-file-name-p (concat tramp-archive-test-archive
"foo/bar")))
125 (tramp-archive-file-name-localname
126 (concat tramp-archive-test-archive
"foo/bar"))
128 ;; A file archive inside a file archive.
130 (tramp-archive-file-name-p (concat tramp-archive-test-archive
"baz.tar")))
133 (tramp-archive-file-name-archive
134 (concat tramp-archive-test-archive
"baz.tar"))
135 tramp-archive-test-file-archive
))
138 (tramp-archive-file-name-localname
139 (concat tramp-archive-test-archive
"baz.tar"))
142 (tramp-archive-file-name-p (concat tramp-archive-test-archive
"baz.tar/")))
145 (tramp-archive-file-name-archive
146 (concat tramp-archive-test-archive
"baz.tar/"))
147 (concat tramp-archive-test-archive
"baz.tar")))
150 (tramp-archive-file-name-localname
151 (concat tramp-archive-test-archive
"baz.tar/"))
154 (ert-deftest tramp-archive-test02-file-name-dissect
()
155 "Check archive file name components."
156 (skip-unless tramp-archive-enabled
)
158 (with-parsed-tramp-archive-file-name tramp-archive-test-archive nil
159 (should (string-equal method tramp-archive-method
))
166 (tramp-archive-gvfs-file-name tramp-archive-test-archive
) 'host
)))
170 (url-hexify-string (concat "file://" tramp-archive-test-file-archive
))))
172 (should (string-equal localname
"/"))
173 (should (string-equal archive tramp-archive-test-file-archive
)))
176 (with-parsed-tramp-archive-file-name
177 (concat tramp-archive-test-archive
"foo") nil
178 (should (string-equal method tramp-archive-method
))
185 (tramp-archive-gvfs-file-name tramp-archive-test-archive
) 'host
)))
189 (url-hexify-string (concat "file://" tramp-archive-test-file-archive
))))
191 (should (string-equal localname
"/foo"))
192 (should (string-equal archive tramp-archive-test-file-archive
)))
194 ;; File archive in file archive.
195 (let* ((tramp-archive-test-file-archive
196 (concat tramp-archive-test-archive
"baz.tar"))
197 (tramp-archive-test-archive
198 (file-name-as-directory tramp-archive-test-file-archive
))
199 (tramp-methods (cons `(,tramp-archive-method
) tramp-methods
))
200 (tramp-gvfs-methods tramp-archive-all-gvfs-methods
))
202 (with-parsed-tramp-archive-file-name
203 (expand-file-name "bar" tramp-archive-test-archive
) nil
204 (should (string-equal method tramp-archive-method
))
211 (tramp-archive-gvfs-file-name tramp-archive-test-archive
) 'host
)))
212 ;; We reimplement the logic of tramp-archive.el here. Don't
213 ;; know, whether it is worth the test.
219 (tramp-gvfs-url-file-name
220 (tramp-make-tramp-file-name
228 ;; `directory-file-name' does not leave file archive
229 ;; boundaries. So we must cut the trailing slash
232 (file-name-directory tramp-archive-test-file-archive
) 0 -
1)))
234 (file-name-nondirectory tramp-archive-test-file-archive
)))))
236 (should (string-equal localname
"/bar"))
237 (should (string-equal archive tramp-archive-test-file-archive
)))
240 (tramp-archive-cleanup-hash))))
242 (ert-deftest tramp-archive-test05-expand-file-name
()
243 "Check `expand-file-name'."
246 (expand-file-name "/foo.tar/path/./file") "/foo.tar/path/file"))
248 (string-equal (expand-file-name "/foo.tar/path/../file") "/foo.tar/file"))
249 ;; `expand-file-name' does not care "~/" in archive file names.
251 (string-equal (expand-file-name "/foo.tar/~/file") "/foo.tar/~/file"))
252 ;; `expand-file-name' does not care file archive boundaries.
253 (should (string-equal (expand-file-name "/foo.tar/./file") "/foo.tar/file"))
254 (should (string-equal (expand-file-name "/foo.tar/../file") "/file")))
256 ;; This test is inspired by Bug#30293.
257 (ert-deftest tramp-archive-test05-expand-file-name-non-archive-directory
()
258 "Check existing directories with archive file name syntax.
259 They shall still be supported"
260 (should (file-directory-p tramp-archive-test-directory
))
261 ;; `tramp-archive-file-name-p' tests only for file name syntax. It
262 ;; doesn't test, whether it is really a file archive.
264 (tramp-archive-file-name-p
265 (file-name-as-directory tramp-archive-test-directory
)))
267 (file-directory-p (file-name-as-directory tramp-archive-test-directory
)))
269 (file-exists-p (expand-file-name "foo" tramp-archive-test-directory
))))
271 (ert-deftest tramp-archive-test06-directory-file-name
()
272 "Check `directory-file-name'.
273 This checks also `file-name-as-directory', `file-name-directory',
274 `file-name-nondirectory' and `unhandled-file-name-directory'."
275 (skip-unless tramp-archive-enabled
)
279 (directory-file-name "/foo.tar/path/to/file") "/foo.tar/path/to/file"))
282 (directory-file-name "/foo.tar/path/to/file/") "/foo.tar/path/to/file"))
283 ;; `directory-file-name' does not leave file archive boundaries.
284 (should (string-equal (directory-file-name "/foo.tar/") "/foo.tar/"))
288 (file-name-as-directory "/foo.tar/path/to/file") "/foo.tar/path/to/file/"))
291 (file-name-as-directory "/foo.tar/path/to/file/") "/foo.tar/path/to/file/"))
292 (should (string-equal (file-name-as-directory "/foo.tar/") "/foo.tar/"))
293 (should (string-equal (file-name-as-directory "/foo.tar") "/foo.tar/"))
297 (file-name-directory "/foo.tar/path/to/file") "/foo.tar/path/to/"))
300 (file-name-directory "/foo.tar/path/to/file/") "/foo.tar/path/to/file/"))
301 (should (string-equal (file-name-directory "/foo.tar/") "/foo.tar/"))
304 (string-equal (file-name-nondirectory "/foo.tar/path/to/file") "file"))
306 (string-equal (file-name-nondirectory "/foo.tar/path/to/file/") ""))
307 (should (string-equal (file-name-nondirectory "/foo.tar/") ""))
310 (unhandled-file-name-directory "/foo.tar/path/to/file")))
312 (ert-deftest tramp-archive-test07-file-exists-p
()
313 "Check `file-exist-p', `write-region' and `delete-file'."
314 (skip-unless tramp-archive-enabled
)
317 (let ((default-directory tramp-archive-test-archive
))
318 (should (file-exists-p tramp-archive-test-file-archive
))
319 (should (file-exists-p tramp-archive-test-archive
))
320 (should (file-exists-p "foo.txt"))
321 (should (file-exists-p "foo.lnk"))
322 (should (file-exists-p "bar"))
323 (should (file-exists-p "bar/bar"))
325 (write-region "foo" nil
"baz")
332 (tramp-archive-cleanup-hash)))
334 (ert-deftest tramp-archive-test08-file-local-copy
()
335 "Check `file-local-copy'."
336 (skip-unless tramp-archive-enabled
)
344 (expand-file-name "bar/bar" tramp-archive-test-archive
))))
346 (insert-file-contents tmp-name
)
347 (should (string-equal (buffer-string) "bar\n")))
349 (tramp-archive--test-delete tmp-name
)
353 (expand-file-name "what" tramp-archive-test-archive
)))
354 :type tramp-file-missing
))
357 (ignore-errors (tramp-archive--test-delete tmp-name
))
358 (tramp-archive-cleanup-hash))))
360 (ert-deftest tramp-archive-test09-insert-file-contents
()
361 "Check `insert-file-contents'."
362 (skip-unless tramp-archive-enabled
)
364 (let ((tmp-name (expand-file-name "bar/bar" tramp-archive-test-archive
)))
367 (insert-file-contents tmp-name
)
368 (should (string-equal (buffer-string) "bar\n"))
369 (insert-file-contents tmp-name
)
370 (should (string-equal (buffer-string) "bar\nbar\n"))
372 (insert-file-contents tmp-name nil
1 3)
373 (should (string-equal (buffer-string) "arbar\nbar\n"))
375 (insert-file-contents tmp-name nil nil nil
'replace
)
376 (should (string-equal (buffer-string) "bar\n"))
379 (insert-file-contents
380 (expand-file-name "what" tramp-archive-test-archive
))
381 :type tramp-file-missing
))
384 (tramp-archive-cleanup-hash))))
386 (ert-deftest tramp-archive-test11-copy-file
()
388 (skip-unless tramp-archive-enabled
)
391 (let ((tmp-name1 (expand-file-name "bar/bar" tramp-archive-test-archive
))
392 (tmp-name2 (tramp-archive--test-make-temp-name)))
395 (copy-file tmp-name1 tmp-name2
)
396 (should (file-exists-p tmp-name2
))
398 (insert-file-contents tmp-name2
)
399 (should (string-equal (buffer-string) "bar\n")))
401 (copy-file tmp-name1 tmp-name2
)
402 :type
'file-already-exists
)
403 (copy-file tmp-name1 tmp-name2
'ok
)
404 ;; The file archive is not writable.
406 (copy-file tmp-name2 tmp-name1
'ok
)
410 (ignore-errors (tramp-archive--test-delete tmp-name2
))
411 (tramp-archive-cleanup-hash)))
413 ;; Copy directory to existing directory.
414 (let ((tmp-name1 (expand-file-name "bar" tramp-archive-test-archive
))
415 (tmp-name2 (tramp-archive--test-make-temp-name)))
418 (make-directory tmp-name2
)
419 (should (file-directory-p tmp-name2
))
420 ;; Directory `tmp-name2' exists already, so we must use
421 ;; `file-name-as-directory'.
422 (copy-file tmp-name1
(file-name-as-directory tmp-name2
))
426 (concat (file-name-nondirectory tmp-name1
) "/bar") tmp-name2
))))
429 (ignore-errors (tramp-archive--test-delete tmp-name2
))
430 (tramp-archive-cleanup-hash)))
432 ;; Copy directory/file to non-existing directory.
433 (let ((tmp-name1 (expand-file-name "bar" tramp-archive-test-archive
))
434 (tmp-name2 (tramp-archive--test-make-temp-name)))
437 (make-directory tmp-name2
)
438 (should (file-directory-p tmp-name2
))
441 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name2
))
445 (concat (file-name-nondirectory tmp-name1
) "/bar") tmp-name2
))))
448 (ignore-errors (tramp-archive--test-delete tmp-name2
))
449 (tramp-archive-cleanup-hash))))
451 (ert-deftest tramp-archive-test15-copy-directory
()
452 "Check `copy-directory'."
453 (skip-unless tramp-archive-enabled
)
455 (let* ((tmp-name1 (expand-file-name "bar" tramp-archive-test-archive
))
456 (tmp-name2 (tramp-archive--test-make-temp-name))
457 (tmp-name3 (expand-file-name
458 (file-name-nondirectory tmp-name1
) tmp-name2
))
459 (tmp-name4 (expand-file-name "bar" tmp-name2
))
460 (tmp-name5 (expand-file-name "bar" tmp-name3
)))
462 ;; Copy complete directory.
465 ;; Copy empty directory.
466 (copy-directory tmp-name1 tmp-name2
)
467 (should (file-directory-p tmp-name2
))
468 (should (file-exists-p tmp-name4
))
469 ;; Target directory does exist already.
470 ;; This has been changed in Emacs 26.1.
471 (when (tramp-archive--test-emacs26-p)
473 (copy-directory tmp-name1 tmp-name2
)
475 (tramp-archive--test-delete tmp-name4
)
476 (copy-directory tmp-name1
(file-name-as-directory tmp-name2
))
477 (should (file-directory-p tmp-name3
))
478 (should (file-exists-p tmp-name5
)))
481 (ignore-errors (tramp-archive--test-delete tmp-name2
))
482 (tramp-archive-cleanup-hash))
484 ;; Copy directory contents.
487 ;; Copy empty directory.
488 (copy-directory tmp-name1 tmp-name2 nil
'parents
'contents
)
489 (should (file-directory-p tmp-name2
))
490 (should (file-exists-p tmp-name4
))
491 ;; Target directory does exist already.
492 (tramp-archive--test-delete tmp-name4
)
494 tmp-name1
(file-name-as-directory tmp-name2
)
495 nil
'parents
'contents
)
496 (should (file-directory-p tmp-name2
))
497 (should (file-exists-p tmp-name4
))
498 (should-not (file-directory-p tmp-name3
))
499 (should-not (file-exists-p tmp-name5
)))
502 (ignore-errors (tramp-archive--test-delete tmp-name2
))
503 (tramp-archive-cleanup-hash))))
505 (ert-deftest tramp-archive-test16-directory-files
()
506 "Check `directory-files'."
507 (skip-unless tramp-archive-enabled
)
509 (let ((tmp-name tramp-archive-test-archive
)
510 (files '("." ".." "bar" "baz.tar" "foo.hrd" "foo.lnk" "foo.txt")))
513 (should (file-directory-p tmp-name
))
514 (should (equal (directory-files tmp-name
) files
))
515 (should (equal (directory-files tmp-name
'full
)
516 (mapcar (lambda (x) (concat tmp-name x
)) files
)))
517 (should (equal (directory-files
518 tmp-name nil directory-files-no-dot-files-regexp
)
519 (delete "." (delete ".." files
))))
520 (should (equal (directory-files
521 tmp-name
'full directory-files-no-dot-files-regexp
)
522 (mapcar (lambda (x) (concat tmp-name x
))
523 (delete "." (delete ".." files
))))))
526 (tramp-archive-cleanup-hash))))
528 (ert-deftest tramp-archive-test17-insert-directory
()
529 "Check `insert-directory'."
530 (skip-unless tramp-archive-enabled
)
532 (let (;; We test for the summary line. Keyword "total" could be localized.
534 (append '("LANG=C" "LANGUAGE=C" "LC_ALL=C") process-environment
)))
537 ;; Due to Bug#29423, this works only since for Emacs 26.1.
538 (when nil
;; TODO (tramp-archive--test-emacs26-p)
540 (insert-directory tramp-archive-test-archive nil
)
541 (goto-char (point-min))
543 (looking-at-p (regexp-quote tramp-archive-test-archive
)))))
545 (insert-directory tramp-archive-test-archive
"-al")
546 (goto-char (point-min))
549 (format "^.+ %s$" (regexp-quote tramp-archive-test-archive
)))))
552 (file-name-as-directory tramp-archive-test-archive
)
553 "-al" nil
'full-directory-p
)
554 (goto-char (point-min))
558 ;; There might be a summary line.
559 "\\(total.+[[:digit:]]+\n\\)?"
560 ;; We don't know in which order the files appear.
562 "\\(.+ %s\\( ->.+\\)?\n\\)\\{%d\\}"
563 (regexp-opt (directory-files tramp-archive-test-archive
))
564 (length (directory-files tramp-archive-test-archive
))))))))
567 (tramp-archive-cleanup-hash))))
569 (ert-deftest tramp-archive-test18-file-attributes
()
570 "Check `file-attributes'.
571 This tests also `file-readable-p' and `file-regular-p'."
572 (skip-unless tramp-archive-enabled
)
574 (let ((tmp-name1 (expand-file-name "foo.txt" tramp-archive-test-archive
))
575 (tmp-name2 (expand-file-name "foo.lnk" tramp-archive-test-archive
))
576 (tmp-name3 (expand-file-name "bar" tramp-archive-test-archive
))
580 (should (file-exists-p tmp-name1
))
581 (should (file-readable-p tmp-name1
))
582 (should (file-regular-p tmp-name1
))
584 ;; We do not test inodes and device numbers.
585 (setq attr
(file-attributes tmp-name1
))
586 (should (consp attr
))
587 (should (null (car attr
)))
588 (should (numberp (nth 1 attr
))) ;; Link.
589 (should (numberp (nth 2 attr
))) ;; Uid.
590 (should (numberp (nth 3 attr
))) ;; Gid.
592 (should (stringp (current-time-string (nth 4 attr
))))
593 ;; Last modification time.
594 (should (stringp (current-time-string (nth 5 attr
))))
595 ;; Last status change time.
596 (should (stringp (current-time-string (nth 6 attr
))))
597 (should (numberp (nth 7 attr
))) ;; Size.
598 (should (stringp (nth 8 attr
))) ;; Modes.
600 (setq attr
(file-attributes tmp-name1
'string
))
601 (should (stringp (nth 2 attr
))) ;; Uid.
602 (should (stringp (nth 3 attr
))) ;; Gid.
605 (should (file-exists-p tmp-name2
))
606 (should (file-symlink-p tmp-name2
))
607 (setq attr
(file-attributes tmp-name2
))
608 (should (string-equal (car attr
) (file-name-nondirectory tmp-name1
)))
611 (should (file-exists-p tmp-name3
))
612 (should (file-readable-p tmp-name3
))
613 (should-not (file-regular-p tmp-name3
))
614 (setq attr
(file-attributes tmp-name3
))
615 (should (eq (car attr
) t
)))
618 (tramp-archive-cleanup-hash))))
620 (ert-deftest tramp-archive-test19-directory-files-and-attributes
()
621 "Check `directory-files-and-attributes'."
622 (skip-unless tramp-archive-enabled
)
624 (let ((tmp-name (expand-file-name "bar" tramp-archive-test-archive
))
628 (should (file-directory-p tmp-name
))
629 (setq attr
(directory-files-and-attributes tmp-name
))
630 (should (consp attr
))
633 (equal (file-attributes (expand-file-name (car elt
) tmp-name
))
635 (setq attr
(directory-files-and-attributes tmp-name
'full
))
637 (should (equal (file-attributes (car elt
)) (cdr elt
))))
638 (setq attr
(directory-files-and-attributes tmp-name nil
"^b"))
639 (should (equal (mapcar 'car attr
) '("bar"))))
642 (tramp-archive-cleanup-hash))))
644 (ert-deftest tramp-archive-test20-file-modes
()
646 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
647 (skip-unless tramp-archive-enabled
)
649 (let ((tmp-name1 (expand-file-name "foo.txt" tramp-archive-test-archive
))
650 (tmp-name2 (expand-file-name "bar" tramp-archive-test-archive
)))
653 (should (file-exists-p tmp-name1
))
654 ;; `set-file-modes' is not implemented.
656 (set-file-modes tmp-name1
#o777
)
658 (should (= (file-modes tmp-name1
) #o400
))
659 (should-not (file-executable-p tmp-name1
))
660 (should-not (file-writable-p tmp-name1
))
662 (should (file-exists-p tmp-name2
))
663 ;; `set-file-modes' is not implemented.
665 (set-file-modes tmp-name2
#o777
)
667 (should (= (file-modes tmp-name2
) #o500
))
668 (should (file-executable-p tmp-name2
))
669 (should-not (file-writable-p tmp-name2
)))
672 (tramp-archive-cleanup-hash))))
674 (ert-deftest tramp-archive-test21-file-links
()
675 "Check `file-symlink-p' and `file-truename'"
676 (skip-unless tramp-archive-enabled
)
678 ;; We must use `file-truename' for the file archive, because it
679 ;; could be located on a symlinked directory. This would let the
681 (let* ((tramp-archive-test-archive (file-truename tramp-archive-test-archive
))
682 (tmp-name1 (expand-file-name "foo.txt" tramp-archive-test-archive
))
683 (tmp-name2 (expand-file-name "foo.lnk" tramp-archive-test-archive
)))
687 (should (file-exists-p tmp-name1
))
688 (should (string-equal tmp-name1
(file-truename tmp-name1
)))
689 ;; `make-symbolic-link' is not implemented.
691 (make-symbolic-link tmp-name1 tmp-name2
)
693 (should (file-symlink-p tmp-name2
))
696 ;; This is "/foo.txt".
697 (with-parsed-tramp-archive-file-name tmp-name1 nil localname
)
698 ;; `file-symlink-p' returns "foo.txt". Wer must expand, therefore.
699 (with-parsed-tramp-archive-file-name
701 (file-symlink-p tmp-name2
) tramp-archive-test-archive
)
704 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
706 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
)))
707 (should (file-equal-p tmp-name1 tmp-name2
)))
710 (tramp-archive-cleanup-hash))))
712 (ert-deftest tramp-archive-test26-file-name-completion
()
713 "Check `file-name-completion' and `file-name-all-completions'."
714 (skip-unless tramp-archive-enabled
)
716 (let ((tmp-name tramp-archive-test-archive
))
720 (should (equal (file-name-completion "fo" tmp-name
) "foo."))
721 (should (equal (file-name-completion "foo.txt" tmp-name
) t
))
722 (should (equal (file-name-completion "b" tmp-name
) "ba"))
723 (should-not (file-name-completion "a" tmp-name
))
726 (file-name-completion "b" tmp-name
'file-directory-p
) "bar/"))
729 (sort (file-name-all-completions "fo" tmp-name
) 'string-lessp
)
730 '("foo.hrd" "foo.lnk" "foo.txt")))
733 (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
734 '("bar/" "baz.tar")))
735 (should-not (file-name-all-completions "a" tmp-name
))
736 ;; `completion-regexp-list' restricts the completion to
737 ;; files which match all expressions in this list.
738 (let ((completion-regexp-list
739 `(,directory-files-no-dot-files-regexp
"b")))
741 (equal (file-name-completion "" tmp-name
) "ba"))
744 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
745 '("bar/" "baz.tar")))))
748 (tramp-archive-cleanup-hash))))
750 ;; The functions were introduced in Emacs 26.1.
751 (ert-deftest tramp-archive-test37-make-nearby-temp-file
()
752 "Check `make-nearby-temp-file' and `temporary-file-directory'."
753 (skip-unless tramp-archive-enabled
)
756 (and (fboundp 'make-nearby-temp-file
) (fboundp 'temporary-file-directory
)))
758 ;; `make-nearby-temp-file' and `temporary-file-directory' exists
759 ;; since Emacs 26.1. We don't want to see compiler warnings for
761 (let ((default-directory tramp-archive-test-archive
)
763 ;; The file archive shall know a temporary file directory. It is
764 ;; not in the archive itself.
766 (stringp (with-no-warnings (with-no-warnings (temporary-file-directory)))))
768 (tramp-archive-file-name-p (with-no-warnings (temporary-file-directory))))
770 ;; A temporary file or directory shall not be located in the
773 (with-no-warnings (make-nearby-temp-file "tramp-archive-test")))
774 (should (file-exists-p tmp-file
))
775 (should (file-regular-p tmp-file
))
776 (should-not (tramp-archive-file-name-p tmp-file
))
777 (delete-file tmp-file
)
778 (should-not (file-exists-p tmp-file
))
781 (with-no-warnings (make-nearby-temp-file "tramp-archive-test" 'dir
)))
782 (should (file-exists-p tmp-file
))
783 (should (file-directory-p tmp-file
))
784 (should-not (tramp-archive-file-name-p tmp-file
))
785 (delete-directory tmp-file
)
786 (should-not (file-exists-p tmp-file
))))
788 (ert-deftest tramp-archive-test40-file-system-info
()
789 "Check that `file-system-info' returns proper values."
790 (skip-unless tramp-archive-enabled
)
792 (skip-unless (fboundp 'file-system-info
))
794 ;; `file-system-info' exists since Emacs 27. We don't want to see
795 ;; compiler warnings for older Emacsen.
796 (let ((fsi (with-no-warnings (file-system-info tramp-archive-test-archive
))))
798 (should (and (consp fsi
)
800 (numberp (nth 0 fsi
))
801 ;; FREE and AVAIL are always 0.
803 (zerop (nth 2 fsi
))))))
805 (ert-deftest tramp-archive-test42-auto-load
()
806 "Check that `tramp-archive' autoloads properly."
807 (skip-unless tramp-archive-enabled
)
808 ;; Autoloading tramp-archive works since Emacs 27.1.
809 (skip-unless (tramp-archive--test-emacs27-p))
811 ;; tramp-archive is neither loaded at Emacs startup, nor when
812 ;; loading a file like "/mock::foo" (which loads Tramp).
813 (let ((default-directory (expand-file-name temporary-file-directory
))
816 (message \"tramp-archive loaded: %%s %%s\" \
817 (featurep 'tramp) (featurep 'tramp-archive)) \
818 (file-attributes %S \"/\") \
819 (message \"tramp-archive loaded: %%s %%s\" \
820 (featurep 'tramp) (featurep 'tramp-archive)))"))
821 (dolist (file `("/mock::foo" ,(concat tramp-archive-test-archive
"foo")))
825 "tramp-archive loaded: nil nil[[:ascii:]]+tramp-archive loaded: t %s"
826 (tramp-archive-file-name-p file
))
827 (shell-command-to-string
829 "%s -batch -Q -L %s --eval %s"
830 (shell-quote-argument
831 (expand-file-name invocation-name invocation-directory
))
832 (mapconcat 'shell-quote-argument load-path
" -L ")
833 (shell-quote-argument (format code file
)))))))))
835 (ert-deftest tramp-archive-test42-delay-load
()
836 "Check that `tramp-archive' is loaded lazily, only when needed."
837 (skip-unless tramp-archive-enabled
)
838 ;; Autoloading tramp-archive works since Emacs 27.1.
839 (skip-unless (tramp-archive--test-emacs27-p))
841 ;; tramp-archive is neither loaded at Emacs startup, nor when
842 ;; loading a file like "/foo.tar". It is loaded only when
843 ;; `tramp-archive-enabled' is t.
844 (let ((default-directory (expand-file-name temporary-file-directory
))
847 (setq tramp-archive-enabled %s) \
848 (message \"tramp-archive loaded: %%s\" \
849 (featurep 'tramp-archive)) \
850 (file-attributes %S \"/\") \
851 (message \"tramp-archive loaded: %%s\" \
852 (featurep 'tramp-archive)) \
853 (file-attributes %S \"/\") \
854 (message \"tramp-archive loaded: %%s\" \
855 (featurep 'tramp-archive)))"))
856 ;; tramp-archive doesn't load when `tramp-archive-enabled' is nil.
857 (dolist (tae '(t nil
))
861 "tramp-archive loaded: nil[[:ascii:]]+tramp-archive loaded: nil[[:ascii:]]+tramp-archive loaded: %s"
863 (shell-command-to-string
865 "%s -batch -Q -L %s --eval %s"
866 (shell-quote-argument
867 (expand-file-name invocation-name invocation-directory
))
868 (mapconcat 'shell-quote-argument load-path
" -L ")
869 (shell-quote-argument
871 code tae tramp-archive-test-file-archive
872 (concat tramp-archive-test-archive
"foo"))))))))))
874 (ert-deftest tramp-archive-test99-libarchive-tests
()
875 "Run tests of libarchive test files."
876 :tags
'(:expensive-test
)
877 (skip-unless tramp-archive-enabled
)
878 ;; We do not want to run unless chosen explicitly. This test makes
879 ;; sense only in my local environment. Michael Albinus.
882 (ert--stats-selector ert--current-run-stats
)
883 (ert-test-name (ert-running-test))))
888 '("~/Downloads" "/sftp::~/Downloads" "/ssh::~/Downloads"
889 "http://ftp.debian.org/debian/pool/main/c/coreutils"))
892 '("coreutils_8.26-3_amd64.deb"
893 "coreutils_8.26-3ubuntu3_amd64.deb"))
894 (setq file
(expand-file-name file dir
))
895 (when (file-exists-p file
)
896 (setq file
(expand-file-name "control.tar.gz/control" file
))
898 (should (file-attributes (file-name-as-directory file
))))))
901 (tramp-archive-cleanup-hash))
904 (dolist (dir '("" "/sftp::" "/ssh::"))
910 (lambda (x) (directory-files (concat dir x
) 'full
"uu\\'" 'sort
))
911 '("~/src/libarchive-3.2.2/libarchive/test"
912 "~/src/libarchive-3.2.2/cpio/test"
913 "~/src/libarchive-3.2.2/tar/test"))))
914 (setq file
(file-name-as-directory file
))
916 ((not (tramp-archive-file-name-p file
))
917 (message "skipped: %s" file
))
918 ((file-attributes file
)
920 (t (message "failed: %s" file
)))
921 (tramp-archive-cleanup-hash)))
924 (tramp-archive-cleanup-hash)))
926 (defun tramp-archive-test-all (&optional interactive
)
927 "Run all tests for \\[tramp-archive]."
930 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
)
933 (provide 'tramp-archive-tests
)
934 ;;; tramp-archive-tests.el ends here