1 ;;; tramp-tests.el --- Tests of remote file access -*- lexical-binding:t -*-
3 ;; Copyright (C) 2013-2017 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 tests require a recent ert.el from Emacs 24.4.
24 ;; Some of the tests require access to a remote host files. Since
25 ;; this could be problematic, a mock-up connection method "mock" is
26 ;; used. Emulating a remote connection, it simply calls "sh -i".
27 ;; Tramp's file name handlers still run, so this test is sufficient
28 ;; except for connection establishing.
30 ;; If you want to test a real Tramp connection, set
31 ;; $REMOTE_TEMPORARY_FILE_DIRECTORY to a suitable value in order to
32 ;; overwrite the default value. If you want to skip tests accessing a
33 ;; remote host, set this environment variable to "/dev/null" or
34 ;; whatever is appropriate on your system.
36 ;; A whole test run can be performed calling the command `tramp-test-all'.
48 (declare-function tramp-find-executable
"tramp-sh")
49 (declare-function tramp-get-remote-path
"tramp-sh")
50 (declare-function tramp-get-remote-stat
"tramp-sh")
51 (declare-function tramp-get-remote-perl
"tramp-sh")
52 (defvar auto-save-file-name-transforms
)
53 (defvar tramp-copy-size-limit
)
54 (defvar tramp-persistency-file-name
)
55 (defvar tramp-remote-process-environment
)
56 ;; Suppress nasty messages.
57 (fset 'shell-command-sentinel
'ignore
)
59 ;; There is no default value on w32 systems, which could work out of the box.
60 (defconst tramp-test-temporary-file-directory
62 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
63 ((eq system-type
'windows-nt
) null-device
)
67 (tramp-login-program "sh")
68 (tramp-login-args (("-i")))
69 (tramp-remote-shell "/bin/sh")
70 (tramp-remote-shell-args ("-c"))
71 (tramp-connection-timeout 10)))
73 'tramp-default-host-alist
74 `("\\`mock\\'" nil
,(system-name)))
75 ;; Emacs' Makefile sets $HOME to a nonexistent value. Needed in
76 ;; batch mode only, therefore.
77 (unless (and (null noninteractive
) (file-directory-p "~/"))
78 (setenv "HOME" temporary-file-directory
))
79 (format "/mock::%s" temporary-file-directory
)))
80 "Temporary directory for Tramp tests.")
82 (setq password-cache-expiry nil
84 tramp-cache-read-persistent-data t
;; For auth-sources.
85 tramp-copy-size-limit nil
86 tramp-message-show-message nil
87 tramp-persistency-file-name nil
)
89 ;; This should happen on hydra only.
90 (when (getenv "EMACS_HYDRA_CI")
91 (add-to-list 'tramp-remote-path
'tramp-own-remote-path
))
93 (defvar tramp--test-expensive-test
95 (string-equal (getenv "SELECTOR") "(quote (not (tag :expensive-test)))"))
96 "Whether expensive tests are run.")
98 (defvar tramp--test-enabled-checked nil
99 "Cached result of `tramp--test-enabled'.
100 If the function did run, the value is a cons cell, the `cdr'
103 (defun tramp--test-enabled ()
104 "Whether remote file access is enabled."
105 (unless (consp tramp--test-enabled-checked
)
107 tramp--test-enabled-checked
111 (file-remote-p tramp-test-temporary-file-directory
)
112 (file-directory-p tramp-test-temporary-file-directory
)
113 (file-writable-p tramp-test-temporary-file-directory
))))))
115 (when (cdr tramp--test-enabled-checked
)
116 ;; Cleanup connection.
118 (tramp-cleanup-connection
119 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
120 nil
'keep-password
)))
123 (cdr tramp--test-enabled-checked
))
125 (defun tramp--test-make-temp-name (&optional local quoted
)
126 "Return a temporary file name for test.
127 If LOCAL is non-nil, a local file name is returned.
128 If QUOTED is non-nil, the local part of the file name is quoted.
129 The temporary file is not created."
131 (if quoted
'tramp-compat-file-name-quote
'identity
)
133 (make-temp-name "tramp-test")
134 (if local temporary-file-directory tramp-test-temporary-file-directory
))))
136 ;; Don't print messages in nested `tramp--test-instrument-test-case' calls.
137 (defvar tramp--test-instrument-test-case-p nil
138 "Whether `tramp--test-instrument-test-case' run.
139 This shall used dynamically bound only.")
141 (defmacro tramp--test-instrument-test-case
(verbose &rest body
)
142 "Run BODY with `tramp-verbose' equal VERBOSE.
143 Print the content of the Tramp debug buffer, if BODY does not
144 eval properly in `should' or `should-not'. `should-error' is not
145 handled properly. BODY shall not contain a timeout."
146 (declare (indent 1) (debug (natnump body
)))
147 `(let ((tramp-verbose (max (or ,verbose
0) (or tramp-verbose
0)))
148 (tramp-message-show-message t
)
149 (tramp-debug-on-error t
)
150 (debug-ignored-errors
151 (cons "^make-symbolic-link not supported$" debug-ignored-errors
))
154 (let ((tramp--test-instrument-test-case-p t
)) ,@body
)
156 (when (and (null tramp--test-instrument-test-case-p
) (> tramp-verbose
3))
157 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
158 (with-current-buffer (tramp-get-connection-buffer v
)
159 (message "%s" (buffer-string)))
160 (with-current-buffer (tramp-get-debug-buffer v
)
161 (message "%s" (buffer-string))))))))
163 (defsubst tramp--test-message
(fmt-string &rest arguments
)
164 "Emit a message into ERT *Messages*."
165 (tramp--test-instrument-test-case 0
168 (tramp-dissect-file-name tramp-test-temporary-file-directory
) 0
169 fmt-string arguments
)))
171 (defsubst tramp--test-backtrace
()
172 "Dump a backtrace into ERT *Messages*."
173 (tramp--test-instrument-test-case 10
175 (tramp-dissect-file-name tramp-test-temporary-file-directory
))))
177 (ert-deftest tramp-test00-availability
()
178 "Test availability of Tramp functions."
179 :expected-result
(if (tramp--test-enabled) :passed
:failed
)
181 "Remote directory: `%s'" tramp-test-temporary-file-directory
)
182 (should (ignore-errors
184 (file-remote-p tramp-test-temporary-file-directory
)
185 (file-directory-p tramp-test-temporary-file-directory
)
186 (file-writable-p tramp-test-temporary-file-directory
)))))
188 (ert-deftest tramp-test01-file-name-syntax
()
189 "Check remote file name syntax."
191 (should (tramp-tramp-file-p "/method::"))
192 (should (tramp-tramp-file-p "/method:host:"))
193 (should (tramp-tramp-file-p "/method:user@:"))
194 (should (tramp-tramp-file-p "/method:user@host:"))
195 (should (tramp-tramp-file-p "/method:user@email@host:"))
198 (should (tramp-tramp-file-p "/method:host#1234:"))
199 (should (tramp-tramp-file-p "/method:user@host#1234:"))
201 ;; Using an IPv4 address.
202 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
203 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
205 ;; Using an IPv6 address.
206 (should (tramp-tramp-file-p "/method:[::1]:"))
207 (should (tramp-tramp-file-p "/method:user@[::1]:"))
209 ;; Local file name part.
210 (should (tramp-tramp-file-p "/method:::"))
211 (should (tramp-tramp-file-p "/method::/:"))
212 (should (tramp-tramp-file-p "/method::/path/to/file"))
213 (should (tramp-tramp-file-p "/method::/:/path/to/file"))
214 (should (tramp-tramp-file-p "/method::file"))
215 (should (tramp-tramp-file-p "/method::/:file"))
218 (should (tramp-tramp-file-p "/method1:|method2::"))
219 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
220 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
221 (should (tramp-tramp-file-p
222 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
225 (should-not (tramp-tramp-file-p nil
))
226 (should-not (tramp-tramp-file-p 'symbol
))
228 (should-not (tramp-tramp-file-p "/host:"))
229 (should-not (tramp-tramp-file-p "/user@host:"))
230 (should-not (tramp-tramp-file-p "/1.2.3.4:"))
231 (should-not (tramp-tramp-file-p "/[]:"))
232 (should-not (tramp-tramp-file-p "/[::1]:"))
233 (should-not (tramp-tramp-file-p "/host:/:"))
234 (should-not (tramp-tramp-file-p "/host1|host2:"))
235 (should-not (tramp-tramp-file-p "/user1@host1|user2@host2:"))
236 ;; Quote with "/:" suppresses file name handlers.
237 (should-not (tramp-tramp-file-p "/::"))
238 (should-not (tramp-tramp-file-p "/:@:"))
239 (should-not (tramp-tramp-file-p "/:[]:"))
240 ;; Methods shall be at least two characters on MS Windows, except
241 ;; the default method.
242 (let ((system-type 'windows-nt
))
243 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
244 (should-not (tramp-tramp-file-p "/c::/path/to/file"))
245 (should (tramp-tramp-file-p "/-::/path/to/file")))
246 (let ((system-type 'gnu
/linux
))
247 (should (tramp-tramp-file-p "/-:h:/path/to/file"))
248 (should (tramp-tramp-file-p "/m::/path/to/file"))))
250 (ert-deftest tramp-test01-file-name-syntax-simplified
()
251 "Check simplified file name syntax."
252 :tags
'(:expensive-test
)
253 (let ((syntax tramp-syntax
))
256 (tramp-change-syntax 'simplified
)
258 (should (tramp-tramp-file-p "/host:"))
259 (should (tramp-tramp-file-p "/user@:"))
260 (should (tramp-tramp-file-p "/user@host:"))
261 (should (tramp-tramp-file-p "/user@email@host:"))
264 (should (tramp-tramp-file-p "/host#1234:"))
265 (should (tramp-tramp-file-p "/user@host#1234:"))
267 ;; Using an IPv4 address.
268 (should (tramp-tramp-file-p "/1.2.3.4:"))
269 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
271 ;; Using an IPv6 address.
272 (should (tramp-tramp-file-p "/[::1]:"))
273 (should (tramp-tramp-file-p "/user@[::1]:"))
275 ;; Local file name part.
276 (should (tramp-tramp-file-p "/host::"))
277 (should (tramp-tramp-file-p "/host:/:"))
278 (should (tramp-tramp-file-p "/host:/path/to/file"))
279 (should (tramp-tramp-file-p "/host:/:/path/to/file"))
280 (should (tramp-tramp-file-p "/host:file"))
281 (should (tramp-tramp-file-p "/host:/:file"))
284 (should (tramp-tramp-file-p "/host1|host2:"))
285 (should (tramp-tramp-file-p "/user1@host1|user2@host2:"))
286 (should (tramp-tramp-file-p "/user1@host1|user2@host2|user3@host3:"))
289 (should-not (tramp-tramp-file-p nil
))
290 (should-not (tramp-tramp-file-p 'symbol
))
291 ;; Quote with "/:" suppresses file name handlers.
292 (should-not (tramp-tramp-file-p "/::"))
293 (should-not (tramp-tramp-file-p "/:@:"))
294 (should-not (tramp-tramp-file-p "/:[]:")))
297 (tramp-change-syntax syntax
))))
299 (ert-deftest tramp-test01-file-name-syntax-separate
()
300 "Check separate file name syntax."
301 :tags
'(:expensive-test
)
302 (let ((syntax tramp-syntax
))
305 (tramp-change-syntax 'separate
)
307 (should (tramp-tramp-file-p "/[method/]"))
308 (should (tramp-tramp-file-p "/[method/host]"))
309 (should (tramp-tramp-file-p "/[method/user@]"))
310 (should (tramp-tramp-file-p "/[method/user@host]"))
311 (should (tramp-tramp-file-p "/[method/user@email@host]"))
314 (should (tramp-tramp-file-p "/[method/host#1234]"))
315 (should (tramp-tramp-file-p "/[method/user@host#1234]"))
317 ;; Using an IPv4 address.
318 (should (tramp-tramp-file-p "/[method/1.2.3.4]"))
319 (should (tramp-tramp-file-p "/[method/user@1.2.3.4]"))
321 ;; Using an IPv6 address.
322 (should (tramp-tramp-file-p "/[method/::1]"))
323 (should (tramp-tramp-file-p "/[method/user@::1]"))
325 ;; Local file name part.
326 (should (tramp-tramp-file-p "/[method/]"))
327 (should (tramp-tramp-file-p "/[method/]/:"))
328 (should (tramp-tramp-file-p "/[method/]/path/to/file"))
329 (should (tramp-tramp-file-p "/[method/]/:/path/to/file"))
330 (should (tramp-tramp-file-p "/[method/]file"))
331 (should (tramp-tramp-file-p "/[method/]/:file"))
334 (should (tramp-tramp-file-p "/[method1/|method2/]"))
335 (should (tramp-tramp-file-p "/[method1/host1|method2/host2]"))
338 "/[method1/user1@host1|method2/user2@host2]"))
341 "/[method1/user1@host1|method2/user2@host2|method3/user3@host3]"))
344 (should-not (tramp-tramp-file-p nil
))
345 (should-not (tramp-tramp-file-p 'symbol
))
347 (should-not (tramp-tramp-file-p "/host:"))
348 (should-not (tramp-tramp-file-p "/user@host:"))
349 (should-not (tramp-tramp-file-p "/1.2.3.4:"))
350 (should-not (tramp-tramp-file-p "/host:/:"))
351 (should-not (tramp-tramp-file-p "/host1|host2:"))
352 (should-not (tramp-tramp-file-p "/user1@host1|user2@host2:"))
353 ;; Quote with "/:" suppresses file name handlers.
354 (should-not (tramp-tramp-file-p "/:[]")))
357 (tramp-change-syntax syntax
))))
359 (ert-deftest tramp-test02-file-name-dissect
()
360 "Check remote file name components."
361 (let ((tramp-default-method "default-method")
362 (tramp-default-user "default-user")
363 (tramp-default-host "default-host"))
364 ;; Expand `tramp-default-user' and `tramp-default-host'.
365 (should (string-equal
366 (file-remote-p "/method::")
367 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
368 (should (string-equal (file-remote-p "/method::" 'method
) "method"))
369 (should (string-equal (file-remote-p "/method::" 'user
) "default-user"))
370 (should (string-equal (file-remote-p "/method::" 'host
) "default-host"))
371 (should (string-equal (file-remote-p "/method::" 'localname
) ""))
372 (should (string-equal (file-remote-p "/method::" 'hop
) nil
))
374 ;; Expand `tramp-default-method' and `tramp-default-user'.
375 (should (string-equal
376 (file-remote-p "/-:host:")
377 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
378 (should (string-equal (file-remote-p "/-:host:" 'method
) "default-method"))
379 (should (string-equal (file-remote-p "/-:host:" 'user
) "default-user"))
380 (should (string-equal (file-remote-p "/-:host:" 'host
) "host"))
381 (should (string-equal (file-remote-p "/-:host:" 'localname
) ""))
382 (should (string-equal (file-remote-p "/-:host:" 'hop
) nil
))
384 ;; Expand `tramp-default-method' and `tramp-default-host'.
385 (should (string-equal
386 (file-remote-p "/-:user@:")
387 (format "/%s:%s@%s:" "default-method" "user" "default-host")))
388 (should (string-equal (file-remote-p "/-:user@:" 'method
) "default-method"))
389 (should (string-equal (file-remote-p "/-:user@:" 'user
) "user"))
390 (should (string-equal (file-remote-p "/-:user@:" 'host
) "default-host"))
391 (should (string-equal (file-remote-p "/-:user@:" 'localname
) ""))
392 (should (string-equal (file-remote-p "/-:user@:" 'hop
) nil
))
394 ;; Expand `tramp-default-method'.
395 (should (string-equal
396 (file-remote-p "/-:user@host:")
397 (format "/%s:%s@%s:" "default-method" "user" "host")))
398 (should (string-equal
399 (file-remote-p "/-:user@host:" 'method
) "default-method"))
400 (should (string-equal (file-remote-p "/-:user@host:" 'user
) "user"))
401 (should (string-equal (file-remote-p "/-:user@host:" 'host
) "host"))
402 (should (string-equal (file-remote-p "/-:user@host:" 'localname
) ""))
403 (should (string-equal (file-remote-p "/-:user@host:" 'hop
) nil
))
405 ;; Expand `tramp-default-user'.
406 (should (string-equal
407 (file-remote-p "/method:host:")
408 (format "/%s:%s@%s:" "method" "default-user" "host")))
409 (should (string-equal (file-remote-p "/method:host:" 'method
) "method"))
410 (should (string-equal (file-remote-p "/method:host:" 'user
) "default-user"))
411 (should (string-equal (file-remote-p "/method:host:" 'host
) "host"))
412 (should (string-equal (file-remote-p "/method:host:" 'localname
) ""))
413 (should (string-equal (file-remote-p "/method:host:" 'hop
) nil
))
415 ;; Expand `tramp-default-host'.
416 (should (string-equal
417 (file-remote-p "/method:user@:")
418 (format "/%s:%s@%s:" "method" "user" "default-host")))
419 (should (string-equal (file-remote-p "/method:user@:" 'method
) "method"))
420 (should (string-equal (file-remote-p "/method:user@:" 'user
) "user"))
421 (should (string-equal (file-remote-p "/method:user@:" 'host
)
423 (should (string-equal (file-remote-p "/method:user@:" 'localname
) ""))
424 (should (string-equal (file-remote-p "/method:user@:" 'hop
) nil
))
427 (should (string-equal
428 (file-remote-p "/method:user@host:")
429 (format "/%s:%s@%s:" "method" "user" "host")))
430 (should (string-equal
431 (file-remote-p "/method:user@host:" 'method
) "method"))
432 (should (string-equal (file-remote-p "/method:user@host:" 'user
) "user"))
433 (should (string-equal (file-remote-p "/method:user@host:" 'host
) "host"))
434 (should (string-equal (file-remote-p "/method:user@host:" 'localname
) ""))
435 (should (string-equal (file-remote-p "/method:user@host:" 'hop
) nil
))
438 (should (string-equal
439 (file-remote-p "/method:user@email@host:")
440 (format "/%s:%s@%s:" "method" "user@email" "host")))
441 (should (string-equal
442 (file-remote-p "/method:user@email@host:" 'method
) "method"))
443 (should (string-equal
444 (file-remote-p "/method:user@email@host:" 'user
) "user@email"))
445 (should (string-equal
446 (file-remote-p "/method:user@email@host:" 'host
) "host"))
447 (should (string-equal
448 (file-remote-p "/method:user@email@host:" 'localname
) ""))
449 (should (string-equal
450 (file-remote-p "/method:user@email@host:" 'hop
) nil
))
452 ;; Expand `tramp-default-method' and `tramp-default-user'.
453 (should (string-equal
454 (file-remote-p "/-:host#1234:")
455 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
456 (should (string-equal
457 (file-remote-p "/-:host#1234:" 'method
) "default-method"))
458 (should (string-equal (file-remote-p "/-:host#1234:" 'user
) "default-user"))
459 (should (string-equal (file-remote-p "/-:host#1234:" 'host
) "host#1234"))
460 (should (string-equal (file-remote-p "/-:host#1234:" 'localname
) ""))
461 (should (string-equal (file-remote-p "/-:host#1234:" 'hop
) nil
))
463 ;; Expand `tramp-default-method'.
464 (should (string-equal
465 (file-remote-p "/-:user@host#1234:")
466 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
467 (should (string-equal
468 (file-remote-p "/-:user@host#1234:" 'method
) "default-method"))
469 (should (string-equal (file-remote-p "/-:user@host#1234:" 'user
) "user"))
470 (should (string-equal (file-remote-p "/-:user@host#1234:" 'host
) "host#1234"))
471 (should (string-equal (file-remote-p "/-:user@host#1234:" 'localname
) ""))
472 (should (string-equal (file-remote-p "/-:user@host#1234:" 'hop
) nil
))
474 ;; Expand `tramp-default-user'.
475 (should (string-equal
476 (file-remote-p "/method:host#1234:")
477 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
478 (should (string-equal
479 (file-remote-p "/method:host#1234:" 'method
) "method"))
480 (should (string-equal
481 (file-remote-p "/method:host#1234:" 'user
) "default-user"))
482 (should (string-equal
483 (file-remote-p "/method:host#1234:" 'host
) "host#1234"))
484 (should (string-equal (file-remote-p "/method:host#1234:" 'localname
) ""))
485 (should (string-equal (file-remote-p "/method:host#1234:" 'hop
) nil
))
488 (should (string-equal
489 (file-remote-p "/method:user@host#1234:")
490 (format "/%s:%s@%s:" "method" "user" "host#1234")))
491 (should (string-equal
492 (file-remote-p "/method:user@host#1234:" 'method
) "method"))
493 (should (string-equal
494 (file-remote-p "/method:user@host#1234:" 'user
) "user"))
495 (should (string-equal
496 (file-remote-p "/method:user@host#1234:" 'host
) "host#1234"))
497 (should (string-equal
498 (file-remote-p "/method:user@host#1234:" 'localname
) ""))
499 (should (string-equal
500 (file-remote-p "/method:user@host#1234:" 'hop
) nil
))
502 ;; Expand `tramp-default-method' and `tramp-default-user'.
503 (should (string-equal
504 (file-remote-p "/-:1.2.3.4:")
505 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
506 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'method
) "default-method"))
507 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'user
) "default-user"))
508 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'host
) "1.2.3.4"))
509 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'localname
) ""))
510 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'hop
) nil
))
512 ;; Expand `tramp-default-method'.
513 (should (string-equal
514 (file-remote-p "/-:user@1.2.3.4:")
515 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
516 (should (string-equal
517 (file-remote-p "/-:user@1.2.3.4:" 'method
) "default-method"))
518 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'user
) "user"))
519 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'host
) "1.2.3.4"))
520 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'localname
) ""))
521 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'hop
) nil
))
523 ;; Expand `tramp-default-user'.
524 (should (string-equal
525 (file-remote-p "/method:1.2.3.4:")
526 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
527 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method
) "method"))
528 (should (string-equal
529 (file-remote-p "/method:1.2.3.4:" 'user
) "default-user"))
530 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host
) "1.2.3.4"))
531 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname
) ""))
532 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'hop
) nil
))
535 (should (string-equal
536 (file-remote-p "/method:user@1.2.3.4:")
537 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
538 (should (string-equal
539 (file-remote-p "/method:user@1.2.3.4:" 'method
) "method"))
540 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user
) "user"))
541 (should (string-equal
542 (file-remote-p "/method:user@1.2.3.4:" 'host
) "1.2.3.4"))
543 (should (string-equal
544 (file-remote-p "/method:user@1.2.3.4:" 'localname
) ""))
545 (should (string-equal
546 (file-remote-p "/method:user@1.2.3.4:" 'hop
) nil
))
548 ;; Expand `tramp-default-method', `tramp-default-user' and
549 ;; `tramp-default-host'.
550 (should (string-equal
551 (file-remote-p "/-:[]:")
553 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
554 (should (string-equal (file-remote-p "/-:[]:" 'method
) "default-method"))
555 (should (string-equal (file-remote-p "/-:[]:" 'user
) "default-user"))
556 (should (string-equal (file-remote-p "/-:[]:" 'host
) "default-host"))
557 (should (string-equal (file-remote-p "/-:[]:" 'localname
) ""))
558 (should (string-equal (file-remote-p "/-:[]:" 'hop
) nil
))
560 ;; Expand `tramp-default-method' and `tramp-default-user'.
561 (let ((tramp-default-host "::1"))
562 (should (string-equal
563 (file-remote-p "/-:[]:")
564 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
565 (should (string-equal (file-remote-p "/-:[]:" 'method
) "default-method"))
566 (should (string-equal (file-remote-p "/-:[]:" 'user
) "default-user"))
567 (should (string-equal (file-remote-p "/-:[]:" 'host
) "::1"))
568 (should (string-equal (file-remote-p "/-:[]:" 'localname
) ""))
569 (should (string-equal (file-remote-p "/-:[]:" 'hop
) nil
)))
571 ;; Expand `tramp-default-method' and `tramp-default-user'.
572 (should (string-equal
573 (file-remote-p "/-:[::1]:")
574 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
575 (should (string-equal (file-remote-p "/-:[::1]:" 'method
) "default-method"))
576 (should (string-equal (file-remote-p "/-:[::1]:" 'user
) "default-user"))
577 (should (string-equal (file-remote-p "/-:[::1]:" 'host
) "::1"))
578 (should (string-equal (file-remote-p "/-:[::1]:" 'localname
) ""))
579 (should (string-equal (file-remote-p "/-:[::1]:" 'hop
) nil
))
581 ;; Expand `tramp-default-method'.
582 (should (string-equal
583 (file-remote-p "/-:user@[::1]:")
584 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
585 (should (string-equal
586 (file-remote-p "/-:user@[::1]:" 'method
) "default-method"))
587 (should (string-equal (file-remote-p "/-:user@[::1]:" 'user
) "user"))
588 (should (string-equal (file-remote-p "/-:user@[::1]:" 'host
) "::1"))
589 (should (string-equal (file-remote-p "/-:user@[::1]:" 'localname
) ""))
590 (should (string-equal (file-remote-p "/-:user@[::1]:" 'hop
) nil
))
592 ;; Expand `tramp-default-user'.
593 (should (string-equal
594 (file-remote-p "/method:[::1]:")
595 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
596 (should (string-equal (file-remote-p "/method:[::1]:" 'method
) "method"))
597 (should (string-equal
598 (file-remote-p "/method:[::1]:" 'user
) "default-user"))
599 (should (string-equal (file-remote-p "/method:[::1]:" 'host
) "::1"))
600 (should (string-equal (file-remote-p "/method:[::1]:" 'localname
) ""))
601 (should (string-equal (file-remote-p "/method:[::1]:" 'hop
) nil
))
604 (should (string-equal
605 (file-remote-p "/method:user@[::1]:")
606 (format "/%s:%s@%s:" "method" "user" "[::1]")))
607 (should (string-equal
608 (file-remote-p "/method:user@[::1]:" 'method
) "method"))
609 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user
) "user"))
610 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host
) "::1"))
611 (should (string-equal
612 (file-remote-p "/method:user@[::1]:" 'localname
) ""))
613 (should (string-equal (file-remote-p "/method:user@[::1]:" 'hop
) nil
))
615 ;; Local file name part.
616 (should (string-equal (file-remote-p "/-:host:/:" 'localname
) "/:"))
617 (should (string-equal (file-remote-p "/method:::" 'localname
) ":"))
618 (should (string-equal (file-remote-p "/method:: " 'localname
) " "))
619 (should (string-equal (file-remote-p "/method::file" 'localname
) "file"))
620 (should (string-equal
621 (file-remote-p "/method::/path/to/file" 'localname
)
627 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
628 (format "/%s:%s@%s|%s:%s@%s:"
629 "method1" "user1" "host1" "method2" "user2" "host2")))
633 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method
)
638 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user
)
643 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host
)
648 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname
)
653 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'hop
)
655 "method1" "user1" "host1")))
661 "/method1:user1@host1"
662 "|method2:user2@host2"
663 "|method3:user3@host3:/path/to/file"))
664 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
665 "method1" "user1" "host1"
666 "method2" "user2" "host2"
667 "method3" "user3" "host3")))
672 "/method1:user1@host1"
673 "|method2:user2@host2"
674 "|method3:user3@host3:/path/to/file")
681 "/method1:user1@host1"
682 "|method2:user2@host2"
683 "|method3:user3@host3:/path/to/file")
690 "/method1:user1@host1"
691 "|method2:user2@host2"
692 "|method3:user3@host3:/path/to/file")
699 "/method1:user1@host1"
700 "|method2:user2@host2"
701 "|method3:user3@host3:/path/to/file")
708 "/method1:user1@host1"
709 "|method2:user2@host2"
710 "|method3:user3@host3:/path/to/file")
712 (format "%s:%s@%s|%s:%s@%s|"
713 "method1" "user1" "host1" "method2" "user2" "host2")))))
715 (ert-deftest tramp-test02-file-name-dissect-simplified
()
716 "Check simplified file name components."
717 :tags
'(:expensive-test
)
718 (let ((tramp-default-method "default-method")
719 (tramp-default-user "default-user")
720 (tramp-default-host "default-host")
721 (syntax tramp-syntax
))
724 (tramp-change-syntax 'simplified
)
725 ;; Expand `tramp-default-method' and `tramp-default-user'.
726 (should (string-equal
727 (file-remote-p "/host:")
728 (format "/%s@%s:" "default-user" "host")))
729 (should (string-equal
730 (file-remote-p "/host:" 'method
) "default-method"))
731 (should (string-equal (file-remote-p "/host:" 'user
) "default-user"))
732 (should (string-equal (file-remote-p "/host:" 'host
) "host"))
733 (should (string-equal (file-remote-p "/host:" 'localname
) ""))
734 (should (string-equal (file-remote-p "/host:" 'hop
) nil
))
736 ;; Expand `tramp-default-method' and `tramp-default-host'.
737 (should (string-equal
738 (file-remote-p "/user@:")
739 (format "/%s@%s:" "user" "default-host")))
740 (should (string-equal
741 (file-remote-p "/user@:" 'method
) "default-method"))
742 (should (string-equal (file-remote-p "/user@:" 'user
) "user"))
743 (should (string-equal (file-remote-p "/user@:" 'host
) "default-host"))
744 (should (string-equal (file-remote-p "/user@:" 'localname
) ""))
745 (should (string-equal (file-remote-p "/user@:" 'hop
) nil
))
747 ;; Expand `tramp-default-method'.
748 (should (string-equal
749 (file-remote-p "/user@host:")
750 (format "/%s@%s:" "user" "host")))
751 (should (string-equal
752 (file-remote-p "/user@host:" 'method
) "default-method"))
753 (should (string-equal (file-remote-p "/user@host:" 'user
) "user"))
754 (should (string-equal (file-remote-p "/user@host:" 'host
) "host"))
755 (should (string-equal (file-remote-p "/user@host:" 'localname
) ""))
756 (should (string-equal (file-remote-p "/user@host:" 'hop
) nil
))
759 (should (string-equal
760 (file-remote-p "/user@email@host:")
761 (format "/%s@%s:" "user@email" "host")))
762 (should (string-equal
764 "/user@email@host:" 'method
) "default-method"))
765 (should (string-equal
766 (file-remote-p "/user@email@host:" 'user
) "user@email"))
767 (should (string-equal
768 (file-remote-p "/user@email@host:" 'host
) "host"))
769 (should (string-equal
770 (file-remote-p "/user@email@host:" 'localname
) ""))
771 (should (string-equal
772 (file-remote-p "/user@email@host:" 'hop
) nil
))
774 ;; Expand `tramp-default-method' and `tramp-default-user'.
775 (should (string-equal
776 (file-remote-p "/host#1234:")
777 (format "/%s@%s:" "default-user" "host#1234")))
778 (should (string-equal
779 (file-remote-p "/host#1234:" 'method
) "default-method"))
780 (should (string-equal
781 (file-remote-p "/host#1234:" 'user
) "default-user"))
782 (should (string-equal
783 (file-remote-p "/host#1234:" 'host
) "host#1234"))
784 (should (string-equal (file-remote-p "/host#1234:" 'localname
) ""))
785 (should (string-equal (file-remote-p "/host#1234:" 'hop
) nil
))
787 ;; Expand `tramp-default-method'.
788 (should (string-equal
789 (file-remote-p "/user@host#1234:")
790 (format "/%s@%s:" "user" "host#1234")))
791 (should (string-equal
792 (file-remote-p "/user@host#1234:" 'method
) "default-method"))
793 (should (string-equal
794 (file-remote-p "/user@host#1234:" 'user
) "user"))
795 (should (string-equal
796 (file-remote-p "/user@host#1234:" 'host
) "host#1234"))
797 (should (string-equal
798 (file-remote-p "/user@host#1234:" 'localname
) ""))
799 (should (string-equal (file-remote-p "/user@host#1234:" 'hop
) nil
))
801 ;; Expand `tramp-default-method' and `tramp-default-user'.
802 (should (string-equal
803 (file-remote-p "/1.2.3.4:")
804 (format "/%s@%s:" "default-user" "1.2.3.4")))
805 (should (string-equal
806 (file-remote-p "/1.2.3.4:" 'method
) "default-method"))
807 (should (string-equal
808 (file-remote-p "/1.2.3.4:" 'user
) "default-user"))
809 (should (string-equal (file-remote-p "/1.2.3.4:" 'host
) "1.2.3.4"))
810 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname
) ""))
811 (should (string-equal (file-remote-p "/1.2.3.4:" 'hop
) nil
))
813 ;; Expand `tramp-default-method'.
814 (should (string-equal
815 (file-remote-p "/user@1.2.3.4:")
816 (format "/%s@%s:" "user" "1.2.3.4")))
817 (should (string-equal
818 (file-remote-p "/user@1.2.3.4:" 'method
) "default-method"))
819 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user
) "user"))
820 (should (string-equal
821 (file-remote-p "/user@1.2.3.4:" 'host
) "1.2.3.4"))
822 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname
) ""))
823 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'hop
) nil
))
825 ;; Expand `tramp-default-method', `tramp-default-user' and
826 ;; `tramp-default-host'.
827 (should (string-equal
828 (file-remote-p "/[]:")
830 "/%s@%s:" "default-user" "default-host")))
831 (should (string-equal
832 (file-remote-p "/[]:" 'method
) "default-method"))
833 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
834 (should (string-equal (file-remote-p "/[]:" 'host
) "default-host"))
835 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
836 (should (string-equal (file-remote-p "/[]:" 'hop
) nil
))
838 ;; Expand `tramp-default-method' and `tramp-default-user'.
839 (let ((tramp-default-host "::1"))
840 (should (string-equal
841 (file-remote-p "/[]:")
842 (format "/%s@%s:" "default-user" "[::1]")))
843 (should (string-equal
844 (file-remote-p "/[]:" 'method
) "default-method"))
845 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
846 (should (string-equal (file-remote-p "/[]:" 'host
) "::1"))
847 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
848 (should (string-equal (file-remote-p "/[]:" 'hop
) nil
)))
850 ;; Expand `tramp-default-method' and `tramp-default-user'.
851 (should (string-equal
852 (file-remote-p "/[::1]:")
853 (format "/%s@%s:" "default-user" "[::1]")))
854 (should (string-equal
855 (file-remote-p "/[::1]:" 'method
) "default-method"))
856 (should (string-equal (file-remote-p "/[::1]:" 'user
) "default-user"))
857 (should (string-equal (file-remote-p "/[::1]:" 'host
) "::1"))
858 (should (string-equal (file-remote-p "/[::1]:" 'localname
) ""))
859 (should (string-equal (file-remote-p "/[::1]:" 'hop
) nil
))
861 ;; Expand `tramp-default-method'.
862 (should (string-equal
863 (file-remote-p "/user@[::1]:")
864 (format "/%s@%s:" "user" "[::1]")))
865 (should (string-equal
866 (file-remote-p "/user@[::1]:" 'method
) "default-method"))
867 (should (string-equal (file-remote-p "/user@[::1]:" 'user
) "user"))
868 (should (string-equal (file-remote-p "/user@[::1]:" 'host
) "::1"))
869 (should (string-equal (file-remote-p "/user@[::1]:" 'localname
) ""))
870 (should (string-equal (file-remote-p "/user@[::1]:" 'hop
) nil
))
872 ;; Local file name part.
873 (should (string-equal (file-remote-p "/host:/:" 'localname
) "/:"))
874 (should (string-equal (file-remote-p "/host::" 'localname
) ":"))
875 (should (string-equal (file-remote-p "/host: " 'localname
) " "))
876 (should (string-equal (file-remote-p "/host:file" 'localname
) "file"))
877 (should (string-equal
878 (file-remote-p "/host:/path/to/file" 'localname
)
884 (file-remote-p "/user1@host1|user2@host2:/path/to/file")
885 (format "/%s@%s|%s@%s:" "user1" "host1" "user2" "host2")))
889 "/user1@host1|user2@host2:/path/to/file" 'method
)
894 "/user1@host1|user2@host2:/path/to/file" 'user
)
899 "/user1@host1|user2@host2:/path/to/file" 'host
)
904 "/user1@host1|user2@host2:/path/to/file" 'localname
)
909 "/user1@host1|user2@host2:/path/to/file" 'hop
)
910 (format "%s@%s|" "user1" "host1")))
918 "|user3@host3:/path/to/file"))
919 (format "/%s@%s|%s@%s|%s@%s:"
929 "|user3@host3:/path/to/file")
938 "|user3@host3:/path/to/file")
947 "|user3@host3:/path/to/file")
956 "|user3@host3:/path/to/file")
965 "|user3@host3:/path/to/file")
967 (format "%s@%s|%s@%s|"
968 "user1" "host1" "user2" "host2"))))
971 (tramp-change-syntax syntax
))))
973 (ert-deftest tramp-test02-file-name-dissect-separate
()
974 "Check separate file name components."
975 :tags
'(:expensive-test
)
976 (let ((tramp-default-method "default-method")
977 (tramp-default-user "default-user")
978 (tramp-default-host "default-host")
979 (syntax tramp-syntax
))
982 (tramp-change-syntax 'separate
)
983 ;; Expand `tramp-default-user' and `tramp-default-host'.
984 (should (string-equal
985 (file-remote-p "/[method/]")
987 "/[%s/%s@%s]" "method" "default-user" "default-host")))
988 (should (string-equal (file-remote-p "/[method/]" 'method
) "method"))
989 (should (string-equal
990 (file-remote-p "/[method/]" 'user
) "default-user"))
991 (should (string-equal
992 (file-remote-p "/[method/]" 'host
) "default-host"))
993 (should (string-equal (file-remote-p "/[method/]" 'localname
) ""))
994 (should (string-equal (file-remote-p "/[method/]" 'hop
) nil
))
996 ;; Expand `tramp-default-method' and `tramp-default-user'.
997 (should (string-equal
998 (file-remote-p "/[/host]")
1000 "/[%s/%s@%s]" "default-method" "default-user" "host")))
1001 (should (string-equal
1002 (file-remote-p "/[/host]" 'method
) "default-method"))
1003 (should (string-equal
1004 (file-remote-p "/[/host]" 'user
) "default-user"))
1005 (should (string-equal (file-remote-p "/[/host]" 'host
) "host"))
1006 (should (string-equal (file-remote-p "/[/host]" 'localname
) ""))
1007 (should (string-equal (file-remote-p "/[/host]" 'hop
) nil
))
1009 ;; Expand `tramp-default-method' and `tramp-default-host'.
1010 (should (string-equal
1011 (file-remote-p "/[/user@]")
1013 "/[%s/%s@%s]" "default-method" "user" "default-host")))
1014 (should (string-equal
1015 (file-remote-p "/[/user@]" 'method
) "default-method"))
1016 (should (string-equal (file-remote-p "/[/user@]" 'user
) "user"))
1017 (should (string-equal
1018 (file-remote-p "/[/user@]" 'host
) "default-host"))
1019 (should (string-equal (file-remote-p "/[/user@]" 'localname
) ""))
1020 (should (string-equal (file-remote-p "/[/user@]" 'hop
) nil
))
1022 ;; Expand `tramp-default-method'.
1023 (should (string-equal
1024 (file-remote-p "/[/user@host]")
1025 (format "/[%s/%s@%s]" "default-method" "user" "host")))
1026 (should (string-equal
1027 (file-remote-p "/[/user@host]" 'method
) "default-method"))
1028 (should (string-equal (file-remote-p "/[/user@host]" 'user
) "user"))
1029 (should (string-equal (file-remote-p "/[/user@host]" 'host
) "host"))
1030 (should (string-equal (file-remote-p "/[/user@host]" 'localname
) ""))
1031 (should (string-equal (file-remote-p "/[/user@host]" 'hop
) nil
))
1033 ;; Expand `tramp-default-method' and `tramp-default-user'.
1034 (should (string-equal
1035 (file-remote-p "/[-/host]")
1037 "/[%s/%s@%s]" "default-method" "default-user" "host")))
1038 (should (string-equal
1039 (file-remote-p "/[-/host]" 'method
) "default-method"))
1040 (should (string-equal
1041 (file-remote-p "/[-/host]" 'user
) "default-user"))
1042 (should (string-equal (file-remote-p "/[-/host]" 'host
) "host"))
1043 (should (string-equal (file-remote-p "/[-/host]" 'localname
) ""))
1044 (should (string-equal (file-remote-p "/[-/host]" 'hop
) nil
))
1046 ;; Expand `tramp-default-method' and `tramp-default-host'.
1047 (should (string-equal
1048 (file-remote-p "/[-/user@]")
1050 "/[%s/%s@%s]" "default-method" "user" "default-host")))
1051 (should (string-equal
1052 (file-remote-p "/[-/user@]" 'method
) "default-method"))
1053 (should (string-equal (file-remote-p "/[-/user@]" 'user
) "user"))
1054 (should (string-equal
1055 (file-remote-p "/[-/user@]" 'host
) "default-host"))
1056 (should (string-equal (file-remote-p "/[-/user@]" 'localname
) ""))
1057 (should (string-equal (file-remote-p "/[-/user@]" 'hop
) nil
))
1059 ;; Expand `tramp-default-method'.
1060 (should (string-equal
1061 (file-remote-p "/[-/user@host]")
1062 (format "/[%s/%s@%s]" "default-method" "user" "host")))
1063 (should (string-equal
1064 (file-remote-p "/[-/user@host]" 'method
) "default-method"))
1065 (should (string-equal (file-remote-p "/[-/user@host]" 'user
) "user"))
1066 (should (string-equal (file-remote-p "/[-/user@host]" 'host
) "host"))
1067 (should (string-equal (file-remote-p "/[-/user@host]" 'localname
) ""))
1068 (should (string-equal (file-remote-p "/[-/user@host]" 'hop
) nil
))
1070 ;; Expand `tramp-default-user'.
1071 (should (string-equal
1072 (file-remote-p "/[method/host]")
1073 (format "/[%s/%s@%s]" "method" "default-user" "host")))
1074 (should (string-equal
1075 (file-remote-p "/[method/host]" 'method
) "method"))
1076 (should (string-equal
1077 (file-remote-p "/[method/host]" 'user
) "default-user"))
1078 (should (string-equal (file-remote-p "/[method/host]" 'host
) "host"))
1079 (should (string-equal (file-remote-p "/[method/host]" 'localname
) ""))
1080 (should (string-equal (file-remote-p "/[method/host]" 'hop
) nil
))
1082 ;; Expand `tramp-default-host'.
1083 (should (string-equal
1084 (file-remote-p "/[method/user@]")
1085 (format "/[%s/%s@%s]" "method" "user" "default-host")))
1086 (should (string-equal
1087 (file-remote-p "/[method/user@]" 'method
) "method"))
1088 (should (string-equal (file-remote-p "/[method/user@]" 'user
) "user"))
1089 (should (string-equal
1090 (file-remote-p "/[method/user@]" 'host
) "default-host"))
1091 (should (string-equal
1092 (file-remote-p "/[method/user@]" 'localname
) ""))
1093 (should (string-equal (file-remote-p "/[method/user@]" 'hop
) nil
))
1096 (should (string-equal
1097 (file-remote-p "/[method/user@host]")
1098 (format "/[%s/%s@%s]" "method" "user" "host")))
1099 (should (string-equal
1100 (file-remote-p "/[method/user@host]" 'method
) "method"))
1101 (should (string-equal
1102 (file-remote-p "/[method/user@host]" 'user
) "user"))
1103 (should (string-equal
1104 (file-remote-p "/[method/user@host]" 'host
) "host"))
1105 (should (string-equal
1106 (file-remote-p "/[method/user@host]" 'localname
) ""))
1107 (should (string-equal
1108 (file-remote-p "/[method/user@host]" 'hop
) nil
))
1111 (should (string-equal
1112 (file-remote-p "/[method/user@email@host]")
1113 (format "/[%s/%s@%s]" "method" "user@email" "host")))
1114 (should (string-equal
1116 "/[method/user@email@host]" 'method
) "method"))
1117 (should (string-equal
1119 "/[method/user@email@host]" 'user
) "user@email"))
1120 (should (string-equal
1121 (file-remote-p "/[method/user@email@host]" 'host
) "host"))
1122 (should (string-equal
1123 (file-remote-p "/[method/user@email@host]" 'localname
) ""))
1124 (should (string-equal
1125 (file-remote-p "/[method/user@email@host]" 'hop
) nil
))
1127 ;; Expand `tramp-default-method' and `tramp-default-user'.
1128 (should (string-equal
1129 (file-remote-p "/[/host#1234]")
1131 "/[%s/%s@%s]" "default-method" "default-user" "host#1234")))
1132 (should (string-equal
1133 (file-remote-p "/[/host#1234]" 'method
) "default-method"))
1134 (should (string-equal
1135 (file-remote-p "/[/host#1234]" 'user
) "default-user"))
1136 (should (string-equal
1137 (file-remote-p "/[/host#1234]" 'host
) "host#1234"))
1138 (should (string-equal (file-remote-p "/[/host#1234]" 'localname
) ""))
1139 (should (string-equal (file-remote-p "/[/host#1234]" 'hop
) nil
))
1141 ;; Expand `tramp-default-method'.
1142 (should (string-equal
1143 (file-remote-p "/[/user@host#1234]")
1144 (format "/[%s/%s@%s]" "default-method" "user" "host#1234")))
1145 (should (string-equal
1147 "/[/user@host#1234]" 'method
) "default-method"))
1148 (should (string-equal
1150 "/[/user@host#1234]" 'user
) "user"))
1151 (should (string-equal
1152 (file-remote-p "/[/user@host#1234]" 'host
) "host#1234"))
1153 (should (string-equal
1154 (file-remote-p "/[/user@host#1234]" 'localname
) ""))
1155 (should (string-equal (file-remote-p "/[/user@host#1234]" 'hop
) nil
))
1157 ;; Expand `tramp-default-method' and `tramp-default-user'.
1158 (should (string-equal
1159 (file-remote-p "/[-/host#1234]")
1161 "/[%s/%s@%s]" "default-method" "default-user" "host#1234")))
1162 (should (string-equal
1163 (file-remote-p "/[-/host#1234]" 'method
) "default-method"))
1164 (should (string-equal
1165 (file-remote-p "/[-/host#1234]" 'user
) "default-user"))
1166 (should (string-equal
1167 (file-remote-p "/[-/host#1234]" 'host
) "host#1234"))
1168 (should (string-equal (file-remote-p "/[-/host#1234]" 'localname
) ""))
1169 (should (string-equal (file-remote-p "/[-/host#1234]" 'hop
) nil
))
1171 ;; Expand `tramp-default-method'.
1172 (should (string-equal
1173 (file-remote-p "/[-/user@host#1234]")
1174 (format "/[%s/%s@%s]" "default-method" "user" "host#1234")))
1175 (should (string-equal
1177 "/[-/user@host#1234]" 'method
) "default-method"))
1178 (should (string-equal
1180 "/[-/user@host#1234]" 'user
) "user"))
1181 (should (string-equal
1182 (file-remote-p "/[-/user@host#1234]" 'host
) "host#1234"))
1183 (should (string-equal
1184 (file-remote-p "/[-/user@host#1234]" 'localname
) ""))
1185 (should (string-equal (file-remote-p "/[-/user@host#1234]" 'hop
) nil
))
1187 ;; Expand `tramp-default-user'.
1188 (should (string-equal
1189 (file-remote-p "/[method/host#1234]")
1190 (format "/[%s/%s@%s]" "method" "default-user" "host#1234")))
1191 (should (string-equal
1192 (file-remote-p "/[method/host#1234]" 'method
) "method"))
1193 (should (string-equal
1194 (file-remote-p "/[method/host#1234]" 'user
) "default-user"))
1195 (should (string-equal
1196 (file-remote-p "/[method/host#1234]" 'host
) "host#1234"))
1197 (should (string-equal
1198 (file-remote-p "/[method/host#1234]" 'localname
) ""))
1199 (should (string-equal (file-remote-p "/[method/host#1234]" 'hop
) nil
))
1202 (should (string-equal
1203 (file-remote-p "/[method/user@host#1234]")
1204 (format "/[%s/%s@%s]" "method" "user" "host#1234")))
1205 (should (string-equal
1206 (file-remote-p "/[method/user@host#1234]" 'method
) "method"))
1207 (should (string-equal
1208 (file-remote-p "/[method/user@host#1234]" 'user
) "user"))
1209 (should (string-equal
1211 "/[method/user@host#1234]" 'host
) "host#1234"))
1212 (should (string-equal
1213 (file-remote-p "/[method/user@host#1234]" 'localname
) ""))
1214 (should (string-equal
1215 (file-remote-p "/[method/user@host#1234]" 'hop
) nil
))
1217 ;; Expand `tramp-default-method' and `tramp-default-user'.
1218 (should (string-equal
1219 (file-remote-p "/[/1.2.3.4]")
1221 "/[%s/%s@%s]" "default-method" "default-user" "1.2.3.4")))
1222 (should (string-equal
1223 (file-remote-p "/[/1.2.3.4]" 'method
) "default-method"))
1224 (should (string-equal
1225 (file-remote-p "/[/1.2.3.4]" 'user
) "default-user"))
1226 (should (string-equal
1227 (file-remote-p "/[/1.2.3.4]" 'host
) "1.2.3.4"))
1228 (should (string-equal (file-remote-p "/[/1.2.3.4]" 'localname
) ""))
1229 (should (string-equal (file-remote-p "/[/1.2.3.4]" 'hop
) nil
))
1231 ;; Expand `tramp-default-method'.
1232 (should (string-equal
1233 (file-remote-p "/[/user@1.2.3.4]")
1234 (format "/[%s/%s@%s]" "default-method" "user" "1.2.3.4")))
1235 (should (string-equal
1237 "/[/user@1.2.3.4]" 'method
) "default-method"))
1238 (should (string-equal
1239 (file-remote-p "/[/user@1.2.3.4]" 'user
) "user"))
1240 (should (string-equal
1241 (file-remote-p "/[/user@1.2.3.4]" 'host
) "1.2.3.4"))
1242 (should (string-equal
1243 (file-remote-p "/[/user@1.2.3.4]" 'localname
) ""))
1244 (should (string-equal (file-remote-p "/[/user@1.2.3.4]" 'hop
) nil
))
1246 ;; Expand `tramp-default-method' and `tramp-default-user'.
1247 (should (string-equal
1248 (file-remote-p "/[-/1.2.3.4]")
1250 "/[%s/%s@%s]" "default-method" "default-user" "1.2.3.4")))
1251 (should (string-equal
1252 (file-remote-p "/[-/1.2.3.4]" 'method
) "default-method"))
1253 (should (string-equal
1254 (file-remote-p "/[-/1.2.3.4]" 'user
) "default-user"))
1255 (should (string-equal
1256 (file-remote-p "/[-/1.2.3.4]" 'host
) "1.2.3.4"))
1257 (should (string-equal (file-remote-p "/[-/1.2.3.4]" 'localname
) ""))
1258 (should (string-equal (file-remote-p "/[-/1.2.3.4]" 'hop
) nil
))
1260 ;; Expand `tramp-default-method'.
1261 (should (string-equal
1262 (file-remote-p "/[-/user@1.2.3.4]")
1263 (format "/[%s/%s@%s]" "default-method" "user" "1.2.3.4")))
1264 (should (string-equal
1266 "/[-/user@1.2.3.4]" 'method
) "default-method"))
1267 (should (string-equal
1268 (file-remote-p "/[-/user@1.2.3.4]" 'user
) "user"))
1269 (should (string-equal
1270 (file-remote-p "/[-/user@1.2.3.4]" 'host
) "1.2.3.4"))
1271 (should (string-equal
1272 (file-remote-p "/[-/user@1.2.3.4]" 'localname
) ""))
1273 (should (string-equal (file-remote-p "/[-/user@1.2.3.4]" 'hop
) nil
))
1275 ;; Expand `tramp-default-user'.
1276 (should (string-equal
1277 (file-remote-p "/[method/1.2.3.4]")
1278 (format "/[%s/%s@%s]" "method" "default-user" "1.2.3.4")))
1279 (should (string-equal
1280 (file-remote-p "/[method/1.2.3.4]" 'method
) "method"))
1281 (should (string-equal
1282 (file-remote-p "/[method/1.2.3.4]" 'user
) "default-user"))
1283 (should (string-equal
1284 (file-remote-p "/[method/1.2.3.4]" 'host
) "1.2.3.4"))
1285 (should (string-equal
1286 (file-remote-p "/[method/1.2.3.4]" 'localname
) ""))
1287 (should (string-equal (file-remote-p "/[method/1.2.3.4]" 'hop
) nil
))
1290 (should (string-equal
1291 (file-remote-p "/[method/user@1.2.3.4]")
1292 (format "/[%s/%s@%s]" "method" "user" "1.2.3.4")))
1293 (should (string-equal
1294 (file-remote-p "/[method/user@1.2.3.4]" 'method
) "method"))
1295 (should (string-equal
1296 (file-remote-p "/[method/user@1.2.3.4]" 'user
) "user"))
1297 (should (string-equal
1298 (file-remote-p "/[method/user@1.2.3.4]" 'host
) "1.2.3.4"))
1299 (should (string-equal
1300 (file-remote-p "/[method/user@1.2.3.4]" 'localname
) ""))
1301 (should (string-equal
1302 (file-remote-p "/[method/user@1.2.3.4]" 'hop
) nil
))
1304 ;; Expand `tramp-default-method', `tramp-default-user' and
1305 ;; `tramp-default-host'.
1306 (should (string-equal
1307 (file-remote-p "/[/]")
1310 "default-method" "default-user" "default-host")))
1311 (should (string-equal
1312 (file-remote-p "/[/]" 'method
) "default-method"))
1313 (should (string-equal (file-remote-p "/[/]" 'user
) "default-user"))
1314 (should (string-equal (file-remote-p "/[/]" 'host
) "default-host"))
1315 (should (string-equal (file-remote-p "/[/]" 'localname
) ""))
1316 (should (string-equal (file-remote-p "/[/]" 'hop
) nil
))
1318 ;; Expand `tramp-default-method' and `tramp-default-user'.
1319 (let ((tramp-default-host "::1"))
1320 (should (string-equal
1321 (file-remote-p "/[/]")
1324 "default-method" "default-user" "::1")))
1325 (should (string-equal
1326 (file-remote-p "/[/]" 'method
) "default-method"))
1327 (should (string-equal (file-remote-p "/[/]" 'user
) "default-user"))
1328 (should (string-equal (file-remote-p "/[/]" 'host
) "::1"))
1329 (should (string-equal (file-remote-p "/[/]" 'localname
) ""))
1330 (should (string-equal (file-remote-p "/[/]" 'hop
) nil
)))
1332 ;; Expand `tramp-default-method' and `tramp-default-user'.
1333 (should (string-equal
1334 (file-remote-p "/[/::1]")
1336 "/[%s/%s@%s]" "default-method" "default-user" "::1")))
1337 (should (string-equal
1338 (file-remote-p "/[/::1]" 'method
) "default-method"))
1339 (should (string-equal
1340 (file-remote-p "/[/::1]" 'user
) "default-user"))
1341 (should (string-equal (file-remote-p "/[/::1]" 'host
) "::1"))
1342 (should (string-equal (file-remote-p "/[/::1]" 'localname
) ""))
1343 (should (string-equal (file-remote-p "/[/::1]" 'hop
) nil
))
1345 ;; Expand `tramp-default-method'.
1346 (should (string-equal
1347 (file-remote-p "/[/user@::1]")
1348 (format "/[%s/%s@%s]" "default-method" "user" "::1")))
1349 (should (string-equal
1350 (file-remote-p "/[/user@::1]" 'method
) "default-method"))
1351 (should (string-equal (file-remote-p "/[/user@::1]" 'user
) "user"))
1352 (should (string-equal (file-remote-p "/[/user@::1]" 'host
) "::1"))
1353 (should (string-equal (file-remote-p "/[/user@::1]" 'localname
) ""))
1354 (should (string-equal (file-remote-p "/[/user@::1]" 'hop
) nil
))
1356 ;; Expand `tramp-default-method', `tramp-default-user' and
1357 ;; `tramp-default-host'.
1358 (should (string-equal
1359 (file-remote-p "/[-/]")
1362 "default-method" "default-user" "default-host")))
1363 (should (string-equal
1364 (file-remote-p "/[-/]" 'method
) "default-method"))
1365 (should (string-equal (file-remote-p "/[-/]" 'user
) "default-user"))
1366 (should (string-equal (file-remote-p "/[-/]" 'host
) "default-host"))
1367 (should (string-equal (file-remote-p "/[-/]" 'localname
) ""))
1368 (should (string-equal (file-remote-p "/[-/]" 'hop
) nil
))
1370 ;; Expand `tramp-default-method' and `tramp-default-user'.
1371 (let ((tramp-default-host "::1"))
1372 (should (string-equal
1373 (file-remote-p "/[-/]")
1376 "default-method" "default-user" "::1")))
1377 (should (string-equal
1378 (file-remote-p "/[-/]" 'method
) "default-method"))
1379 (should (string-equal (file-remote-p "/[-/]" 'user
) "default-user"))
1380 (should (string-equal (file-remote-p "/[-/]" 'host
) "::1"))
1381 (should (string-equal (file-remote-p "/[-/]" 'localname
) ""))
1382 (should (string-equal (file-remote-p "/[-/]" 'hop
) nil
)))
1384 ;; Expand `tramp-default-method' and `tramp-default-user'.
1385 (should (string-equal
1386 (file-remote-p "/[-/::1]")
1388 "/[%s/%s@%s]" "default-method" "default-user" "::1")))
1389 (should (string-equal
1390 (file-remote-p "/[-/::1]" 'method
) "default-method"))
1391 (should (string-equal
1392 (file-remote-p "/[-/::1]" 'user
) "default-user"))
1393 (should (string-equal (file-remote-p "/[-/::1]" 'host
) "::1"))
1394 (should (string-equal (file-remote-p "/[-/::1]" 'localname
) ""))
1395 (should (string-equal (file-remote-p "/[-/::1]" 'hop
) nil
))
1397 ;; Expand `tramp-default-method'.
1398 (should (string-equal
1399 (file-remote-p "/[-/user@::1]")
1400 (format "/[%s/%s@%s]" "default-method" "user" "::1")))
1401 (should (string-equal
1402 (file-remote-p "/[-/user@::1]" 'method
) "default-method"))
1403 (should (string-equal (file-remote-p "/[-/user@::1]" 'user
) "user"))
1404 (should (string-equal (file-remote-p "/[-/user@::1]" 'host
) "::1"))
1405 (should (string-equal (file-remote-p "/[-/user@::1]" 'localname
) ""))
1406 (should (string-equal (file-remote-p "/[-/user@::1]" 'hop
) nil
))
1408 ;; Expand `tramp-default-user'.
1409 (should (string-equal
1410 (file-remote-p "/[method/::1]")
1411 (format "/[%s/%s@%s]" "method" "default-user" "::1")))
1412 (should (string-equal
1413 (file-remote-p "/[method/::1]" 'method
) "method"))
1414 (should (string-equal
1415 (file-remote-p "/[method/::1]" 'user
) "default-user"))
1416 (should (string-equal (file-remote-p "/[method/::1]" 'host
) "::1"))
1417 (should (string-equal (file-remote-p "/[method/::1]" 'localname
) ""))
1418 (should (string-equal (file-remote-p "/[method/::1]" 'hop
) nil
))
1421 (should (string-equal
1422 (file-remote-p "/[method/user@::1]")
1423 (format "/[%s/%s@%s]" "method" "user" "::1")))
1424 (should (string-equal
1425 (file-remote-p "/[method/user@::1]" 'method
) "method"))
1426 (should (string-equal
1427 (file-remote-p "/[method/user@::1]" 'user
) "user"))
1428 (should (string-equal
1429 (file-remote-p "/[method/user@::1]" 'host
) "::1"))
1430 (should (string-equal
1431 (file-remote-p "/[method/user@::1]" 'localname
) ""))
1432 (should (string-equal (file-remote-p "/[method/user@::1]" 'hop
) nil
))
1434 ;; Local file name part.
1435 (should (string-equal (file-remote-p "/[/host]/:" 'localname
) "/:"))
1436 (should (string-equal (file-remote-p "/[-/host]/:" 'localname
) "/:"))
1437 (should (string-equal (file-remote-p "/[method/]:" 'localname
) ":"))
1438 (should (string-equal (file-remote-p "/[method/] " 'localname
) " "))
1439 (should (string-equal
1440 (file-remote-p "/[method/]file" 'localname
) "file"))
1441 (should (string-equal
1442 (file-remote-p "/[method/]/path/to/file" 'localname
)
1449 "/[method1/user1@host1|method2/user2@host2]/path/to/file")
1450 (format "/[%s/%s@%s|%s/%s@%s]"
1451 "method1" "user1" "host1" "method2" "user2" "host2")))
1455 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'method
)
1460 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'user
)
1465 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'host
)
1470 "/[method1/user1@host1|method2/user2@host2]/path/to/file"
1476 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'hop
)
1478 "method1" "user1" "host1")))
1484 "/[method1/user1@host1"
1485 "|method2/user2@host2"
1486 "|method3/user3@host3]/path/to/file"))
1487 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1488 "method1" "user1" "host1"
1489 "method2" "user2" "host2"
1490 "method3" "user3" "host3")))
1495 "/[method1/user1@host1"
1496 "|method2/user2@host2"
1497 "|method3/user3@host3]/path/to/file")
1504 "/[method1/user1@host1"
1505 "|method2/user2@host2"
1506 "|method3/user3@host3]/path/to/file")
1513 "/[method1/user1@host1"
1514 "|method2/user2@host2"
1515 "|method3/user3@host3]/path/to/file")
1522 "/[method1/user1@host1"
1523 "|method2/user2@host2"
1524 "|method3/user3@host3]/path/to/file")
1531 "/[method1/user1@host1"
1532 "|method2/user2@host2"
1533 "|method3/user3@host3]/path/to/file")
1535 (format "%s/%s@%s|%s/%s@%s|"
1536 "method1" "user1" "host1" "method2" "user2" "host2"))))
1539 (tramp-change-syntax syntax
))))
1541 (ert-deftest tramp-test03-file-name-defaults
()
1542 "Check default values for some methods."
1543 ;; Default values in tramp-adb.el.
1544 (should (string-equal (file-remote-p "/adb::" 'host
) ""))
1545 ;; Default values in tramp-ftp.el.
1546 (should (string-equal (file-remote-p "/-:ftp.host:" 'method
) "ftp"))
1547 (dolist (u '("ftp" "anonymous"))
1548 (should (string-equal (file-remote-p (format "/-:%s@:" u
) 'method
) "ftp")))
1549 ;; Default values in tramp-gvfs.el.
1550 (when (and (load "tramp-gvfs" 'noerror
'nomessage
)
1551 (symbol-value 'tramp-gvfs-enabled
))
1552 (should (string-equal (file-remote-p "/synce::" 'user
) nil
)))
1553 ;; Default values in tramp-sh.el.
1554 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
1556 (string-equal (file-remote-p (format "/-:root@%s:" h
) 'method
) "su")))
1557 (dolist (m '("su" "sudo" "ksu"))
1558 (should (string-equal (file-remote-p (format "/%s::" m
) 'user
) "root")))
1559 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
1561 (string-equal (file-remote-p (format "/%s::" m
) 'user
) (user-login-name))))
1562 ;; Default values in tramp-smb.el.
1563 (should (string-equal (file-remote-p "/smb::" 'user
) nil
)))
1565 (ert-deftest tramp-test04-substitute-in-file-name
()
1566 "Check `substitute-in-file-name'."
1567 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
1570 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
1572 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
1573 ;; Quoting local part.
1576 (substitute-in-file-name "/method:host:/://foo") "/method:host:/://foo"))
1579 (substitute-in-file-name "/method:host:/:/path//foo")
1580 "/method:host:/:/path//foo"))
1583 (substitute-in-file-name "/method:host:/:/path///foo")
1584 "/method:host:/:/path///foo"))
1588 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
1590 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
1591 ;; Quoting local part.
1594 (substitute-in-file-name "/method:host:/:/path/~/foo")
1595 "/method:host:/:/path/~/foo"))
1598 (substitute-in-file-name "/method:host:/:/path//~/foo")
1599 "/method:host:/:/path//~/foo"))
1601 (let (process-environment)
1604 (substitute-in-file-name "/method:host:/path/$FOO")
1605 "/method:host:/path/$FOO"))
1606 (setenv "FOO" "bla")
1609 (substitute-in-file-name "/method:host:/path/$FOO")
1610 "/method:host:/path/bla"))
1613 (substitute-in-file-name "/method:host:/path/$$FOO")
1614 "/method:host:/path/$FOO"))
1615 ;; Quoting local part.
1618 (substitute-in-file-name "/method:host:/:/path/$FOO")
1619 "/method:host:/:/path/$FOO"))
1620 (setenv "FOO" "bla")
1623 (substitute-in-file-name "/method:host:/:/path/$FOO")
1624 "/method:host:/:/path/$FOO"))
1627 (substitute-in-file-name "/method:host:/:/path/$$FOO")
1628 "/method:host:/:/path/$$FOO"))))
1630 (ert-deftest tramp-test05-expand-file-name
()
1631 "Check `expand-file-name'."
1634 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
1637 (expand-file-name "/method:host:/path/../file") "/method:host:/file"))
1638 ;; Quoting local part.
1641 (expand-file-name "/method:host:/:/path/./file")
1642 "/method:host:/:/path/file"))
1645 (expand-file-name "/method:host:/:/path/../file") "/method:host:/:/file"))
1648 (expand-file-name "/method:host:/:/~/path/./file")
1649 "/method:host:/:/~/path/file")))
1651 ;; The following test is inspired by Bug#26911. It is rather a bug in
1652 ;; `expand-file-name', and it fails for all Emacs versions. Test
1653 ;; added for later, when it is fixed.
1654 (ert-deftest tramp-test05-expand-file-name-relative
()
1655 "Check `expand-file-name'."
1656 ;; Mark as failed until bug has been fixed.
1657 :expected-result
:failed
1658 (skip-unless (tramp--test-enabled))
1659 ;; These are the methods the test doesn't fail.
1660 (when (or (tramp--test-adb-p) (tramp--test-gvfs-p)
1661 (tramp-smb-file-name-p tramp-test-temporary-file-directory
))
1662 (setf (ert-test-expected-result-type
1663 (ert-get-test 'tramp-test05-expand-file-name-relative
))
1668 (let ((default-directory
1670 (file-remote-p tramp-test-temporary-file-directory
) "/path")))
1671 (expand-file-name ".." "./"))
1672 (concat (file-remote-p tramp-test-temporary-file-directory
) "/"))))
1674 (ert-deftest tramp-test06-directory-file-name
()
1675 "Check `directory-file-name'.
1676 This checks also `file-name-as-directory', `file-name-directory',
1677 `file-name-nondirectory' and `unhandled-file-name-directory'."
1680 (directory-file-name "/method:host:/path/to/file")
1681 "/method:host:/path/to/file"))
1684 (directory-file-name "/method:host:/path/to/file/")
1685 "/method:host:/path/to/file"))
1688 (file-name-as-directory "/method:host:/path/to/file")
1689 "/method:host:/path/to/file/"))
1692 (file-name-as-directory "/method:host:/path/to/file/")
1693 "/method:host:/path/to/file/"))
1696 (file-name-directory "/method:host:/path/to/file")
1697 "/method:host:/path/to/"))
1700 (file-name-directory "/method:host:/path/to/file/")
1701 "/method:host:/path/to/file/"))
1703 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
1705 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
1707 (unhandled-file-name-directory "/method:host:/path/to/file"))
1710 (when (tramp--test-enabled) ;; Packages like tramp-gvfs.el might be disabled.
1711 (dolist (n-e '(nil t
))
1712 ;; We must clear `tramp-default-method'. On hydra, it is "ftp",
1713 ;; which ruins the tests.
1714 (let ((non-essential n-e
)
1715 tramp-default-method
)
1720 (file-remote-p tramp-test-temporary-file-directory
'method
))
1723 (file-remote-p tramp-test-temporary-file-directory
'host
))))
1724 (should (string-equal (directory-file-name file
) file
))
1727 (file-name-as-directory file
)
1728 (if (tramp-completion-mode-p)
1729 file
(concat file
"./"))))
1730 (should (string-equal (file-name-directory file
) file
))
1731 (should (string-equal (file-name-nondirectory file
) "")))))))
1733 (ert-deftest tramp-test07-file-exists-p
()
1734 "Check `file-exist-p', `write-region' and `delete-file'."
1735 (skip-unless (tramp--test-enabled))
1737 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1738 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1739 (should-not (file-exists-p tmp-name
))
1740 (write-region "foo" nil tmp-name
)
1741 (should (file-exists-p tmp-name
))
1742 (delete-file tmp-name
)
1743 (should-not (file-exists-p tmp-name
)))))
1745 (ert-deftest tramp-test08-file-local-copy
()
1746 "Check `file-local-copy'."
1747 (skip-unless (tramp--test-enabled))
1749 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1750 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
1754 (write-region "foo" nil tmp-name1
)
1755 (should (setq tmp-name2
(file-local-copy tmp-name1
)))
1757 (insert-file-contents tmp-name2
)
1758 (should (string-equal (buffer-string) "foo")))
1759 ;; Check also that a file transfer with compression works.
1760 (let ((default-directory tramp-test-temporary-file-directory
)
1761 (tramp-copy-size-limit 4)
1762 (tramp-inline-compress-start-size 2))
1763 (delete-file tmp-name2
)
1764 (should (setq tmp-name2
(file-local-copy tmp-name1
))))
1766 (delete-file tmp-name1
)
1767 (delete-file tmp-name2
)
1769 (setq tmp-name2
(file-local-copy tmp-name1
))
1770 :type tramp-file-missing
))
1774 (delete-file tmp-name1
)
1775 (delete-file tmp-name2
))))))
1777 (ert-deftest tramp-test09-insert-file-contents
()
1778 "Check `insert-file-contents'."
1779 (skip-unless (tramp--test-enabled))
1781 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1782 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1785 (write-region "foo" nil tmp-name
)
1786 (insert-file-contents tmp-name
)
1787 (should (string-equal (buffer-string) "foo"))
1788 (insert-file-contents tmp-name
)
1789 (should (string-equal (buffer-string) "foofoo"))
1791 (insert-file-contents tmp-name nil
1 3)
1792 (should (string-equal (buffer-string) "oofoofoo"))
1794 (insert-file-contents tmp-name nil nil nil
'replace
)
1795 (should (string-equal (buffer-string) "foo"))
1797 (delete-file tmp-name
)
1799 (insert-file-contents tmp-name
)
1800 :type tramp-file-missing
))
1803 (ignore-errors (delete-file tmp-name
))))))
1805 (ert-deftest tramp-test10-write-region
()
1806 "Check `write-region'."
1807 (skip-unless (tramp--test-enabled))
1809 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1810 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1813 ;; Write buffer. Use absolute and relative file name.
1816 (write-region nil nil tmp-name
))
1818 (insert-file-contents tmp-name
)
1819 (should (string-equal (buffer-string) "foo")))
1820 (delete-file tmp-name
)
1823 (should-not (file-exists-p tmp-name
))
1824 (let ((default-directory (file-name-directory tmp-name
)))
1825 (should-not (file-exists-p (file-name-nondirectory tmp-name
)))
1826 (write-region nil nil
(file-name-nondirectory tmp-name
))
1827 (should (file-exists-p (file-name-nondirectory tmp-name
))))
1828 (should (file-exists-p tmp-name
)))
1830 (insert-file-contents tmp-name
)
1831 (should (string-equal (buffer-string) "foo")))
1836 (write-region nil nil tmp-name
'append
))
1838 (insert-file-contents tmp-name
)
1839 (should (string-equal (buffer-string) "foobla")))
1842 (write-region nil nil tmp-name
3))
1844 (insert-file-contents tmp-name
)
1845 (should (string-equal (buffer-string) "foobaz")))
1848 (write-region "foo" nil tmp-name
)
1850 (insert-file-contents tmp-name
)
1851 (should (string-equal (buffer-string) "foo")))
1855 (insert "123456789")
1856 (write-region 3 5 tmp-name
))
1858 (insert-file-contents tmp-name
)
1859 (should (string-equal (buffer-string) "34")))
1861 ;; Do not overwrite if excluded.
1862 (cl-letf (((symbol-function 'y-or-n-p
) (lambda (_prompt) t
)))
1863 (write-region "foo" nil tmp-name nil nil nil
'mustbenew
))
1864 ;; `mustbenew' is passed to Tramp since Emacs 26.1.
1865 (when (tramp--test-emacs26-p)
1867 (cl-letf (((symbol-function 'y-or-n-p
) 'ignore
))
1868 (write-region "foo" nil tmp-name nil nil nil
'mustbenew
))
1869 :type
'file-already-exists
)
1871 (write-region "foo" nil tmp-name nil nil nil
'excl
)
1872 :type
'file-already-exists
)))
1875 (ignore-errors (delete-file tmp-name
))))))
1877 (ert-deftest tramp-test11-copy-file
()
1878 "Check `copy-file'."
1879 (skip-unless (tramp--test-enabled))
1881 ;; TODO: The quoted case does not work. Copy local file to remote.
1882 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
1884 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
1885 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
1886 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
1887 (dolist (source-target
1888 `(;; Copy on remote side.
1889 (,tmp-name1 .
,tmp-name2
)
1890 ;; Copy from remote side to local side.
1891 (,tmp-name1 .
,tmp-name3
)
1892 ;; Copy from local side to remote side.
1893 (,tmp-name3 .
,tmp-name1
)))
1894 (let ((source (car source-target
))
1895 (target (cdr source-target
)))
1897 ;; Copy simple file.
1900 (write-region "foo" nil source
)
1901 (should (file-exists-p source
))
1902 (copy-file source target
)
1903 (should (file-exists-p target
))
1905 (insert-file-contents target
)
1906 (should (string-equal (buffer-string) "foo")))
1908 (copy-file source target
)
1909 :type
'file-already-exists
)
1910 (copy-file source target
'ok
))
1913 (ignore-errors (delete-file source
))
1914 (ignore-errors (delete-file target
)))
1916 ;; Copy file to directory.
1919 (write-region "foo" nil source
)
1920 (should (file-exists-p source
))
1921 (make-directory target
)
1922 (should (file-directory-p target
))
1923 ;; This has been changed in Emacs 26.1.
1924 (when (tramp--test-emacs26-p)
1926 (copy-file source target
)
1927 :type
'file-already-exists
))
1928 (copy-file source
(file-name-as-directory target
))
1931 (expand-file-name (file-name-nondirectory source
) target
))))
1934 (ignore-errors (delete-file source
))
1935 (ignore-errors (delete-directory target
'recursive
)))
1937 ;; Copy directory to existing directory.
1940 (make-directory source
)
1941 (should (file-directory-p source
))
1942 (write-region "foo" nil
(expand-file-name "foo" source
))
1943 (should (file-exists-p (expand-file-name "foo" source
)))
1944 (make-directory target
)
1945 (should (file-directory-p target
))
1946 ;; Directory `target' exists already, so we must use
1947 ;; `file-name-as-directory'.
1948 (copy-file source
(file-name-as-directory target
))
1952 (concat (file-name-nondirectory source
) "/foo") target
))))
1955 (ignore-errors (delete-directory source
'recursive
))
1956 (ignore-errors (delete-directory target
'recursive
)))
1958 ;; Copy directory/file to non-existing directory.
1961 (make-directory source
)
1962 (should (file-directory-p source
))
1963 (write-region "foo" nil
(expand-file-name "foo" source
))
1964 (should (file-exists-p (expand-file-name "foo" source
)))
1965 (make-directory target
)
1966 (should (file-directory-p target
))
1969 (expand-file-name (file-name-nondirectory source
) target
))
1973 (concat (file-name-nondirectory source
) "/foo") target
))))
1976 (ignore-errors (delete-directory source
'recursive
))
1977 (ignore-errors (delete-directory target
'recursive
))))))))
1979 (ert-deftest tramp-test12-rename-file
()
1980 "Check `rename-file'."
1981 (skip-unless (tramp--test-enabled))
1983 ;; TODO: The quoted case does not work.
1984 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
1986 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
1987 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
1988 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
1989 (dolist (source-target
1990 `(;; Rename on remote side.
1991 (,tmp-name1 .
,tmp-name2
)
1992 ;; Rename from remote side to local side.
1993 (,tmp-name1 .
,tmp-name3
)
1994 ;; Rename from local side to remote side.
1995 (,tmp-name3 .
,tmp-name1
)))
1996 (let ((source (car source-target
))
1997 (target (cdr source-target
)))
1999 ;; Rename simple file.
2002 (write-region "foo" nil source
)
2003 (should (file-exists-p source
))
2004 (rename-file source target
)
2005 (should-not (file-exists-p source
))
2006 (should (file-exists-p target
))
2008 (insert-file-contents target
)
2009 (should (string-equal (buffer-string) "foo")))
2010 (write-region "foo" nil source
)
2011 (should (file-exists-p source
))
2013 (rename-file source target
)
2014 :type
'file-already-exists
)
2015 (rename-file source target
'ok
)
2016 (should-not (file-exists-p source
)))
2019 (ignore-errors (delete-file source
))
2020 (ignore-errors (delete-file target
)))
2022 ;; Rename file to directory.
2025 (write-region "foo" nil source
)
2026 (should (file-exists-p source
))
2027 (make-directory target
)
2028 (should (file-directory-p target
))
2029 ;; This has been changed in Emacs 26.1.
2030 (when (tramp--test-emacs26-p)
2032 (rename-file source target
)
2033 :type
'file-already-exists
))
2034 (rename-file source
(file-name-as-directory target
))
2035 (should-not (file-exists-p source
))
2038 (expand-file-name (file-name-nondirectory source
) target
))))
2041 (ignore-errors (delete-file source
))
2042 (ignore-errors (delete-directory target
'recursive
)))
2044 ;; Rename directory to existing directory.
2047 (make-directory source
)
2048 (should (file-directory-p source
))
2049 (write-region "foo" nil
(expand-file-name "foo" source
))
2050 (should (file-exists-p (expand-file-name "foo" source
)))
2051 (make-directory target
)
2052 (should (file-directory-p target
))
2053 ;; Directory `target' exists already, so we must use
2054 ;; `file-name-as-directory'.
2055 (rename-file source
(file-name-as-directory target
))
2056 (should-not (file-exists-p source
))
2060 (concat (file-name-nondirectory source
) "/foo") target
))))
2063 (ignore-errors (delete-directory source
'recursive
))
2064 (ignore-errors (delete-directory target
'recursive
)))
2066 ;; Rename directory/file to non-existing directory.
2069 (make-directory source
)
2070 (should (file-directory-p source
))
2071 (write-region "foo" nil
(expand-file-name "foo" source
))
2072 (should (file-exists-p (expand-file-name "foo" source
)))
2073 (make-directory target
)
2074 (should (file-directory-p target
))
2077 (expand-file-name (file-name-nondirectory source
) target
))
2078 (should-not (file-exists-p source
))
2082 (concat (file-name-nondirectory source
) "/foo") target
))))
2085 (ignore-errors (delete-directory source
'recursive
))
2086 (ignore-errors (delete-directory target
'recursive
))))))))
2088 (ert-deftest tramp-test13-make-directory
()
2089 "Check `make-directory'.
2090 This tests also `file-directory-p' and `file-accessible-directory-p'."
2091 (skip-unless (tramp--test-enabled))
2093 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2094 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2095 (tmp-name2 (expand-file-name "foo/bar" tmp-name1
)))
2098 (make-directory tmp-name1
)
2099 (should (file-directory-p tmp-name1
))
2100 (should (file-accessible-directory-p tmp-name1
))
2101 (should-error (make-directory tmp-name2
) :type
'file-error
)
2102 (make-directory tmp-name2
'parents
)
2103 (should (file-directory-p tmp-name2
))
2104 (should (file-accessible-directory-p tmp-name2
))
2105 ;; If PARENTS is non-nil, `make-directory' shall not
2106 ;; signal an error when DIR exists already.
2107 (make-directory tmp-name2
'parents
))
2110 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2112 (ert-deftest tramp-test14-delete-directory
()
2113 "Check `delete-directory'."
2114 (skip-unless (tramp--test-enabled))
2116 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2117 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2118 ;; Delete empty directory.
2119 (make-directory tmp-name
)
2120 (should (file-directory-p tmp-name
))
2121 (delete-directory tmp-name
)
2122 (should-not (file-directory-p tmp-name
))
2123 ;; Delete non-empty directory.
2124 (make-directory tmp-name
)
2125 (should (file-directory-p tmp-name
))
2126 (write-region "foo" nil
(expand-file-name "bla" tmp-name
))
2127 (should (file-exists-p (expand-file-name "bla" tmp-name
)))
2128 (should-error (delete-directory tmp-name
) :type
'file-error
)
2129 (delete-directory tmp-name
'recursive
)
2130 (should-not (file-directory-p tmp-name
)))))
2132 (ert-deftest tramp-test15-copy-directory
()
2133 "Check `copy-directory'."
2134 (skip-unless (tramp--test-enabled))
2136 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2137 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2138 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2139 (tmp-name3 (expand-file-name
2140 (file-name-nondirectory tmp-name1
) tmp-name2
))
2141 (tmp-name4 (expand-file-name "foo" tmp-name1
))
2142 (tmp-name5 (expand-file-name "foo" tmp-name2
))
2143 (tmp-name6 (expand-file-name "foo" tmp-name3
)))
2145 ;; Copy complete directory.
2148 ;; Copy empty directory.
2149 (make-directory tmp-name1
)
2150 (write-region "foo" nil tmp-name4
)
2151 (should (file-directory-p tmp-name1
))
2152 (should (file-exists-p tmp-name4
))
2153 (copy-directory tmp-name1 tmp-name2
)
2154 (should (file-directory-p tmp-name2
))
2155 (should (file-exists-p tmp-name5
))
2156 ;; Target directory does exist already.
2157 ;; This has been changed in Emacs 26.1.
2158 (when (tramp--test-emacs26-p)
2160 (copy-directory tmp-name1 tmp-name2
)
2162 (copy-directory tmp-name1
(file-name-as-directory tmp-name2
))
2163 (should (file-directory-p tmp-name3
))
2164 (should (file-exists-p tmp-name6
)))
2168 (delete-directory tmp-name1
'recursive
)
2169 (delete-directory tmp-name2
'recursive
)))
2171 ;; Copy directory contents.
2174 ;; Copy empty directory.
2175 (make-directory tmp-name1
)
2176 (write-region "foo" nil tmp-name4
)
2177 (should (file-directory-p tmp-name1
))
2178 (should (file-exists-p tmp-name4
))
2179 (copy-directory tmp-name1 tmp-name2 nil
'parents
'contents
)
2180 (should (file-directory-p tmp-name2
))
2181 (should (file-exists-p tmp-name5
))
2182 ;; Target directory does exist already.
2183 (delete-file tmp-name5
)
2184 (should-not (file-exists-p tmp-name5
))
2186 tmp-name1
(file-name-as-directory tmp-name2
)
2187 nil
'parents
'contents
)
2188 (should (file-directory-p tmp-name2
))
2189 (should (file-exists-p tmp-name5
))
2190 (should-not (file-directory-p tmp-name3
))
2191 (should-not (file-exists-p tmp-name6
)))
2195 (delete-directory tmp-name1
'recursive
)
2196 (delete-directory tmp-name2
'recursive
))))))
2198 (ert-deftest tramp-test16-directory-files
()
2199 "Check `directory-files'."
2200 (skip-unless (tramp--test-enabled))
2202 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2203 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2204 (tmp-name2 (expand-file-name "bla" tmp-name1
))
2205 (tmp-name3 (expand-file-name "foo" tmp-name1
)))
2208 (make-directory tmp-name1
)
2209 (write-region "foo" nil tmp-name2
)
2210 (write-region "bla" nil tmp-name3
)
2211 (should (file-directory-p tmp-name1
))
2212 (should (file-exists-p tmp-name2
))
2213 (should (file-exists-p tmp-name3
))
2214 (should (equal (directory-files tmp-name1
) '("." ".." "bla" "foo")))
2215 (should (equal (directory-files tmp-name1
'full
)
2216 `(,(concat tmp-name1
"/.")
2217 ,(concat tmp-name1
"/..")
2218 ,tmp-name2
,tmp-name3
)))
2219 (should (equal (directory-files
2220 tmp-name1 nil directory-files-no-dot-files-regexp
)
2222 (should (equal (directory-files
2223 tmp-name1
'full directory-files-no-dot-files-regexp
)
2224 `(,tmp-name2
,tmp-name3
))))
2227 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2229 ;; This is not a file name handler test. But Tramp needed to apply an
2230 ;; advice for older Emacs versions, so we check that this has been fixed.
2231 (ert-deftest tramp-test16-file-expand-wildcards
()
2232 "Check `file-expand-wildcards'."
2233 (skip-unless (tramp--test-enabled))
2235 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2236 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2237 (tmp-name2 (expand-file-name "foo" tmp-name1
))
2238 (tmp-name3 (expand-file-name "bar" tmp-name1
))
2239 (tmp-name4 (expand-file-name "baz" tmp-name1
))
2240 (default-directory tmp-name1
))
2243 (make-directory tmp-name1
)
2244 (write-region "foo" nil tmp-name2
)
2245 (write-region "bar" nil tmp-name3
)
2246 (write-region "baz" nil tmp-name4
)
2247 (should (file-directory-p tmp-name1
))
2248 (should (file-exists-p tmp-name2
))
2249 (should (file-exists-p tmp-name3
))
2250 (should (file-exists-p tmp-name4
))
2252 ;; `sort' works destructive.
2254 (equal (file-expand-wildcards "*")
2255 (sort (copy-sequence '("foo" "bar" "baz")) 'string
<)))
2257 (equal (file-expand-wildcards "ba?")
2258 (sort (copy-sequence '("bar" "baz")) 'string
<)))
2260 (equal (file-expand-wildcards "ba[rz]")
2261 (sort (copy-sequence '("bar" "baz")) 'string
<)))
2265 (file-expand-wildcards "*" 'full
)
2267 (copy-sequence `(,tmp-name2
,tmp-name3
,tmp-name4
)) 'string
<)))
2270 (file-expand-wildcards "ba?" 'full
)
2271 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2274 (file-expand-wildcards "ba[rz]" 'full
)
2275 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2279 (file-expand-wildcards (concat tmp-name1
"/" "*"))
2281 (copy-sequence `(,tmp-name2
,tmp-name3
,tmp-name4
)) 'string
<)))
2284 (file-expand-wildcards (concat tmp-name1
"/" "ba?"))
2285 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2288 (file-expand-wildcards (concat tmp-name1
"/" "ba[rz]"))
2289 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<))))
2293 (delete-directory tmp-name1
'recursive
))))))
2295 (ert-deftest tramp-test17-insert-directory
()
2296 "Check `insert-directory'."
2297 (skip-unless (tramp--test-enabled))
2299 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2301 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2302 (tmp-name2 (expand-file-name "foo" tmp-name1
))
2303 ;; We test for the summary line. Keyword "total" could be localized.
2304 (process-environment
2305 (append '("LANG=C" "LANGUAGE=C" "LC_ALL=C") process-environment
)))
2308 (make-directory tmp-name1
)
2309 (write-region "foo" nil tmp-name2
)
2310 (should (file-directory-p tmp-name1
))
2311 (should (file-exists-p tmp-name2
))
2313 (insert-directory tmp-name1 nil
)
2314 (goto-char (point-min))
2315 (should (looking-at-p (regexp-quote tmp-name1
))))
2317 (insert-directory tmp-name1
"-al")
2318 (goto-char (point-min))
2320 (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1
)))))
2322 (insert-directory (file-name-as-directory tmp-name1
) "-al")
2323 (goto-char (point-min))
2325 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1
)))))
2328 (file-name-as-directory tmp-name1
) "-al" nil
'full-directory-p
)
2329 (goto-char (point-min))
2333 ;; There might be a summary line.
2334 "\\(total.+[[:digit:]]+\n\\)?"
2335 ;; We don't know in which order ".", ".." and "foo" appear.
2336 "\\(.+ \\(\\.?\\.\\|foo\\)\n\\)\\{3\\}")))))
2339 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2341 (ert-deftest tramp-test17-dired-with-wildcards
()
2342 "Check `dired' with wildcards."
2343 (skip-unless (tramp--test-enabled))
2344 (skip-unless (tramp--test-sh-p))
2345 (skip-unless (not (tramp--test-rsync-p)))
2346 ;; Since Emacs 26.1.
2347 (skip-unless (fboundp 'insert-directory-wildcard-in-dir-p
))
2349 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2351 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2353 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2354 (tmp-name3 (expand-file-name "foo" tmp-name1
))
2355 (tmp-name4 (expand-file-name "bar" tmp-name2
))
2356 (tramp-test-temporary-file-directory
2358 (if quoted
'tramp-compat-file-name-quote
'identity
)
2359 tramp-test-temporary-file-directory
))
2363 (make-directory tmp-name1
)
2364 (write-region "foo" nil tmp-name3
)
2365 (should (file-directory-p tmp-name1
))
2366 (should (file-exists-p tmp-name3
))
2367 (make-directory tmp-name2
)
2368 (write-region "foo" nil tmp-name4
)
2369 (should (file-directory-p tmp-name2
))
2370 (should (file-exists-p tmp-name4
))
2372 ;; Check for expanded directory names.
2373 (with-current-buffer
2377 "tramp-test*" tramp-test-temporary-file-directory
)))
2378 (goto-char (point-min))
2383 tmp-name1 tramp-test-temporary-file-directory
))))
2384 (goto-char (point-min))
2389 tmp-name2 tramp-test-temporary-file-directory
)))))
2390 (kill-buffer buffer
)
2392 ;; Check for expanded directory and file names.
2393 (with-current-buffer
2397 "tramp-test*/*" tramp-test-temporary-file-directory
)))
2398 (goto-char (point-min))
2403 tmp-name3 tramp-test-temporary-file-directory
))))
2404 (goto-char (point-min))
2410 tramp-test-temporary-file-directory
)))))
2411 (kill-buffer buffer
)
2413 ;; Check for special characters.
2414 (setq tmp-name3
(expand-file-name "*?" tmp-name1
))
2415 (setq tmp-name4
(expand-file-name "[a-z0-9]" tmp-name2
))
2416 (write-region "foo" nil tmp-name3
)
2417 (should (file-exists-p tmp-name3
))
2418 (write-region "foo" nil tmp-name4
)
2419 (should (file-exists-p tmp-name4
))
2421 (with-current-buffer
2425 "tramp-test*/*" tramp-test-temporary-file-directory
)))
2426 (goto-char (point-min))
2431 tmp-name3 tramp-test-temporary-file-directory
))))
2432 (goto-char (point-min))
2438 tramp-test-temporary-file-directory
)))))
2439 (kill-buffer buffer
))
2442 (ignore-errors (kill-buffer buffer
))
2443 (ignore-errors (delete-directory tmp-name1
'recursive
))
2444 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
2446 ;; Method "smb" supports `make-symbolic-link' only if the remote host
2447 ;; has CIFS capabilities. tramp-adb.el and tramp-gvfs.el do not
2448 ;; support symbolic links at all.
2449 (defmacro tramp--test-ignore-make-symbolic-link-error
(&rest body
)
2450 "Run BODY, ignoring \"make-symbolic-link not supported\" file error."
2451 (declare (indent defun
) (debug t
))
2452 `(condition-case err
2455 (unless (and (eq (car err
) 'file-error
)
2456 (string-equal (error-message-string err
)
2457 "make-symbolic-link not supported"))
2458 (signal (car err
) (cdr err
))))))
2460 (ert-deftest tramp-test18-file-attributes
()
2461 "Check `file-attributes'.
2462 This tests also `file-readable-p', `file-regular-p' and
2463 `file-ownership-preserved-p'."
2464 (skip-unless (tramp--test-enabled))
2466 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2467 ;; We must use `file-truename' for the temporary directory,
2468 ;; because it could be located on a symlinked directory. This
2469 ;; would let the test fail.
2470 (let* ((tramp-test-temporary-file-directory
2471 (file-truename tramp-test-temporary-file-directory
))
2472 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
2473 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2474 ;; File name with "//".
2478 (file-remote-p tmp-name1
)
2479 (replace-regexp-in-string
2480 "/" "//" (file-remote-p tmp-name1
'localname
))))
2484 ;; `file-ownership-preserved-p' should return t for
2485 ;; non-existing files. It is implemented only in tramp-sh.el.
2486 (when (tramp--test-sh-p)
2487 (should (file-ownership-preserved-p tmp-name1
'group
)))
2488 (write-region "foo" nil tmp-name1
)
2489 (should (file-exists-p tmp-name1
))
2490 (should (file-readable-p tmp-name1
))
2491 (should (file-regular-p tmp-name1
))
2492 (when (tramp--test-sh-p)
2493 (should (file-ownership-preserved-p tmp-name1
'group
)))
2495 ;; We do not test inodes and device numbers.
2496 (setq attr
(file-attributes tmp-name1
))
2497 (should (consp attr
))
2498 (should (null (car attr
)))
2499 (should (numberp (nth 1 attr
))) ;; Link.
2500 (should (numberp (nth 2 attr
))) ;; Uid.
2501 (should (numberp (nth 3 attr
))) ;; Gid.
2502 ;; Last access time.
2503 (should (stringp (current-time-string (nth 4 attr
))))
2504 ;; Last modification time.
2505 (should (stringp (current-time-string (nth 5 attr
))))
2506 ;; Last status change time.
2507 (should (stringp (current-time-string (nth 6 attr
))))
2508 (should (numberp (nth 7 attr
))) ;; Size.
2509 (should (stringp (nth 8 attr
))) ;; Modes.
2511 (setq attr
(file-attributes tmp-name1
'string
))
2512 (should (stringp (nth 2 attr
))) ;; Uid.
2513 (should (stringp (nth 3 attr
))) ;; Gid.
2515 (tramp--test-ignore-make-symbolic-link-error
2516 (when (tramp--test-sh-p)
2517 (should (file-ownership-preserved-p tmp-name2
'group
)))
2518 (make-symbolic-link tmp-name1 tmp-name2
)
2519 (should (file-exists-p tmp-name2
))
2520 (should (file-symlink-p tmp-name2
))
2521 (when (tramp--test-sh-p)
2522 (should (file-ownership-preserved-p tmp-name2
'group
)))
2523 (setq attr
(file-attributes tmp-name2
))
2527 (if quoted
'tramp-compat-file-name-quote
'identity
)
2529 (file-remote-p (file-truename tmp-name1
) 'localname
)))
2530 (delete-file tmp-name2
))
2532 ;; Check, that "//" in symlinks are handled properly.
2534 (let ((default-directory tramp-test-temporary-file-directory
))
2538 (tramp-file-name-localname
2539 (tramp-dissect-file-name tmp-name3
))
2540 (tramp-file-name-localname
2541 (tramp-dissect-file-name tmp-name2
)))
2543 (when (file-symlink-p tmp-name2
)
2544 (setq attr
(file-attributes tmp-name2
))
2548 (tramp-file-name-localname
2549 (tramp-dissect-file-name tmp-name3
))))
2550 (delete-file tmp-name2
))
2552 (when (tramp--test-sh-p)
2553 (should (file-ownership-preserved-p tmp-name1
'group
)))
2554 (delete-file tmp-name1
)
2555 (make-directory tmp-name1
)
2556 (should (file-exists-p tmp-name1
))
2557 (should (file-readable-p tmp-name1
))
2558 (should-not (file-regular-p tmp-name1
))
2559 (when (tramp--test-sh-p)
2560 (should (file-ownership-preserved-p tmp-name1
'group
)))
2561 (setq attr
(file-attributes tmp-name1
))
2562 (should (eq (car attr
) t
)))
2565 (ignore-errors (delete-directory tmp-name1
))
2566 (ignore-errors (delete-file tmp-name1
))
2567 (ignore-errors (delete-file tmp-name2
))))))
2569 (ert-deftest tramp-test19-directory-files-and-attributes
()
2570 "Check `directory-files-and-attributes'."
2571 (skip-unless (tramp--test-enabled))
2573 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2574 ;; `directory-files-and-attributes' contains also values for
2575 ;; "../". Ensure that this doesn't change during tests, for
2576 ;; example due to handling temporary files.
2577 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2578 (tmp-name2 (expand-file-name "bla" tmp-name1
))
2582 (make-directory tmp-name1
)
2583 (should (file-directory-p tmp-name1
))
2584 (make-directory tmp-name2
)
2585 (should (file-directory-p tmp-name2
))
2586 (write-region "foo" nil
(expand-file-name "foo" tmp-name2
))
2587 (write-region "bar" nil
(expand-file-name "bar" tmp-name2
))
2588 (write-region "boz" nil
(expand-file-name "boz" tmp-name2
))
2589 (setq attr
(directory-files-and-attributes tmp-name2
))
2590 (should (consp attr
))
2591 ;; Dumb remote shells without perl(1) or stat(1) are not
2592 ;; able to return the date correctly. They say "don't know".
2597 5 (file-attributes (expand-file-name (car elt
) tmp-name2
)))
2600 (equal (file-attributes (expand-file-name (car elt
) tmp-name2
))
2602 (setq attr
(directory-files-and-attributes tmp-name2
'full
))
2604 (unless (equal (nth 5 (file-attributes (car elt
))) '(0 0))
2606 (equal (file-attributes (car elt
)) (cdr elt
)))))
2607 (setq attr
(directory-files-and-attributes tmp-name2 nil
"^b"))
2608 (should (equal (mapcar 'car attr
) '("bar" "boz"))))
2611 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2613 (ert-deftest tramp-test20-file-modes
()
2614 "Check `file-modes'.
2615 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
2616 (skip-unless (tramp--test-enabled))
2617 (skip-unless (tramp--test-sh-p))
2619 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2620 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2623 (write-region "foo" nil tmp-name
)
2624 (should (file-exists-p tmp-name
))
2625 (set-file-modes tmp-name
#o777
)
2626 (should (= (file-modes tmp-name
) #o777
))
2627 (should (file-executable-p tmp-name
))
2628 (should (file-writable-p tmp-name
))
2629 (set-file-modes tmp-name
#o444
)
2630 (should (= (file-modes tmp-name
) #o444
))
2631 (should-not (file-executable-p tmp-name
))
2632 ;; A file is always writable for user "root".
2633 (unless (zerop (nth 2 (file-attributes tmp-name
)))
2634 (should-not (file-writable-p tmp-name
))))
2637 (ignore-errors (delete-file tmp-name
))))))
2639 (ert-deftest tramp-test21-file-links
()
2640 "Check `file-symlink-p'.
2641 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2642 (skip-unless (tramp--test-enabled))
2643 ;; The semantics has changed heavily in Emacs 26.1. We cannot test
2644 ;; older Emacsen, therefore.
2645 (skip-unless (tramp--test-emacs26-p))
2647 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2648 ;; We must use `file-truename' for the temporary directory,
2649 ;; because it could be located on a symlinked directory. This
2650 ;; would let the test fail.
2651 (let* ((tramp-test-temporary-file-directory
2652 (file-truename tramp-test-temporary-file-directory
))
2653 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
2654 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2655 (tmp-name3 (tramp--test-make-temp-name 'local quoted
))
2656 (tmp-name4 (tramp--test-make-temp-name nil quoted
))
2658 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name4
)))
2659 ;; Check `make-symbolic-link'.
2661 (tramp--test-ignore-make-symbolic-link-error
2662 (write-region "foo" nil tmp-name1
)
2663 (should (file-exists-p tmp-name1
))
2664 (make-symbolic-link tmp-name1 tmp-name2
)
2668 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2669 (file-remote-p tmp-name1
'localname
))
2670 (file-symlink-p tmp-name2
)))
2672 (make-symbolic-link tmp-name1 tmp-name2
)
2673 :type
'file-already-exists
)
2674 ;; number means interactive case.
2675 (cl-letf (((symbol-function 'yes-or-no-p
) 'ignore
))
2677 (make-symbolic-link tmp-name1 tmp-name2
0)
2678 :type
'file-already-exists
))
2679 (cl-letf (((symbol-function 'yes-or-no-p
) (lambda (_prompt) t
)))
2680 (make-symbolic-link tmp-name1 tmp-name2
0)
2684 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2685 (file-remote-p tmp-name1
'localname
))
2686 (file-symlink-p tmp-name2
))))
2687 (make-symbolic-link tmp-name1 tmp-name2
'ok-if-already-exists
)
2691 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2692 (file-remote-p tmp-name1
'localname
))
2693 (file-symlink-p tmp-name2
)))
2694 ;; If we use the local part of `tmp-name1', it shall still work.
2696 (file-remote-p tmp-name1
'localname
)
2697 tmp-name2
'ok-if-already-exists
)
2701 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2702 (file-remote-p tmp-name1
'localname
))
2703 (file-symlink-p tmp-name2
)))
2704 ;; `tmp-name3' is a local file name. Therefore, the link
2705 ;; target remains unchanged, even if quoted.
2706 (make-symbolic-link tmp-name1 tmp-name3
)
2708 (string-equal tmp-name1
(file-symlink-p tmp-name3
)))
2709 ;; Check directory as newname.
2710 (make-directory tmp-name4
)
2712 (make-symbolic-link tmp-name1 tmp-name4
)
2713 :type
'file-already-exists
)
2714 (make-symbolic-link tmp-name1
(file-name-as-directory tmp-name4
))
2718 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2719 (file-remote-p tmp-name1
'localname
))
2720 (file-symlink-p tmp-name5
)))
2721 ;; `smbclient' does not show symlinks in directories, so
2722 ;; we cannot delete a non-empty directory. We delete the
2724 (delete-file tmp-name5
))
2728 (delete-file tmp-name1
)
2729 (delete-file tmp-name2
)
2730 (delete-file tmp-name3
)
2731 (delete-directory tmp-name4
'recursive
)))
2733 ;; Check `add-name-to-file'.
2736 (write-region "foo" nil tmp-name1
)
2737 (should (file-exists-p tmp-name1
))
2738 (add-name-to-file tmp-name1 tmp-name2
)
2739 (should (file-regular-p tmp-name2
))
2741 (add-name-to-file tmp-name1 tmp-name2
)
2742 :type
'file-already-exists
)
2743 ;; A number means interactive case.
2744 (cl-letf (((symbol-function 'yes-or-no-p
) 'ignore
))
2746 (add-name-to-file tmp-name1 tmp-name2
0)
2747 :type
'file-already-exists
))
2748 (cl-letf (((symbol-function 'yes-or-no-p
) (lambda (_prompt) t
)))
2749 (add-name-to-file tmp-name1 tmp-name2
0)
2750 (should (file-regular-p tmp-name2
)))
2751 (add-name-to-file tmp-name1 tmp-name2
'ok-if-already-exists
)
2752 (should-not (file-symlink-p tmp-name2
))
2753 (should (file-regular-p tmp-name2
))
2754 ;; `tmp-name3' is a local file name.
2756 (add-name-to-file tmp-name1 tmp-name3
)
2758 ;; Check directory as newname.
2759 (make-directory tmp-name4
)
2761 (add-name-to-file tmp-name1 tmp-name4
)
2762 :type
'file-already-exists
)
2763 (add-name-to-file tmp-name1
(file-name-as-directory tmp-name4
))
2766 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name4
))))
2770 (delete-file tmp-name1
)
2771 (delete-file tmp-name2
)
2772 (delete-directory tmp-name4
'recursive
)))
2774 ;; Check `file-truename'.
2776 (tramp--test-ignore-make-symbolic-link-error
2777 (write-region "foo" nil tmp-name1
)
2778 (should (file-exists-p tmp-name1
))
2779 (should (string-equal tmp-name1
(file-truename tmp-name1
)))
2780 (make-symbolic-link tmp-name1 tmp-name2
)
2781 (should (file-symlink-p tmp-name2
))
2782 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
2784 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
)))
2785 (should (file-equal-p tmp-name1 tmp-name2
))
2786 ;; Symbolic links could look like a remote file name.
2787 ;; They must be quoted then.
2788 (delete-file tmp-name2
)
2789 (make-symbolic-link "/penguin:motd:" tmp-name2
)
2790 (should (file-symlink-p tmp-name2
))
2793 (file-truename tmp-name2
)
2794 (tramp-compat-file-name-quote
2795 (concat (file-remote-p tmp-name2
) "/penguin:motd:"))))
2796 ;; `tmp-name3' is a local file name.
2797 (make-symbolic-link tmp-name1 tmp-name3
)
2798 (should (file-symlink-p tmp-name3
))
2799 (should-not (string-equal tmp-name3
(file-truename tmp-name3
)))
2800 ;; `file-truename' returns a quoted file name for `tmp-name3'.
2801 ;; We must unquote it.
2804 (file-truename tmp-name1
)
2805 (tramp-compat-file-name-unquote (file-truename tmp-name3
)))))
2809 (delete-file tmp-name1
)
2810 (delete-file tmp-name2
)
2811 (delete-file tmp-name3
)))
2813 ;; Symbolic links could be nested.
2815 (tramp--test-ignore-make-symbolic-link-error
2816 (make-directory tmp-name1
)
2817 (should (file-directory-p tmp-name1
))
2818 (let* ((tramp-test-temporary-file-directory
2819 (file-truename tmp-name1
))
2820 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2821 (tmp-name3 tmp-name2
)
2822 (number-nesting 15))
2823 (dotimes (_ number-nesting
)
2826 (setq tmp-name3
(tramp--test-make-temp-name nil quoted
))))
2829 (file-truename tmp-name2
)
2830 (file-truename tmp-name3
)))
2832 (with-temp-buffer (insert-file-contents tmp-name2
))
2833 :type tramp-file-missing
)
2835 (with-temp-buffer (insert-file-contents tmp-name3
))
2836 :type tramp-file-missing
)
2837 ;; `directory-files' does not show symlinks to
2838 ;; non-existing targets in the "smb" case. So we remove
2839 ;; the symlinks manually.
2840 (while (stringp (setq tmp-name2
(file-symlink-p tmp-name3
)))
2841 (delete-file tmp-name3
)
2842 (setq tmp-name3
(concat (file-remote-p tmp-name3
) tmp-name2
)))))
2845 (ignore-errors (delete-directory tmp-name1
'recursive
)))
2847 ;; Detect cyclic symbolic links.
2849 (tramp--test-ignore-make-symbolic-link-error
2850 (make-symbolic-link tmp-name2 tmp-name1
)
2851 (should (file-symlink-p tmp-name1
))
2852 (make-symbolic-link tmp-name1 tmp-name2
)
2853 (should (file-symlink-p tmp-name2
))
2854 (should-error (file-truename tmp-name1
) :type
'file-error
))
2858 (delete-file tmp-name1
)
2859 (delete-file tmp-name2
)))
2861 ;; `file-truename' shall preserve trailing link of directories.
2862 (unless (file-symlink-p tramp-test-temporary-file-directory
)
2863 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory
))
2864 (dir2 (file-name-as-directory dir1
)))
2865 (should (string-equal (file-truename dir1
) (expand-file-name dir1
)))
2867 (string-equal (file-truename dir2
) (expand-file-name dir2
))))))))
2869 (ert-deftest tramp-test22-file-times
()
2870 "Check `set-file-times' and `file-newer-than-file-p'."
2871 (skip-unless (tramp--test-enabled))
2872 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
2874 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2875 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2876 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2877 (tmp-name3 (tramp--test-make-temp-name nil quoted
)))
2880 (write-region "foo" nil tmp-name1
)
2881 (should (file-exists-p tmp-name1
))
2882 (should (consp (nth 5 (file-attributes tmp-name1
))))
2883 ;; '(0 0) means don't know, and will be replaced by
2884 ;; `current-time'. Therefore, we use '(0 1). We skip the
2885 ;; test, if the remote handler is not able to set the
2887 (skip-unless (set-file-times tmp-name1
'(0 1)))
2888 ;; Dumb remote shells without perl(1) or stat(1) are not
2889 ;; able to return the date correctly. They say "don't know".
2890 (unless (equal (nth 5 (file-attributes tmp-name1
)) '(0 0))
2891 (should (equal (nth 5 (file-attributes tmp-name1
)) '(0 1)))
2892 (write-region "bla" nil tmp-name2
)
2893 (should (file-exists-p tmp-name2
))
2894 (should (file-newer-than-file-p tmp-name2 tmp-name1
))
2895 ;; `tmp-name3' does not exist.
2896 (should (file-newer-than-file-p tmp-name2 tmp-name3
))
2897 (should-not (file-newer-than-file-p tmp-name3 tmp-name1
))))
2901 (delete-file tmp-name1
)
2902 (delete-file tmp-name2
))))))
2904 (ert-deftest tramp-test23-visited-file-modtime
()
2905 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
2906 (skip-unless (tramp--test-enabled))
2908 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2909 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2912 (write-region "foo" nil tmp-name
)
2913 (should (file-exists-p tmp-name
))
2915 (insert-file-contents tmp-name
)
2916 (should (verify-visited-file-modtime))
2917 (set-visited-file-modtime '(0 1))
2918 (should (verify-visited-file-modtime))
2919 (should (equal (visited-file-modtime) '(0 1 0 0)))))
2922 (ignore-errors (delete-file tmp-name
))))))
2924 ;; This test is inspired by Bug#29149.
2925 (ert-deftest tramp-test24-file-acl
()
2926 "Check that `file-acl' and `set-file-acl' work proper."
2927 (skip-unless (tramp--test-enabled))
2928 (skip-unless (file-acl tramp-test-temporary-file-directory
))
2930 ;; TODO: The quoted case does not work. Copy local file to remote.
2931 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
2933 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2934 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2935 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
2936 ;; Both files are remote.
2939 ;; Two files with same ACLs.
2940 (write-region "foo" nil tmp-name1
)
2941 (should (file-exists-p tmp-name1
))
2942 (should (file-acl tmp-name1
))
2943 (copy-file tmp-name1 tmp-name2 nil nil nil
'preserve-permissions
)
2944 (should (file-acl tmp-name2
))
2945 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name2
)))
2946 ;; Different permissions mean different ACLs.
2947 (set-file-modes tmp-name1
#o777
)
2948 (set-file-modes tmp-name2
#o444
)
2950 (string-equal (file-acl tmp-name1
) (file-acl tmp-name2
)))
2952 (should (set-file-acl tmp-name2
(file-acl tmp-name1
)))
2953 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name2
)))
2954 ;; An invalid ACL does not harm.
2955 (should-not (set-file-acl tmp-name2
"foo")))
2958 (ignore-errors (delete-file tmp-name1
))
2959 (ignore-errors (delete-file tmp-name2
)))
2961 ;; Remote and local file.
2963 (when (and (file-acl temporary-file-directory
)
2964 (not (tramp--test-windows-nt-or-smb-p)))
2965 ;; Two files with same ACLs.
2966 (write-region "foo" nil tmp-name1
)
2967 (should (file-exists-p tmp-name1
))
2968 (should (file-acl tmp-name1
))
2969 (copy-file tmp-name1 tmp-name3 nil nil nil
'preserve-permissions
)
2970 (should (file-acl tmp-name3
))
2971 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
2972 ;; Different permissions mean different ACLs.
2973 (set-file-modes tmp-name1
#o777
)
2974 (set-file-modes tmp-name3
#o444
)
2976 (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
2978 (set-file-acl tmp-name3
(file-acl tmp-name1
))
2979 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
2981 ;; Two files with same ACLs.
2982 (delete-file tmp-name1
)
2983 (copy-file tmp-name3 tmp-name1 nil nil nil
'preserve-permissions
)
2984 (should (file-acl tmp-name1
))
2985 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
2986 ;; Different permissions mean different ACLs.
2987 (set-file-modes tmp-name1
#o777
)
2988 (set-file-modes tmp-name3
#o444
)
2990 (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
2992 (set-file-acl tmp-name1
(file-acl tmp-name3
))
2993 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
))))
2996 (ignore-errors (delete-file tmp-name1
))
2997 (ignore-errors (delete-file tmp-name3
))))))
2999 (ert-deftest tramp-test25-file-selinux
()
3000 "Check `file-selinux-context' and `set-file-selinux-context'."
3001 (skip-unless (tramp--test-enabled))
3003 (not (equal (file-selinux-context tramp-test-temporary-file-directory
)
3004 '(nil nil nil nil
))))
3006 ;; TODO: The quoted case does not work. Copy local file to remote.
3007 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
3009 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3010 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
3011 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
3012 ;; Both files are remote.
3015 ;; Two files with same SELinux context.
3016 (write-region "foo" nil tmp-name1
)
3017 (should (file-exists-p tmp-name1
))
3018 (should (file-selinux-context tmp-name1
))
3019 (copy-file tmp-name1 tmp-name2
)
3020 (should (file-selinux-context tmp-name2
))
3023 (file-selinux-context tmp-name1
)
3024 (file-selinux-context tmp-name2
)))
3025 ;; Check different SELinux context. We cannot support
3026 ;; different ranges in this test; let's assume the most
3028 (let ((context (file-selinux-context tmp-name1
)))
3029 (when (and (string-equal (nth 3 context
) "s0")
3030 (setcar (nthcdr 3 context
) "s0:c0")
3031 (set-file-selinux-context tmp-name1 context
))
3034 (file-selinux-context tmp-name1
)
3035 (file-selinux-context tmp-name2
)))))
3036 ;; Copy SELinux context.
3038 (set-file-selinux-context
3039 tmp-name2
(file-selinux-context tmp-name1
)))
3042 (file-selinux-context tmp-name1
)
3043 (file-selinux-context tmp-name2
)))
3044 ;; An invalid SELinux context does not harm.
3045 (should-not (set-file-selinux-context tmp-name2
"foo")))
3048 (ignore-errors (delete-file tmp-name1
))
3049 (ignore-errors (delete-file tmp-name2
)))
3051 ;; Remote and local file.
3054 (or (equal (file-selinux-context temporary-file-directory
)
3056 (tramp--test-windows-nt-or-smb-p)))
3057 ;; Both users shall use the same SELinux context.
3059 (let ((default-directory temporary-file-directory
))
3060 (shell-command-to-string "id -Z"))
3061 (let ((default-directory
3062 tramp-test-temporary-file-directory
))
3063 (shell-command-to-string "id -Z"))))
3065 ;; Two files with same SELinux context.
3066 (write-region "foo" nil tmp-name1
)
3067 (should (file-exists-p tmp-name1
))
3068 (should (file-selinux-context tmp-name1
))
3069 (copy-file tmp-name1 tmp-name3
)
3070 (should (file-selinux-context tmp-name3
))
3071 ;; We cannot expect that copying over file system
3072 ;; boundaries keeps SELinux context. So we copy it
3075 (set-file-selinux-context
3076 tmp-name3
(file-selinux-context tmp-name1
)))
3079 (file-selinux-context tmp-name1
)
3080 (file-selinux-context tmp-name3
)))
3081 ;; Check different SELinux context. We cannot support
3082 ;; different ranges in this test; let's assume the most
3084 (let ((context (file-selinux-context tmp-name1
)))
3085 (when (and (string-equal (nth 3 context
) "s0")
3086 (setcar (nthcdr 3 context
) "s0:c0")
3087 (set-file-selinux-context tmp-name1 context
))
3090 (file-selinux-context tmp-name1
)
3091 (file-selinux-context tmp-name3
)))))
3092 ;; Copy SELinux context.
3094 (set-file-selinux-context
3095 tmp-name3
(file-selinux-context tmp-name1
)))
3098 (file-selinux-context tmp-name1
)
3099 (file-selinux-context tmp-name3
)))
3101 ;; Two files with same SELinux context.
3102 (delete-file tmp-name1
)
3103 (copy-file tmp-name3 tmp-name1
)
3104 (should (file-selinux-context tmp-name1
))
3105 ;; We cannot expect that copying over file system
3106 ;; boundaries keeps SELinux context. So we copy it
3109 (set-file-selinux-context
3110 tmp-name1
(file-selinux-context tmp-name3
)))
3113 (file-selinux-context tmp-name1
)
3114 (file-selinux-context tmp-name3
)))
3115 ;; Check different SELinux context. We cannot support
3116 ;; different ranges in this test; let's assume the most
3118 (let ((context (file-selinux-context tmp-name3
)))
3119 (when (and (string-equal (nth 3 context
) "s0")
3120 (setcar (nthcdr 3 context
) "s0:c0")
3121 (set-file-selinux-context tmp-name3 context
))
3124 (file-selinux-context tmp-name1
)
3125 (file-selinux-context tmp-name3
)))))
3126 ;; Copy SELinux context.
3128 (set-file-selinux-context
3129 tmp-name1
(file-selinux-context tmp-name3
)))
3132 (file-selinux-context tmp-name1
)
3133 (file-selinux-context tmp-name3
))))
3136 (ignore-errors (delete-file tmp-name1
))
3137 (ignore-errors (delete-file tmp-name3
))))))
3139 (ert-deftest tramp-test26-file-name-completion
()
3140 "Check `file-name-completion' and `file-name-all-completions'."
3141 (skip-unless (tramp--test-enabled))
3143 ;; Method and host name in completion mode. This kind of completion
3144 ;; does not work on MS Windows.
3145 (when (not (memq system-type
'(cygwin windows-nt
)))
3146 (let ((method (file-remote-p tramp-test-temporary-file-directory
'method
))
3147 (host (file-remote-p tramp-test-temporary-file-directory
'host
))
3148 (orig-syntax tramp-syntax
))
3149 (when (and (stringp host
) (string-match tramp-host-with-port-regexp host
))
3150 (setq host
(match-string 1 host
)))
3155 (if tramp--test-expensive-test
3156 (tramp-syntax-values) `(,orig-syntax
)))
3157 (tramp-change-syntax syntax
)
3158 (let ;; This is needed for the `simplified' syntax.
3160 (if (zerop (length tramp-method-regexp
))
3161 "" tramp-default-method-marker
))
3162 ;; This is needed for the `separate' syntax.
3163 (prefix-format (substring tramp-prefix-format
1)))
3164 ;; Complete method name.
3165 (unless (or (zerop (length method
))
3166 (zerop (length tramp-method-regexp
)))
3169 (concat prefix-format method tramp-postfix-method-format
)
3170 (file-name-all-completions
3171 (concat prefix-format
(substring method
0 1)) "/"))))
3172 ;; Complete host name for default method. With gvfs
3173 ;; based methods, host name will be determined as
3174 ;; host.local, so we omit the test.
3175 (let ((tramp-default-method (or method tramp-default-method
)))
3176 (unless (or (zerop (length host
))
3177 (tramp--test-gvfs-p tramp-default-method
))
3181 prefix-format method-marker tramp-postfix-method-format
3182 host tramp-postfix-host-format
)
3183 (file-name-all-completions
3185 prefix-format method-marker tramp-postfix-method-format
3186 (substring host
0 1))
3188 ;; Complete host name.
3189 (unless (or (zerop (length method
))
3190 (zerop (length tramp-method-regexp
))
3191 (zerop (length host
))
3192 (tramp--test-gvfs-p method
))
3196 prefix-format method tramp-postfix-method-format
3197 host tramp-postfix-host-format
)
3198 (file-name-all-completions
3199 (concat prefix-format method tramp-postfix-method-format
)
3203 (tramp-change-syntax orig-syntax
))))
3205 (dolist (n-e '(nil t
))
3206 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3207 (let ((non-essential n-e
)
3208 (tmp-name (tramp--test-make-temp-name nil quoted
)))
3213 (make-directory tmp-name
)
3214 (should (file-directory-p tmp-name
))
3215 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
3216 (should (file-exists-p (expand-file-name "foo" tmp-name
)))
3217 (write-region "bar" nil
(expand-file-name "bold" tmp-name
))
3218 (should (file-exists-p (expand-file-name "bold" tmp-name
)))
3219 (make-directory (expand-file-name "boz" tmp-name
))
3220 (should (file-directory-p (expand-file-name "boz" tmp-name
)))
3221 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
3222 (should (equal (file-name-completion "foo" tmp-name
) t
))
3223 (should (equal (file-name-completion "b" tmp-name
) "bo"))
3224 (should-not (file-name-completion "a" tmp-name
))
3227 (file-name-completion "b" tmp-name
'file-directory-p
) "boz/"))
3229 (equal (file-name-all-completions "fo" tmp-name
) '("foo")))
3232 (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
3234 (should-not (file-name-all-completions "a" tmp-name
))
3235 ;; `completion-regexp-list' restricts the completion to
3236 ;; files which match all expressions in this list.
3237 (let ((completion-regexp-list
3238 `(,directory-files-no-dot-files-regexp
"b")))
3240 (equal (file-name-completion "" tmp-name
) "bo"))
3243 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
3245 ;; `file-name-completion' ignores file names that end in
3246 ;; any string in `completion-ignored-extensions'.
3247 (let ((completion-ignored-extensions '(".ext")))
3248 (write-region "foo" nil
(expand-file-name "foo.ext" tmp-name
))
3249 (should (file-exists-p (expand-file-name "foo.ext" tmp-name
)))
3250 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
3251 (should (equal (file-name-completion "foo" tmp-name
) t
))
3253 (equal (file-name-completion "foo." tmp-name
) "foo.ext"))
3254 (should (equal (file-name-completion "foo.ext" tmp-name
) t
))
3255 ;; `file-name-all-completions' is not affected.
3258 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
3259 '("../" "./" "bold" "boz/" "foo" "foo.ext")))))
3262 (ignore-errors (delete-directory tmp-name
'recursive
)))))))
3264 (ert-deftest tramp-test27-load
()
3266 (skip-unless (tramp--test-enabled))
3268 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3269 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
3272 (load tmp-name
'noerror
'nomessage
)
3273 (should-not (featurep 'tramp-test-load
))
3274 (write-region "(provide 'tramp-test-load)" nil tmp-name
)
3275 ;; `load' in lread.c does not pass `must-suffix'. Why?
3277 ;; (load tmp-name nil 'nomessage 'nosuffix 'must-suffix)
3278 ;; :type 'file-error)
3279 (load tmp-name nil
'nomessage
'nosuffix
)
3280 (should (featurep 'tramp-test-load
)))
3284 (and (featurep 'tramp-test-load
) (unload-feature 'tramp-test-load
))
3285 (delete-file tmp-name
))))))
3287 (ert-deftest tramp-test28-process-file
()
3288 "Check `process-file'."
3289 :tags
'(:expensive-test
)
3290 (skip-unless (tramp--test-enabled))
3291 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
3293 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3294 (let* ((tmp-name (tramp--test-make-temp-name nil quoted
))
3295 (fnnd (file-name-nondirectory tmp-name
))
3296 (default-directory tramp-test-temporary-file-directory
)
3297 kill-buffer-query-functions
)
3300 ;; We cannot use "/bin/true" and "/bin/false"; those paths
3301 ;; do not exist on hydra.
3302 (should (zerop (process-file "true")))
3303 (should-not (zerop (process-file "false")))
3304 (should-not (zerop (process-file "binary-does-not-exist")))
3306 (write-region "foo" nil tmp-name
)
3307 (should (file-exists-p tmp-name
))
3308 (should (zerop (process-file "ls" nil t nil fnnd
)))
3309 ;; `ls' could produce colorized output.
3310 (goto-char (point-min))
3312 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3313 (replace-match "" nil nil
))
3314 (should (string-equal (format "%s\n" fnnd
) (buffer-string)))
3315 (should-not (get-buffer-window (current-buffer) t
))
3317 ;; Second run. The output must be appended.
3318 (goto-char (point-max))
3319 (should (zerop (process-file "ls" nil t t fnnd
)))
3320 ;; `ls' could produce colorized output.
3321 (goto-char (point-min))
3323 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3324 (replace-match "" nil nil
))
3326 (string-equal (format "%s\n%s\n" fnnd fnnd
) (buffer-string)))
3327 ;; A non-nil DISPLAY must not raise the buffer.
3328 (should-not (get-buffer-window (current-buffer) t
))))
3331 (ignore-errors (delete-file tmp-name
))))))
3333 (ert-deftest tramp-test29-start-file-process
()
3334 "Check `start-file-process'."
3335 :tags
'(:expensive-test
)
3336 (skip-unless (tramp--test-enabled))
3337 (skip-unless (tramp--test-sh-p))
3339 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3340 (let ((default-directory tramp-test-temporary-file-directory
)
3341 (tmp-name (tramp--test-make-temp-name nil quoted
))
3342 kill-buffer-query-functions proc
)
3345 (setq proc
(start-file-process "test1" (current-buffer) "cat"))
3346 (should (processp proc
))
3347 (should (equal (process-status proc
) 'run
))
3348 (process-send-string proc
"foo")
3349 (process-send-eof proc
)
3351 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3352 (while (< (- (point-max) (point-min)) (length "foo"))
3353 (accept-process-output proc
0.1)))
3354 (should (string-equal (buffer-string) "foo")))
3357 (ignore-errors (delete-process proc
)))
3361 (write-region "foo" nil tmp-name
)
3362 (should (file-exists-p tmp-name
))
3365 "test2" (current-buffer)
3366 "cat" (file-name-nondirectory tmp-name
)))
3367 (should (processp proc
))
3369 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3370 (while (< (- (point-max) (point-min)) (length "foo"))
3371 (accept-process-output proc
0.1)))
3372 (should (string-equal (buffer-string) "foo")))
3376 (delete-process proc
)
3377 (delete-file tmp-name
)))
3381 (setq proc
(start-file-process "test3" (current-buffer) "cat"))
3382 (should (processp proc
))
3383 (should (equal (process-status proc
) 'run
))
3386 (lambda (p s
) (with-current-buffer (process-buffer p
) (insert s
))))
3387 (process-send-string proc
"foo")
3388 (process-send-eof proc
)
3390 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3391 (while (< (- (point-max) (point-min)) (length "foo"))
3392 (accept-process-output proc
0.1)))
3393 (should (string-equal (buffer-string) "foo")))
3396 (ignore-errors (delete-process proc
))))))
3398 (ert-deftest tramp-test30-interrupt-process
()
3399 "Check `interrupt-process'."
3400 :tags
'(:expensive-test
)
3401 (skip-unless (tramp--test-enabled))
3402 (skip-unless (tramp--test-sh-p))
3403 ;; Since Emacs 26.1.
3404 (skip-unless (boundp 'interrupt-process-functions
))
3406 (let ((default-directory tramp-test-temporary-file-directory
)
3407 kill-buffer-query-functions proc
)
3410 (setq proc
(start-file-process "test" (current-buffer) "sleep" "10"))
3411 (should (processp proc
))
3412 (should (process-live-p proc
))
3413 (should (equal (process-status proc
) 'run
))
3414 (should (numberp (process-get proc
'remote-pid
)))
3415 (should (interrupt-process proc
))
3416 ;; Let the process accept the interrupt.
3417 (accept-process-output proc
1 nil
0)
3418 (should-not (process-live-p proc
))
3419 ;; An interrupted process cannot be interrupted, again.
3420 (should-error (interrupt-process proc
) :type
'error
))
3423 (ignore-errors (delete-process proc
)))))
3425 (ert-deftest tramp-test31-shell-command
()
3426 "Check `shell-command'."
3427 :tags
'(:expensive-test
)
3428 (skip-unless (tramp--test-enabled))
3429 (skip-unless (tramp--test-sh-p))
3431 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3432 (let ((tmp-name (tramp--test-make-temp-name nil quoted
))
3433 (default-directory tramp-test-temporary-file-directory
)
3434 ;; Suppress nasty messages.
3436 kill-buffer-query-functions
)
3439 (write-region "foo" nil tmp-name
)
3440 (should (file-exists-p tmp-name
))
3442 (format "ls %s" (file-name-nondirectory tmp-name
))
3444 ;; `ls' could produce colorized output.
3445 (goto-char (point-min))
3447 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3448 (replace-match "" nil nil
))
3451 (format "%s\n" (file-name-nondirectory tmp-name
))
3455 (ignore-errors (delete-file tmp-name
)))
3459 (write-region "foo" nil tmp-name
)
3460 (should (file-exists-p tmp-name
))
3461 (async-shell-command
3462 (format "ls %s" (file-name-nondirectory tmp-name
))
3465 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
3466 (while (< (- (point-max) (point-min))
3467 (1+ (length (file-name-nondirectory tmp-name
))))
3468 (accept-process-output
3469 (get-buffer-process (current-buffer)) 0.1)))
3470 ;; `ls' could produce colorized output.
3471 (goto-char (point-min))
3473 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3474 (replace-match "" nil nil
))
3475 ;; There might be a nasty "Process *Async Shell* finished" message.
3476 (goto-char (point-min))
3478 (narrow-to-region (point-min) (point))
3481 (format "%s\n" (file-name-nondirectory tmp-name
))
3485 (ignore-errors (delete-file tmp-name
)))
3489 (write-region "foo" nil tmp-name
)
3490 (should (file-exists-p tmp-name
))
3491 (async-shell-command "read line; ls $line" (current-buffer))
3492 (process-send-string
3493 (get-buffer-process (current-buffer))
3494 (format "%s\n" (file-name-nondirectory tmp-name
)))
3496 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
3497 (while (< (- (point-max) (point-min))
3498 (1+ (length (file-name-nondirectory tmp-name
))))
3499 (accept-process-output
3500 (get-buffer-process (current-buffer)) 0.1)))
3501 ;; `ls' could produce colorized output.
3502 (goto-char (point-min))
3504 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3505 (replace-match "" nil nil
))
3506 ;; There might be a nasty "Process *Async Shell* finished" message.
3507 (goto-char (point-min))
3509 (narrow-to-region (point-min) (point))
3512 (format "%s\n" (file-name-nondirectory tmp-name
))
3516 (ignore-errors (delete-file tmp-name
))))))
3518 (defun tramp--test-shell-command-to-string-asynchronously (command)
3519 "Like `shell-command-to-string', but for asynchronous processes."
3521 (async-shell-command command
(current-buffer))
3523 (while (get-buffer-process (current-buffer))
3524 (accept-process-output (get-buffer-process (current-buffer)) 0.1)))
3525 (accept-process-output nil
0.1)
3526 (buffer-substring-no-properties (point-min) (point-max))))
3528 ;; This test is inspired by Bug#23952.
3529 (ert-deftest tramp-test32-environment-variables
()
3530 "Check that remote processes set / unset environment variables properly."
3531 :tags
'(:expensive-test
)
3532 (skip-unless (tramp--test-enabled))
3533 (skip-unless (tramp--test-sh-p))
3535 (dolist (this-shell-command-to-string
3537 shell-command-to-string
3539 tramp--test-shell-command-to-string-asynchronously
))
3541 (let ((default-directory tramp-test-temporary-file-directory
)
3542 (shell-file-name "/bin/sh")
3543 (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
3544 kill-buffer-query-functions
)
3548 (let ((process-environment
3549 (cons (concat envvar
"=foo") process-environment
)))
3555 this-shell-command-to-string
3556 (format "echo -n ${%s:?bla}" envvar
))))))
3559 ;; Set the empty value.
3560 (let ((process-environment
3561 (cons (concat envvar
"=") process-environment
)))
3567 this-shell-command-to-string
3568 (format "echo -n ${%s:?bla}" envvar
))))
3572 (regexp-quote envvar
)
3573 (funcall this-shell-command-to-string
"set")))))
3575 ;; We force a reconnect, in order to have a clean environment.
3576 (tramp-cleanup-connection
3577 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
3578 'keep-debug
'keep-password
)
3580 ;; Unset the variable.
3581 (let ((tramp-remote-process-environment
3582 (cons (concat envvar
"=foo")
3583 tramp-remote-process-environment
)))
3584 ;; Set the initial value, we want to unset below.
3589 this-shell-command-to-string
3590 (format "echo -n ${%s:?bla}" envvar
))))
3591 (let ((process-environment
3592 (cons envvar process-environment
)))
3593 ;; Variable is unset.
3598 this-shell-command-to-string
3599 (format "echo -n ${%s:?bla}" envvar
))))
3600 ;; Variable is unset.
3603 (regexp-quote envvar
)
3604 (funcall this-shell-command-to-string
"set")))))))))
3606 ;; This test is inspired by Bug#27009.
3607 (ert-deftest tramp-test32-environment-variables-and-port-numbers
()
3608 "Check that two connections with separate ports are different."
3609 (skip-unless (tramp--test-enabled))
3610 ;; We test it only for the mock-up connection; otherwise there might
3611 ;; be problems with the used ports.
3614 (eq tramp-syntax
'default
)
3616 "mock" (file-remote-p tramp-test-temporary-file-directory
'method
))))
3618 ;; We force a reconnect, in order to have a clean environment.
3619 (dolist (dir `(,tramp-test-temporary-file-directory
3620 "/mock:localhost#11111:" "/mock:localhost#22222:"))
3621 (tramp-cleanup-connection
3622 (tramp-dissect-file-name dir
) 'keep-debug
'keep-password
))
3625 (dolist (port '(11111 22222))
3626 (let* ((default-directory
3627 (format "/mock:localhost#%d:%s" port temporary-file-directory
))
3628 (shell-file-name "/bin/sh")
3629 (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
3630 ;; We cannot use `process-environment', because this
3631 ;; would be applied in `process-file'.
3632 (tramp-remote-process-environment
3634 (format "%s=%d" envvar port
)
3635 tramp-remote-process-environment
)))
3638 (number-to-string port
)
3639 (shell-command-to-string (format "echo -n $%s" envvar
))))))
3642 (dolist (dir '("/mock:localhost#11111:" "/mock:localhost#22222:"))
3643 (tramp-cleanup-connection (tramp-dissect-file-name dir
)))))
3645 ;; The functions were introduced in Emacs 26.1.
3646 (ert-deftest tramp-test33-explicit-shell-file-name
()
3647 "Check that connection-local `explicit-shell-file-name' is set."
3648 :tags
'(:expensive-test
)
3649 (skip-unless (tramp--test-enabled))
3650 (skip-unless (tramp--test-sh-p))
3651 ;; Since Emacs 26.1.
3652 (skip-unless (and (fboundp 'connection-local-set-profile-variables
)
3653 (fboundp 'connection-local-set-profiles
)))
3655 ;; `connection-local-set-profile-variables' and
3656 ;; `connection-local-set-profiles' exist since Emacs 26.1. We don't
3657 ;; want to see compiler warnings for older Emacsen.
3658 (let ((default-directory tramp-test-temporary-file-directory
)
3659 explicit-shell-file-name kill-buffer-query-functions
)
3662 ;; `shell-mode' would ruin our test, because it deletes all
3663 ;; buffer local variables.
3664 (put 'explicit-shell-file-name
'permanent-local t
)
3665 ;; Declare connection-local variable `explicit-shell-file-name'.
3667 (connection-local-set-profile-variables
3669 '((explicit-shell-file-name .
"/bin/sh")
3670 (explicit-sh-args .
("-i"))))
3671 (connection-local-set-profiles
3672 `(:application tramp
3673 :protocol
,(file-remote-p default-directory
'method
)
3674 :user
,(file-remote-p default-directory
'user
)
3675 :machine
,(file-remote-p default-directory
'host
))
3678 ;; Run interactive shell. Since the default directory is
3679 ;; remote, `explicit-shell-file-name' shall be set in order
3680 ;; to avoid a question.
3681 (with-current-buffer (get-buffer-create "*shell*")
3682 (ignore-errors (kill-process (current-buffer)))
3683 (should-not explicit-shell-file-name
)
3684 (call-interactively 'shell
)
3685 (should explicit-shell-file-name
)))
3687 (put 'explicit-shell-file-name
'permanent-local nil
)
3688 (kill-buffer "*shell*"))))
3690 (ert-deftest tramp-test34-vc-registered
()
3691 "Check `vc-registered'."
3692 :tags
'(:expensive-test
)
3693 (skip-unless (tramp--test-enabled))
3694 (skip-unless (tramp--test-sh-p))
3696 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3697 (let* ((default-directory tramp-test-temporary-file-directory
)
3698 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
3699 (tmp-name2 (expand-file-name "foo" tmp-name1
))
3700 (tramp-remote-process-environment tramp-remote-process-environment
)
3701 (vc-handled-backends
3702 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3704 ((tramp-find-executable
3705 v vc-git-program
(tramp-get-remote-path v
))
3707 ((tramp-find-executable
3708 v vc-hg-program
(tramp-get-remote-path v
))
3710 ((tramp-find-executable
3711 v vc-bzr-program
(tramp-get-remote-path v
))
3712 (setq tramp-remote-process-environment
3713 (cons (format "BZR_HOME=%s"
3714 (file-remote-p tmp-name1
'localname
))
3715 tramp-remote-process-environment
))
3716 ;; We must force a reconnect, in order to activate $BZR_HOME.
3717 (tramp-cleanup-connection
3718 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
3719 'keep-debug
'keep-password
)
3722 ;; Suppress nasty messages.
3723 (inhibit-message t
))
3724 (skip-unless vc-handled-backends
)
3725 (unless quoted
(tramp--test-message "%s" vc-handled-backends
))
3729 (make-directory tmp-name1
)
3730 (write-region "foo" nil tmp-name2
)
3731 (should (file-directory-p tmp-name1
))
3732 (should (file-exists-p tmp-name2
))
3733 (should-not (vc-registered tmp-name1
))
3734 (should-not (vc-registered tmp-name2
))
3736 (let ((default-directory tmp-name1
))
3737 ;; Create empty repository, and register the file.
3738 ;; Sometimes, creation of repository fails (bzr!); we
3739 ;; skip the test then.
3741 (vc-create-repo (car vc-handled-backends
))
3742 (error (skip-unless nil
)))
3743 ;; The structure of VC-FILESET is not documented. Let's
3744 ;; hope it won't change.
3747 (list (car vc-handled-backends
)
3748 (list (file-name-nondirectory tmp-name2
))))
3749 ;; `vc-register' has changed its arguments in Emacs 25.1.
3752 nil
(list (car vc-handled-backends
)
3753 (list (file-name-nondirectory tmp-name2
))))))
3754 ;; vc-git uses an own process sentinel, Tramp's sentinel
3755 ;; for flushing the cache isn't used.
3756 (dired-uncache (concat (file-remote-p default-directory
) "/"))
3757 (should (vc-registered (file-name-nondirectory tmp-name2
)))))
3760 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
3762 (ert-deftest tramp-test35-make-auto-save-file-name
()
3763 "Check `make-auto-save-file-name'."
3764 (skip-unless (tramp--test-enabled))
3766 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3767 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3768 (tmp-name2 (tramp--test-make-temp-name nil quoted
)))
3772 ;; Use default `auto-save-file-name-transforms' mechanism.
3773 (let (tramp-auto-save-directory)
3775 (setq buffer-file-name tmp-name1
)
3778 (make-auto-save-file-name)
3779 ;; This is taken from original `make-auto-save-file-name'.
3780 ;; We call `convert-standard-filename', because on
3781 ;; MS Windows the (local) colons must be replaced by
3782 ;; exclamation marks.
3783 (convert-standard-filename
3787 (subst-char-in-string
3788 ?
/ ?
! (replace-regexp-in-string "!" "!!" tmp-name1
)))
3789 temporary-file-directory
))))))
3792 (let (tramp-auto-save-directory auto-save-file-name-transforms
)
3794 (setq buffer-file-name tmp-name1
)
3797 (make-auto-save-file-name)
3799 (if quoted
'tramp-compat-file-name-quote
'identity
)
3801 (format "#%s#" (file-name-nondirectory tmp-name1
))
3802 tramp-test-temporary-file-directory
))))))
3804 ;; TODO: The following two cases don't work yet.
3806 ;; Use default `tramp-auto-save-directory' mechanism.
3807 (let ((tramp-auto-save-directory tmp-name2
))
3809 (setq buffer-file-name tmp-name1
)
3812 (make-auto-save-file-name)
3813 ;; This is taken from Tramp.
3817 (tramp-subst-strs-in-string
3824 (tramp-compat-file-name-unquote tmp-name1
)))
3826 (should (file-directory-p tmp-name2
))))
3828 ;; Relative file names shall work, too.
3829 (let ((tramp-auto-save-directory "."))
3831 (setq buffer-file-name tmp-name1
3832 default-directory tmp-name2
)
3835 (make-auto-save-file-name)
3836 ;; This is taken from Tramp.
3840 (tramp-subst-strs-in-string
3847 (tramp-compat-file-name-unquote tmp-name1
)))
3849 (should (file-directory-p tmp-name2
)))))
3853 (ignore-errors (delete-file tmp-name1
))
3854 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
3856 (ert-deftest tramp-test36-find-backup-file-name
()
3857 "Check `find-backup-file-name'."
3858 (skip-unless (tramp--test-enabled))
3860 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3861 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3862 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
3863 ;; These settings are not used by Tramp, so we ignore them.
3864 version-control delete-old-versions
3865 (kept-old-versions (default-toplevel-value 'kept-old-versions
))
3866 (kept-new-versions (default-toplevel-value 'kept-new-versions
)))
3869 ;; Use default `backup-directory-alist' mechanism.
3870 (let (backup-directory-alist tramp-backup-directory-alist
)
3873 (find-backup-file-name tmp-name1
)
3876 (if quoted
'tramp-compat-file-name-quote
'identity
)
3878 (format "%s~" (file-name-nondirectory tmp-name1
))
3879 tramp-test-temporary-file-directory
)))))))
3882 ;; Map `backup-directory-alist'.
3883 (let ((backup-directory-alist `(("." .
,tmp-name2
)))
3884 tramp-backup-directory-alist
)
3887 (find-backup-file-name tmp-name1
)
3890 (if quoted
'tramp-compat-file-name-quote
'identity
)
3894 ;; This is taken from `make-backup-file-name-1'.
3895 (subst-char-in-string
3896 ?
/ ?
! (replace-regexp-in-string "!" "!!" tmp-name1
)))
3898 ;; The backup directory is created.
3899 (should (file-directory-p tmp-name2
)))
3902 (ignore-errors (delete-directory tmp-name2
'recursive
)))
3905 ;; Map `tramp-backup-directory-alist'.
3906 (let ((tramp-backup-directory-alist `(("." .
,tmp-name2
)))
3907 backup-directory-alist
)
3910 (find-backup-file-name tmp-name1
)
3913 (if quoted
'tramp-compat-file-name-quote
'identity
)
3917 ;; This is taken from `make-backup-file-name-1'.
3918 (subst-char-in-string
3919 ?
/ ?
! (replace-regexp-in-string "!" "!!" tmp-name1
)))
3921 ;; The backup directory is created.
3922 (should (file-directory-p tmp-name2
)))
3925 (ignore-errors (delete-directory tmp-name2
'recursive
)))
3928 ;; Map `tramp-backup-directory-alist' with local file name.
3929 (let ((tramp-backup-directory-alist
3930 `(("." .
,(file-remote-p tmp-name2
'localname
))))
3931 backup-directory-alist
)
3934 (find-backup-file-name tmp-name1
)
3937 (if quoted
'tramp-compat-file-name-quote
'identity
)
3941 ;; This is taken from `make-backup-file-name-1'.
3942 (subst-char-in-string
3943 ?
/ ?
! (replace-regexp-in-string "!" "!!" tmp-name1
)))
3945 ;; The backup directory is created.
3946 (should (file-directory-p tmp-name2
)))
3949 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
3951 ;; The functions were introduced in Emacs 26.1.
3952 (ert-deftest tramp-test37-make-nearby-temp-file
()
3953 "Check `make-nearby-temp-file' and `temporary-file-directory'."
3954 (skip-unless (tramp--test-enabled))
3955 ;; Since Emacs 26.1.
3957 (and (fboundp 'make-nearby-temp-file
) (fboundp 'temporary-file-directory
)))
3959 ;; `make-nearby-temp-file' and `temporary-file-directory' exists
3960 ;; since Emacs 26.1. We don't want to see compiler warnings for
3962 (let ((default-directory tramp-test-temporary-file-directory
)
3964 ;; The remote host shall know a temporary file directory.
3965 (should (stringp (with-no-warnings (temporary-file-directory))))
3968 (file-remote-p default-directory
)
3969 (file-remote-p (with-no-warnings (temporary-file-directory)))))
3971 ;; The temporary file shall be located on the remote host.
3972 (setq tmp-file
(with-no-warnings (make-nearby-temp-file "tramp-test")))
3973 (should (file-exists-p tmp-file
))
3974 (should (file-regular-p tmp-file
))
3977 (file-remote-p default-directory
)
3978 (file-remote-p tmp-file
)))
3979 (delete-file tmp-file
)
3980 (should-not (file-exists-p tmp-file
))
3982 (setq tmp-file
(with-no-warnings (make-nearby-temp-file "tramp-test" 'dir
)))
3983 (should (file-exists-p tmp-file
))
3984 (should (file-directory-p tmp-file
))
3985 (delete-directory tmp-file
)
3986 (should-not (file-exists-p tmp-file
))))
3988 (defun tramp--test-emacs26-p ()
3989 "Check for Emacs version >= 26.1.
3990 Some semantics has been changed for there, w/o new functions or
3991 variables, so we check the Emacs version directly."
3992 (>= emacs-major-version
26))
3994 (defun tramp--test-adb-p ()
3995 "Check, whether the remote host runs Android.
3996 This requires restrictions of file name syntax."
3997 (tramp-adb-file-name-p tramp-test-temporary-file-directory
))
3999 (defun tramp--test-docker-p ()
4000 "Check, whether the docker method is used.
4001 This does not support some special file names."
4003 "docker" (file-remote-p tramp-test-temporary-file-directory
'method
)))
4005 (defun tramp--test-ftp-p ()
4006 "Check, whether an FTP-like method is used.
4007 This does not support globbing characters in file names (yet)."
4008 ;; Globbing characters are ??, ?* and ?\[.
4010 "ftp$" (file-remote-p tramp-test-temporary-file-directory
'method
)))
4012 (defun tramp--test-gvfs-p (&optional method
)
4013 "Check, whether the remote host runs a GVFS based method.
4014 This requires restrictions of file name syntax."
4015 (or (member method tramp-gvfs-methods
)
4016 (tramp-gvfs-file-name-p tramp-test-temporary-file-directory
)))
4018 (defun tramp--test-hpux-p ()
4019 "Check, whether the remote host runs HP-UX.
4020 Several special characters do not work properly there."
4021 ;; We must refill the cache. `file-truename' does it.
4022 (with-parsed-tramp-file-name
4023 (file-truename tramp-test-temporary-file-directory
) nil
4024 (string-match "^HP-UX" (tramp-get-connection-property v
"uname" ""))))
4026 (defun tramp--test-rsync-p ()
4027 "Check, whether the rsync method is used.
4028 This does not support special file names."
4030 "rsync" (file-remote-p tramp-test-temporary-file-directory
'method
)))
4032 (defun tramp--test-sh-p ()
4033 "Check, whether the remote host runs a based method from tramp-sh.el."
4035 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
4036 'tramp-sh-file-name-handler
))
4038 (defun tramp--test-windows-nt-and-batch ()
4039 "Check, whether the locale host runs MS Windows in batch mode.
4040 This does not support special characters."
4041 (and (eq system-type
'windows-nt
) noninteractive
))
4043 (defun tramp--test-windows-nt-and-pscp-psftp-p ()
4044 "Check, whether the locale host runs MS Windows, and ps{cp,ftp} is used.
4045 This does not support utf8 based file transfer."
4046 (and (eq system-type
'windows-nt
)
4048 (regexp-opt '("pscp" "psftp"))
4049 (file-remote-p tramp-test-temporary-file-directory
'method
))))
4051 (defun tramp--test-windows-nt-or-smb-p ()
4052 "Check, whether the locale or remote host runs MS Windows.
4053 This requires restrictions of file name syntax."
4054 (or (eq system-type
'windows-nt
)
4055 (tramp-smb-file-name-p tramp-test-temporary-file-directory
)))
4057 (defun tramp--test-check-files (&rest files
)
4058 "Run a simple but comprehensive test over every file in FILES."
4059 ;; TODO: The quoted case does not work.
4060 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
4062 ;; We must use `file-truename' for the temporary directory,
4063 ;; because it could be located on a symlinked directory. This
4064 ;; would let the test fail.
4065 (let* ((tramp-test-temporary-file-directory
4066 (file-truename tramp-test-temporary-file-directory
))
4067 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
4068 (tmp-name2 (tramp--test-make-temp-name 'local quoted
))
4069 (files (delq nil files
))
4070 (process-environment process-environment
))
4073 (make-directory tmp-name1
)
4074 (make-directory tmp-name2
)
4077 (let* ((file1 (expand-file-name elt tmp-name1
))
4078 (file2 (expand-file-name elt tmp-name2
))
4079 (file3 (expand-file-name (concat elt
"foo") tmp-name1
)))
4080 (write-region elt nil file1
)
4081 (should (file-exists-p file1
))
4083 ;; Check file contents.
4085 (insert-file-contents file1
)
4086 (should (string-equal (buffer-string) elt
)))
4088 ;; Copy file both directions.
4089 (copy-file file1
(file-name-as-directory tmp-name2
))
4090 (should (file-exists-p file2
))
4092 (should-not (file-exists-p file1
))
4093 (copy-file file2
(file-name-as-directory tmp-name1
))
4094 (should (file-exists-p file1
))
4096 (tramp--test-ignore-make-symbolic-link-error
4097 (make-symbolic-link file1 file3
)
4098 (should (file-symlink-p file3
))
4101 (expand-file-name file1
) (file-truename file3
)))
4105 (if quoted
'tramp-compat-file-name-quote
'identity
)
4106 (car (file-attributes file3
)))
4107 (file-remote-p (file-truename file1
) 'localname
)))
4108 ;; Check file contents.
4110 (insert-file-contents file3
)
4111 (should (string-equal (buffer-string) elt
)))
4112 (delete-file file3
))))
4114 ;; Check file names.
4115 (should (equal (directory-files
4116 tmp-name1 nil directory-files-no-dot-files-regexp
)
4117 (sort (copy-sequence files
) 'string-lessp
)))
4118 (should (equal (directory-files
4119 tmp-name2 nil directory-files-no-dot-files-regexp
)
4120 (sort (copy-sequence files
) 'string-lessp
)))
4122 ;; `substitute-in-file-name' could return different
4123 ;; values. For `adb', there could be strange file
4124 ;; permissions preventing overwriting a file. We don't
4125 ;; care in this testcase.
4128 (substitute-in-file-name (expand-file-name elt tmp-name1
)))
4130 (substitute-in-file-name
4131 (expand-file-name elt tmp-name2
))))
4132 (ignore-errors (write-region elt nil file1
))
4133 (should (file-exists-p file1
))
4134 (ignore-errors (write-region elt nil file2 nil
'nomessage
))
4135 (should (file-exists-p file2
))))
4137 (should (equal (directory-files
4138 tmp-name1 nil directory-files-no-dot-files-regexp
)
4140 tmp-name2 nil directory-files-no-dot-files-regexp
)))
4142 ;; Check directory creation. We use a subdirectory "foo"
4143 ;; in order to avoid conflicts with previous file name tests.
4145 (let* ((elt1 (concat elt
"foo"))
4146 (file1 (expand-file-name (concat "foo/" elt
) tmp-name1
))
4147 (file2 (expand-file-name elt file1
))
4148 (file3 (expand-file-name elt1 file1
)))
4149 (make-directory file1
'parents
)
4150 (should (file-directory-p file1
))
4151 (write-region elt nil file2
)
4152 (should (file-exists-p file2
))
4156 file1 nil directory-files-no-dot-files-regexp
)
4160 (caar (directory-files-and-attributes
4161 file1 nil directory-files-no-dot-files-regexp
))
4164 ;; Check symlink in `directory-files-and-attributes'.
4165 ;; It does not work in the "smb" case, only relative
4166 ;; symlinks to existing files are shown there.
4167 (tramp--test-ignore-make-symbolic-link-error
4169 (tramp-smb-file-name-p tramp-test-temporary-file-directory
)
4170 (make-symbolic-link file2 file3
)
4171 (should (file-symlink-p file3
))
4174 (caar (directory-files-and-attributes
4175 file1 nil
(regexp-quote elt1
)))
4180 (if quoted
'tramp-compat-file-name-quote
'identity
)
4181 (cadr (car (directory-files-and-attributes
4182 file1 nil
(regexp-quote elt1
)))))
4183 (file-remote-p (file-truename file2
) 'localname
)))
4185 (should-not (file-exists-p file3
))))
4188 (should-not (file-exists-p file2
))
4189 (delete-directory file1
)
4190 (should-not (file-exists-p file1
))))
4192 ;; Check, that environment variables are set correctly.
4193 (when (and tramp--test-expensive-test
(tramp--test-sh-p))
4195 (let ((envvar (concat "VAR_" (upcase (md5 elt
))))
4196 (default-directory tramp-test-temporary-file-directory
)
4197 (process-environment process-environment
))
4199 ;; The value of PS1 could confuse Tramp's detection
4200 ;; of process output. So we unset it temporarily.
4203 (should (zerop (process-file "env" nil t nil
)))
4204 (goto-char (point-min))
4209 (regexp-quote envvar
)
4210 (regexp-quote (getenv envvar
))))))))))
4213 (ignore-errors (delete-directory tmp-name1
'recursive
))
4214 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
4216 (defun tramp--test-special-characters ()
4217 "Perform the test in `tramp-test38-special-characters*'."
4218 ;; Newlines, slashes and backslashes in file names are not
4219 ;; supported. So we don't test. And we don't test the tab
4220 ;; character on Windows or Cygwin, because the backslash is
4221 ;; interpreted as a path separator, preventing "\t" from being
4222 ;; expanded to <TAB>.
4223 (tramp--test-check-files
4224 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4226 (if (or (tramp--test-adb-p)
4227 (tramp--test-docker-p)
4228 (eq system-type
'cygwin
))
4235 (unless (or (tramp--test-ftp-p)
4236 (tramp--test-gvfs-p)
4237 (tramp--test-windows-nt-or-smb-p))
4239 (unless (or (tramp--test-ftp-p)
4240 (tramp--test-gvfs-p)
4241 (tramp--test-windows-nt-or-smb-p))
4243 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4247 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4250 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4253 (unless (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4256 (unless (or (tramp--test-ftp-p) (tramp--test-gvfs-p)) "[foo]bar[baz]")
4259 ;; These tests are inspired by Bug#17238.
4260 (ert-deftest tramp-test38-special-characters
()
4261 "Check special characters in file names."
4262 (skip-unless (tramp--test-enabled))
4263 (skip-unless (not (tramp--test-rsync-p)))
4264 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4266 (tramp--test-special-characters))
4268 (ert-deftest tramp-test38-special-characters-with-stat
()
4269 "Check special characters in file names.
4270 Use the `stat' command."
4271 :tags
'(:expensive-test
)
4272 (skip-unless (tramp--test-enabled))
4273 (skip-unless (tramp--test-sh-p))
4274 (skip-unless (not (tramp--test-rsync-p)))
4275 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4276 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4277 (skip-unless (tramp-get-remote-stat v
)))
4279 (let ((tramp-connection-properties
4281 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4283 tramp-connection-properties
)))
4284 (tramp--test-special-characters)))
4286 (ert-deftest tramp-test38-special-characters-with-perl
()
4287 "Check special characters in file names.
4288 Use the `perl' command."
4289 :tags
'(:expensive-test
)
4290 (skip-unless (tramp--test-enabled))
4291 (skip-unless (tramp--test-sh-p))
4292 (skip-unless (not (tramp--test-rsync-p)))
4293 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4294 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4295 (skip-unless (tramp-get-remote-perl v
)))
4297 (let ((tramp-connection-properties
4299 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4301 ;; See `tramp-sh-handle-file-truename'.
4302 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4304 tramp-connection-properties
)))
4305 (tramp--test-special-characters)))
4307 (ert-deftest tramp-test38-special-characters-with-ls
()
4308 "Check special characters in file names.
4309 Use the `ls' command."
4310 :tags
'(:expensive-test
)
4311 (skip-unless (tramp--test-enabled))
4312 (skip-unless (tramp--test-sh-p))
4313 (skip-unless (not (tramp--test-rsync-p)))
4314 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4315 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4317 (let ((tramp-connection-properties
4319 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4321 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4323 ;; See `tramp-sh-handle-file-truename'.
4324 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4326 tramp-connection-properties
)))
4327 (tramp--test-special-characters)))
4329 (defun tramp--test-utf8 ()
4330 "Perform the test in `tramp-test39-utf8*'."
4331 (let* ((utf8 (if (and (eq system-type
'darwin
)
4332 (memq 'utf-8-hfs
(coding-system-list)))
4334 (coding-system-for-read utf8
)
4335 (coding-system-for-write utf8
)
4336 (file-name-coding-system
4337 (coding-system-change-eol-conversion utf8
'unix
)))
4338 (tramp--test-check-files
4339 (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ")
4340 (unless (tramp--test-hpux-p)
4341 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
4343 "Автостопом по гала́ктике")))
4345 (ert-deftest tramp-test39-utf8
()
4346 "Check UTF8 encoding in file names and file contents."
4347 (skip-unless (tramp--test-enabled))
4348 (skip-unless (not (tramp--test-docker-p)))
4349 (skip-unless (not (tramp--test-rsync-p)))
4350 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4351 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4355 (ert-deftest tramp-test39-utf8-with-stat
()
4356 "Check UTF8 encoding in file names and file contents.
4357 Use the `stat' command."
4358 :tags
'(:expensive-test
)
4359 (skip-unless (tramp--test-enabled))
4360 (skip-unless (tramp--test-sh-p))
4361 (skip-unless (not (tramp--test-docker-p)))
4362 (skip-unless (not (tramp--test-rsync-p)))
4363 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4364 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4365 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4366 (skip-unless (tramp-get-remote-stat v
)))
4368 (let ((tramp-connection-properties
4370 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4372 tramp-connection-properties
)))
4373 (tramp--test-utf8)))
4375 (ert-deftest tramp-test39-utf8-with-perl
()
4376 "Check UTF8 encoding in file names and file contents.
4377 Use the `perl' command."
4378 :tags
'(:expensive-test
)
4379 (skip-unless (tramp--test-enabled))
4380 (skip-unless (tramp--test-sh-p))
4381 (skip-unless (not (tramp--test-docker-p)))
4382 (skip-unless (not (tramp--test-rsync-p)))
4383 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4384 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4385 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4386 (skip-unless (tramp-get-remote-perl v
)))
4388 (let ((tramp-connection-properties
4390 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4392 ;; See `tramp-sh-handle-file-truename'.
4393 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4395 tramp-connection-properties
)))
4396 (tramp--test-utf8)))
4398 (ert-deftest tramp-test39-utf8-with-ls
()
4399 "Check UTF8 encoding in file names and file contents.
4400 Use the `ls' command."
4401 :tags
'(:expensive-test
)
4402 (skip-unless (tramp--test-enabled))
4403 (skip-unless (tramp--test-sh-p))
4404 (skip-unless (not (tramp--test-docker-p)))
4405 (skip-unless (not (tramp--test-rsync-p)))
4406 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4407 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4409 (let ((tramp-connection-properties
4411 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4413 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4415 ;; See `tramp-sh-handle-file-truename'.
4416 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4418 tramp-connection-properties
)))
4419 (tramp--test-utf8)))
4421 (ert-deftest tramp-test40-file-system-info
()
4422 "Check that `file-system-info' returns proper values."
4423 (skip-unless (tramp--test-enabled))
4424 ;; Since Emacs 27.1.
4425 (skip-unless (fboundp 'file-system-info
))
4427 ;; `file-system-info' exists since Emacs 27. We don't
4428 ;; want to see compiler warnings for older Emacsen.
4429 (let ((fsi (with-no-warnings
4430 (file-system-info tramp-test-temporary-file-directory
))))
4432 (should (and (consp fsi
)
4434 (numberp (nth 0 fsi
))
4435 (numberp (nth 1 fsi
))
4436 (numberp (nth 2 fsi
))))))
4438 (defun tramp--test-timeout-handler ()
4440 (ert-fail (format "`%s' timed out" (ert-test-name (ert-running-test)))))
4442 ;; This test is inspired by Bug#16928.
4443 (ert-deftest tramp-test41-asynchronous-requests
()
4444 "Check parallel asynchronous requests.
4445 Such requests could arrive from timers, process filters and
4446 process sentinels. They shall not disturb each other."
4447 :tags
'(:expensive-test
)
4448 (skip-unless (tramp--test-enabled))
4449 (skip-unless (tramp--test-sh-p))
4451 ;; This test could be blocked on hydra. So we set a timeout of 300
4452 ;; seconds, and we send a SIGUSR1 signal after 300 seconds.
4453 (with-timeout (300 (tramp--test-timeout-handler))
4454 (define-key special-event-map
[sigusr1] 'tramp--test-timeout-handler)
4455 (tramp--test-instrument-test-case (if (getenv "EMACS_HYDRA_CI") 10 0)
4456 (let* (;; For the watchdog.
4457 (default-directory (expand-file-name temporary-file-directory))
4460 "*watchdog*" nil shell-file-name shell-command-switch
4461 (format "sleep 300; kill -USR1 %d" (emacs-pid))))
4462 (tmp-name (tramp--test-make-temp-name))
4463 (default-directory tmp-name)
4464 ;; Do not cache Tramp properties.
4465 (remote-file-name-inhibit-cache t)
4466 (process-file-side-effects t)
4467 ;; Suppress nasty messages.
4469 ;; Do not run delayed timers.
4470 (timer-max-repeats 0)
4471 ;; Number of asynchronous processes for test.
4473 ;; On hydra, timings are bad.
4476 ((getenv "EMACS_HYDRA_CI") 10)
4478 ;; We must distinguish due to performance reasons.
4481 ((string-equal "mock" (file-remote-p tmp-name 'method))
4483 (t 'file-attributes)))
4484 timer buffers kill-buffer-query-functions)
4488 (make-directory tmp-name)
4490 ;; Setup a timer in order to raise an ordinary command
4491 ;; again and again. `vc-registered' is well suited,
4492 ;; because there are many checks.
4499 (let ((time (float-time))
4500 (default-directory tmp-name)
4502 (buffer-name (nth (random (length buffers)) buffers))))
4503 (tramp--test-message
4504 "Start timer %s %s" file (current-time-string))
4505 (funcall timer-operation file)
4506 ;; Adjust timer if it takes too much time.
4507 (when (> (- (float-time) time) timer-repeat)
4508 (setq timer-repeat (* 1.5 timer-repeat))
4509 (setf (timer--repeat-delay timer) timer-repeat)
4510 (tramp--test-message "Increase timer %s" timer-repeat))
4511 (tramp--test-message
4512 "Stop timer %s %s" file (current-time-string)))))))
4514 ;; Create temporary buffers. The number of buffers
4515 ;; corresponds to the number of processes; it could be
4516 ;; increased in order to make pressure on Tramp.
4517 (dotimes (_ number-proc)
4518 (setq buffers (cons (generate-new-buffer "foo") buffers)))
4520 ;; Open asynchronous processes. Set process filter and sentinel.
4521 (dolist (buf buffers)
4523 (sit-for 0.01 'nodisp)
4525 (start-file-process-shell-command
4526 (buffer-name buf) buf
4528 "(read line && echo $line >$line);"
4529 "(read line && cat $line);"
4530 "(read line && rm $line)")))
4531 (file (expand-file-name (buffer-name buf))))
4532 ;; Remember the file name. Add counter.
4533 (process-put proc 'foo file)
4534 (process-put proc 'bar 0)
4535 ;; Add process filter.
4538 (lambda (proc string)
4539 (with-current-buffer (process-buffer proc)
4541 (unless (zerop (length string))
4542 (should (file-attributes (process-get proc 'foo))))))
4543 ;; Add process sentinel.
4544 (set-process-sentinel
4546 (lambda (proc _state)
4547 (should-not (file-attributes (process-get proc 'foo)))))))
4549 ;; Send a string. Use a random order of the buffers. Mix
4550 ;; with regular operation.
4551 (let ((buffers (copy-sequence buffers)))
4554 (sit-for 0.01 'nodisp)
4555 (let* ((buf (nth (random (length buffers)) buffers))
4556 (proc (get-buffer-process buf))
4557 (file (process-get proc 'foo))
4558 (count (process-get proc 'bar)))
4559 (tramp--test-message
4560 "Start action %d %s %s" count buf (current-time-string))
4561 ;; Regular operation prior process action.
4563 (should-not (file-attributes file))
4564 (should (file-attributes file)))
4565 ;; Send string to process.
4566 (process-send-string proc (format "%s\n" (buffer-name buf)))
4567 (accept-process-output proc 0.1 nil 0)
4568 ;; Give the watchdog a chance.
4569 (read-event nil nil 0.01)
4570 ;; Regular operation post process action.
4572 (should-not (file-attributes file))
4573 (should (file-attributes file)))
4574 (tramp--test-message
4575 "Stop action %d %s %s" count buf (current-time-string))
4576 (process-put proc 'bar (1+ count))
4577 (unless (process-live-p proc)
4578 (setq buffers (delq buf buffers))))))
4580 ;; Checks. All process output shall exists in the
4581 ;; respective buffers. All created files shall be
4583 (tramp--test-message "Check %s" (current-time-string))
4584 (dolist (buf buffers)
4585 (with-current-buffer buf
4586 (should (string-equal (format "%s\n" buf) (buffer-string)))))
4589 tmp-name nil directory-files-no-dot-files-regexp)))
4592 (define-key special-event-map [sigusr1] 'ignore
)
4593 (ignore-errors (quit-process watchdog
))
4594 (dolist (buf buffers
)
4595 (ignore-errors (delete-process (get-buffer-process buf
)))
4596 (ignore-errors (kill-buffer buf
)))
4597 (ignore-errors (cancel-timer timer
))
4598 (ignore-errors (delete-directory tmp-name
'recursive
)))))))
4600 (ert-deftest tramp-test42-recursive-load
()
4601 "Check that Tramp does not fail due to recursive load."
4602 (skip-unless (tramp--test-enabled))
4604 (let ((default-directory (expand-file-name temporary-file-directory
)))
4608 "(expand-file-name %S)" tramp-test-temporary-file-directory
)
4610 "(let ((default-directory %S)) (expand-file-name %S))"
4611 tramp-test-temporary-file-directory
4612 temporary-file-directory
)))
4616 (shell-command-to-string
4618 "%s -batch -Q -L %s --eval %s"
4619 (expand-file-name invocation-name invocation-directory
)
4620 (mapconcat 'shell-quote-argument load-path
" -L ")
4621 (shell-quote-argument code
))))))))
4623 (ert-deftest tramp-test43-remote-load-path
()
4624 "Check that Tramp autoloads its packages with remote `load-path'."
4625 ;; `tramp-cleanup-all-connections' is autoloaded from tramp-cmds.el.
4626 ;; It shall still work, when a remote file name is in the
4628 (let ((default-directory (expand-file-name temporary-file-directory
))
4630 "(let ((force-load-messages t) \
4631 (load-path (cons \"/foo:bar:\" load-path))) \
4632 (tramp-cleanup-all-connections))"))
4638 "tramp-cmds" (file-name-directory (locate-library "tramp"))))
4639 (shell-command-to-string
4641 "%s -batch -Q -L %s -l tramp-sh --eval %s"
4642 (expand-file-name invocation-name invocation-directory
)
4643 (mapconcat 'shell-quote-argument load-path
" -L ")
4644 (shell-quote-argument code
)))))))
4646 (ert-deftest tramp-test44-delay-load
()
4647 "Check that Tramp is loaded lazily, only when needed."
4648 ;; Tramp is neither loaded at Emacs startup, nor when completing a
4649 ;; non-Tramp file name like "/foo". Completing a Tramp-alike file
4650 ;; name like "/foo:" autoloads Tramp, when `tramp-mode' is t.
4653 (setq tramp-mode %s) \
4654 (message \"Tramp loaded: %%s\" (featurep 'tramp)) \
4655 (file-name-all-completions \"/foo\" \"/\") \
4656 (message \"Tramp loaded: %%s\" (featurep 'tramp)) \
4657 (file-name-all-completions \"/foo:\" \"/\") \
4658 (message \"Tramp loaded: %%s\" (featurep 'tramp)))"))
4659 ;; Tramp doesn't load when `tramp-mode' is nil since Emacs 26.1.
4660 (dolist (tm (if (tramp--test-emacs26-p) '(t nil
) '(nil)))
4664 "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: %s[\n\r]+"
4666 (shell-command-to-string
4668 "%s -batch -Q -L %s --eval %s"
4669 (expand-file-name invocation-name invocation-directory
)
4670 (mapconcat 'shell-quote-argument load-path
" -L ")
4671 (shell-quote-argument (format code tm
)))))))))
4673 (ert-deftest tramp-test45-unload
()
4674 "Check that Tramp and its subpackages unload completely.
4675 Since it unloads Tramp, it shall be the last test to run."
4676 :tags
'(:expensive-test
)
4677 (skip-unless noninteractive
)
4678 ;; The autoloaded Tramp objects are different since Emacs 26.1. We
4679 ;; cannot test older Emacsen, therefore.
4680 (skip-unless (tramp--test-emacs26-p))
4682 (when (featurep 'tramp
)
4683 (unload-feature 'tramp
'force
)
4684 ;; No Tramp feature must be left.
4685 (should-not (featurep 'tramp
))
4686 (should-not (all-completions "tramp" (delq 'tramp-tests features
)))
4687 ;; `file-name-handler-alist' must be clean.
4688 (should-not (all-completions "tramp" (mapcar 'cdr file-name-handler-alist
)))
4689 ;; There shouldn't be left a bound symbol, except buffer-local
4690 ;; variables, and autoload functions. We do not regard our test
4691 ;; symbols, and the Tramp unload hooks.
4694 (and (or (and (boundp x
) (null (local-variable-if-set-p x
)))
4695 (and (functionp x
) (null (autoloadp (symbol-function x
)))))
4696 (string-match "^tramp" (symbol-name x
))
4697 (not (string-match "^tramp--?test" (symbol-name x
)))
4698 (not (string-match "unload-hook$" (symbol-name x
)))
4699 (ert-fail (format "`%s' still bound" x
)))))
4700 ;; The defstruct `tramp-file-name' and all its internal functions
4702 (should-not (cl--find-class 'tramp-file-name
))
4706 (string-match "tramp-file-name" (symbol-name x
))
4707 (ert-fail (format "Structure function `%s' still exists" x
)))))
4708 ;; There shouldn't be left a hook function containing a Tramp
4709 ;; function. We do not regard the Tramp unload hooks.
4713 (string-match "-\\(hook\\|function\\)s?$" (symbol-name x
))
4714 (not (string-match "unload-hook$" (symbol-name x
)))
4715 (consp (symbol-value x
))
4716 (ignore-errors (all-completions "tramp" (symbol-value x
)))
4717 (ert-fail (format "Hook `%s' still contains Tramp function" x
)))))))
4721 ;; * dired-compress-file
4723 ;; * file-name-case-insensitive-p
4725 ;; * Work on skipped tests. Make a comment, when it is impossible.
4726 ;; * Fix `tramp-test05-expand-file-name-relative' in `expand-file-name'.
4727 ;; * Fix `tramp-test06-directory-file-name' for `ftp'.
4728 ;; * Fix `tramp-test29-start-file-process' on MS Windows (`process-send-eof'?).
4729 ;; * Fix `tramp-test30-interrupt-process', timeout doesn't work reliably.
4730 ;; * Fix Bug#16928 in `tramp-test41-asynchronous-requests'.
4732 (defun tramp-test-all (&optional interactive
)
4733 "Run all tests for \\[tramp]."
4736 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
) "^tramp"))
4738 (provide 'tramp-tests
)
4739 ;;; tramp-tests.el ends here