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.
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 nil quoted
))
1887 (tmp-name4 (tramp--test-make-temp-name 'local quoted
))
1888 (tmp-name5 (tramp--test-make-temp-name 'local quoted
)))
1890 ;; Copy on remote side.
1893 (write-region "foo" nil tmp-name1
)
1894 (copy-file tmp-name1 tmp-name2
)
1895 (should (file-exists-p tmp-name2
))
1897 (insert-file-contents tmp-name2
)
1898 (should (string-equal (buffer-string) "foo")))
1900 (copy-file tmp-name1 tmp-name2
)
1901 :type
'file-already-exists
)
1902 (copy-file tmp-name1 tmp-name2
'ok
)
1903 (make-directory tmp-name3
)
1904 ;; This has been changed in Emacs 26.1.
1905 (when (tramp--test-emacs26-p)
1907 (copy-file tmp-name1 tmp-name3
)
1908 :type
'file-already-exists
))
1909 (copy-file tmp-name1
(file-name-as-directory tmp-name3
))
1912 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name3
))))
1915 (ignore-errors (delete-file tmp-name1
))
1916 (ignore-errors (delete-file tmp-name2
))
1917 (ignore-errors (delete-directory tmp-name3
'recursive
)))
1919 ;; Copy from remote side to local side.
1922 (write-region "foo" nil tmp-name1
)
1923 (copy-file tmp-name1 tmp-name4
)
1924 (should (file-exists-p tmp-name4
))
1926 (insert-file-contents tmp-name4
)
1927 (should (string-equal (buffer-string) "foo")))
1929 (copy-file tmp-name1 tmp-name4
)
1930 :type
'file-already-exists
)
1931 (copy-file tmp-name1 tmp-name4
'ok
)
1932 (make-directory tmp-name5
)
1933 ;; This has been changed in Emacs 26.1.
1934 (when (tramp--test-emacs26-p)
1936 (copy-file tmp-name1 tmp-name5
)
1937 :type
'file-already-exists
))
1938 (copy-file tmp-name1
(file-name-as-directory tmp-name5
))
1941 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name5
))))
1944 (ignore-errors (delete-file tmp-name1
))
1945 (ignore-errors (delete-file tmp-name4
))
1946 (ignore-errors (delete-directory tmp-name5
'recursive
)))
1948 ;; Copy from local side to remote side.
1951 (write-region "foo" nil tmp-name4 nil
'nomessage
)
1952 (copy-file tmp-name4 tmp-name1
)
1953 (should (file-exists-p tmp-name1
))
1955 (insert-file-contents tmp-name1
)
1956 (should (string-equal (buffer-string) "foo")))
1958 (copy-file tmp-name4 tmp-name1
)
1959 :type
'file-already-exists
)
1960 (copy-file tmp-name4 tmp-name1
'ok
)
1961 (make-directory tmp-name3
)
1962 ;; This has been changed in Emacs 26.1.
1963 (when (tramp--test-emacs26-p)
1965 (copy-file tmp-name4 tmp-name3
)
1966 :type
'file-already-exists
))
1967 (copy-file tmp-name4
(file-name-as-directory tmp-name3
))
1970 (expand-file-name (file-name-nondirectory tmp-name4
) tmp-name3
))))
1973 (ignore-errors (delete-file tmp-name1
))
1974 (ignore-errors (delete-file tmp-name4
))
1975 (ignore-errors (delete-directory tmp-name3
'recursive
))))))
1977 (ert-deftest tramp-test12-rename-file
()
1978 "Check `rename-file'."
1979 (skip-unless (tramp--test-enabled))
1981 ;; TODO: The quoted case does not work.
1982 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
1984 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
1985 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
1986 (tmp-name3 (tramp--test-make-temp-name nil quoted
))
1987 (tmp-name4 (tramp--test-make-temp-name 'local quoted
))
1988 (tmp-name5 (tramp--test-make-temp-name 'local quoted
)))
1990 ;; Rename on remote side.
1993 (write-region "foo" nil tmp-name1
)
1994 (rename-file tmp-name1 tmp-name2
)
1995 (should-not (file-exists-p tmp-name1
))
1996 (should (file-exists-p tmp-name2
))
1998 (insert-file-contents tmp-name2
)
1999 (should (string-equal (buffer-string) "foo")))
2000 (write-region "foo" nil tmp-name1
)
2002 (rename-file tmp-name1 tmp-name2
)
2003 :type
'file-already-exists
)
2004 (rename-file tmp-name1 tmp-name2
'ok
)
2005 (should-not (file-exists-p tmp-name1
))
2006 (write-region "foo" nil tmp-name1
)
2007 (make-directory tmp-name3
)
2008 ;; This has been changed in Emacs 26.1.
2009 (when (tramp--test-emacs26-p)
2011 (rename-file tmp-name1 tmp-name3
)
2012 :type
'file-already-exists
))
2013 (rename-file tmp-name1
(file-name-as-directory tmp-name3
))
2014 (should-not (file-exists-p tmp-name1
))
2017 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name3
))))
2020 (ignore-errors (delete-file tmp-name1
))
2021 (ignore-errors (delete-file tmp-name2
))
2022 (ignore-errors (delete-directory tmp-name3
'recursive
)))
2024 ;; Rename from remote side to local side.
2027 (write-region "foo" nil tmp-name1
)
2028 (rename-file tmp-name1 tmp-name4
)
2029 (should-not (file-exists-p tmp-name1
))
2030 (should (file-exists-p tmp-name4
))
2032 (insert-file-contents tmp-name4
)
2033 (should (string-equal (buffer-string) "foo")))
2034 (write-region "foo" nil tmp-name1
)
2036 (rename-file tmp-name1 tmp-name4
)
2037 :type
'file-already-exists
)
2038 (rename-file tmp-name1 tmp-name4
'ok
)
2039 (should-not (file-exists-p tmp-name1
))
2040 (write-region "foo" nil tmp-name1
)
2041 (make-directory tmp-name5
)
2042 ;; This has been changed in Emacs 26.1.
2043 (when (tramp--test-emacs26-p)
2045 (rename-file tmp-name1 tmp-name5
)
2046 :type
'file-already-exists
))
2047 (rename-file tmp-name1
(file-name-as-directory tmp-name5
))
2048 (should-not (file-exists-p tmp-name1
))
2051 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name5
))))
2054 (ignore-errors (delete-file tmp-name1
))
2055 (ignore-errors (delete-file tmp-name4
))
2056 (ignore-errors (delete-directory tmp-name5
'recursive
)))
2058 ;; Rename from local side to remote side.
2061 (write-region "foo" nil tmp-name4 nil
'nomessage
)
2062 (rename-file tmp-name4 tmp-name1
)
2063 (should-not (file-exists-p tmp-name4
))
2064 (should (file-exists-p tmp-name1
))
2066 (insert-file-contents tmp-name1
)
2067 (should (string-equal (buffer-string) "foo")))
2068 (write-region "foo" nil tmp-name4 nil
'nomessage
)
2070 (rename-file tmp-name4 tmp-name1
)
2071 :type
'file-already-exists
)
2072 (rename-file tmp-name4 tmp-name1
'ok
)
2073 (should-not (file-exists-p tmp-name4
))
2074 (write-region "foo" nil tmp-name4 nil
'nomessage
)
2075 (make-directory tmp-name3
)
2076 ;; This has been changed in Emacs 26.1.
2077 (when (tramp--test-emacs26-p)
2079 (rename-file tmp-name4 tmp-name3
)
2080 :type
'file-already-exists
))
2081 (rename-file tmp-name4
(file-name-as-directory tmp-name3
))
2082 (should-not (file-exists-p tmp-name4
))
2085 (expand-file-name (file-name-nondirectory tmp-name4
) tmp-name3
))))
2088 (ignore-errors (delete-file tmp-name1
))
2089 (ignore-errors (delete-file tmp-name4
))
2090 (ignore-errors (delete-directory tmp-name3
'recursive
))))))
2092 (ert-deftest tramp-test13-make-directory
()
2093 "Check `make-directory'.
2094 This tests also `file-directory-p' and `file-accessible-directory-p'."
2095 (skip-unless (tramp--test-enabled))
2097 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2098 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2099 (tmp-name2 (expand-file-name "foo/bar" tmp-name1
)))
2102 (make-directory tmp-name1
)
2103 (should (file-directory-p tmp-name1
))
2104 (should (file-accessible-directory-p tmp-name1
))
2105 (should-error (make-directory tmp-name2
) :type
'file-error
)
2106 (make-directory tmp-name2
'parents
)
2107 (should (file-directory-p tmp-name2
))
2108 (should (file-accessible-directory-p tmp-name2
))
2109 ;; If PARENTS is non-nil, `make-directory' shall not
2110 ;; signal an error when DIR exists already.
2111 (make-directory tmp-name2
'parents
))
2114 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2116 (ert-deftest tramp-test14-delete-directory
()
2117 "Check `delete-directory'."
2118 (skip-unless (tramp--test-enabled))
2120 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2121 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2122 ;; Delete empty directory.
2123 (make-directory tmp-name
)
2124 (should (file-directory-p tmp-name
))
2125 (delete-directory tmp-name
)
2126 (should-not (file-directory-p tmp-name
))
2127 ;; Delete non-empty directory.
2128 (make-directory tmp-name
)
2129 (should (file-directory-p tmp-name
))
2130 (write-region "foo" nil
(expand-file-name "bla" tmp-name
))
2131 (should (file-exists-p (expand-file-name "bla" tmp-name
)))
2132 (should-error (delete-directory tmp-name
) :type
'file-error
)
2133 (delete-directory tmp-name
'recursive
)
2134 (should-not (file-directory-p tmp-name
)))))
2136 (ert-deftest tramp-test15-copy-directory
()
2137 "Check `copy-directory'."
2138 (skip-unless (tramp--test-enabled))
2140 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2141 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2142 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2143 (tmp-name3 (expand-file-name
2144 (file-name-nondirectory tmp-name1
) tmp-name2
))
2145 (tmp-name4 (expand-file-name "foo" tmp-name1
))
2146 (tmp-name5 (expand-file-name "foo" tmp-name2
))
2147 (tmp-name6 (expand-file-name "foo" tmp-name3
)))
2149 ;; Copy complete directory.
2152 ;; Copy empty directory.
2153 (make-directory tmp-name1
)
2154 (write-region "foo" nil tmp-name4
)
2155 (should (file-directory-p tmp-name1
))
2156 (should (file-exists-p tmp-name4
))
2157 (copy-directory tmp-name1 tmp-name2
)
2158 (should (file-directory-p tmp-name2
))
2159 (should (file-exists-p tmp-name5
))
2160 ;; Target directory does exist already.
2161 ;; This has been changed in Emacs 26.1.
2162 (when (tramp--test-emacs26-p)
2164 (copy-directory tmp-name1 tmp-name2
)
2166 (copy-directory tmp-name1
(file-name-as-directory tmp-name2
))
2167 (should (file-directory-p tmp-name3
))
2168 (should (file-exists-p tmp-name6
)))
2172 (delete-directory tmp-name1
'recursive
)
2173 (delete-directory tmp-name2
'recursive
)))
2175 ;; Copy directory contents.
2178 ;; Copy empty directory.
2179 (make-directory tmp-name1
)
2180 (write-region "foo" nil tmp-name4
)
2181 (should (file-directory-p tmp-name1
))
2182 (should (file-exists-p tmp-name4
))
2183 (copy-directory tmp-name1 tmp-name2 nil
'parents
'contents
)
2184 (should (file-directory-p tmp-name2
))
2185 (should (file-exists-p tmp-name5
))
2186 ;; Target directory does exist already.
2187 (delete-file tmp-name5
)
2188 (should-not (file-exists-p tmp-name5
))
2190 tmp-name1
(file-name-as-directory tmp-name2
)
2191 nil
'parents
'contents
)
2192 (should (file-directory-p tmp-name2
))
2193 (should (file-exists-p tmp-name5
))
2194 (should-not (file-directory-p tmp-name3
))
2195 (should-not (file-exists-p tmp-name6
)))
2199 (delete-directory tmp-name1
'recursive
)
2200 (delete-directory tmp-name2
'recursive
))))))
2202 (ert-deftest tramp-test16-directory-files
()
2203 "Check `directory-files'."
2204 (skip-unless (tramp--test-enabled))
2206 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2207 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2208 (tmp-name2 (expand-file-name "bla" tmp-name1
))
2209 (tmp-name3 (expand-file-name "foo" tmp-name1
)))
2212 (make-directory tmp-name1
)
2213 (write-region "foo" nil tmp-name2
)
2214 (write-region "bla" nil tmp-name3
)
2215 (should (file-directory-p tmp-name1
))
2216 (should (file-exists-p tmp-name2
))
2217 (should (file-exists-p tmp-name3
))
2218 (should (equal (directory-files tmp-name1
) '("." ".." "bla" "foo")))
2219 (should (equal (directory-files tmp-name1
'full
)
2220 `(,(concat tmp-name1
"/.")
2221 ,(concat tmp-name1
"/..")
2222 ,tmp-name2
,tmp-name3
)))
2223 (should (equal (directory-files
2224 tmp-name1 nil directory-files-no-dot-files-regexp
)
2226 (should (equal (directory-files
2227 tmp-name1
'full directory-files-no-dot-files-regexp
)
2228 `(,tmp-name2
,tmp-name3
))))
2231 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2233 ;; This is not a file name handler test. But Tramp needed to apply an
2234 ;; advice for older Emacs versions, so we check that this has been fixed.
2235 (ert-deftest tramp-test16-file-expand-wildcards
()
2236 "Check `file-expand-wildcards'."
2237 (skip-unless (tramp--test-enabled))
2239 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2240 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2241 (tmp-name2 (expand-file-name "foo" tmp-name1
))
2242 (tmp-name3 (expand-file-name "bar" tmp-name1
))
2243 (tmp-name4 (expand-file-name "baz" tmp-name1
))
2244 (default-directory tmp-name1
))
2247 (make-directory tmp-name1
)
2248 (write-region "foo" nil tmp-name2
)
2249 (write-region "bar" nil tmp-name3
)
2250 (write-region "baz" nil tmp-name4
)
2251 (should (file-directory-p tmp-name1
))
2252 (should (file-exists-p tmp-name2
))
2253 (should (file-exists-p tmp-name3
))
2254 (should (file-exists-p tmp-name4
))
2256 ;; `sort' works destructive.
2258 (equal (file-expand-wildcards "*")
2259 (sort (copy-sequence '("foo" "bar" "baz")) 'string
<)))
2261 (equal (file-expand-wildcards "ba?")
2262 (sort (copy-sequence '("bar" "baz")) 'string
<)))
2264 (equal (file-expand-wildcards "ba[rz]")
2265 (sort (copy-sequence '("bar" "baz")) 'string
<)))
2269 (file-expand-wildcards "*" 'full
)
2271 (copy-sequence `(,tmp-name2
,tmp-name3
,tmp-name4
)) 'string
<)))
2274 (file-expand-wildcards "ba?" 'full
)
2275 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2278 (file-expand-wildcards "ba[rz]" 'full
)
2279 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2283 (file-expand-wildcards (concat tmp-name1
"/" "*"))
2285 (copy-sequence `(,tmp-name2
,tmp-name3
,tmp-name4
)) 'string
<)))
2288 (file-expand-wildcards (concat tmp-name1
"/" "ba?"))
2289 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2292 (file-expand-wildcards (concat tmp-name1
"/" "ba[rz]"))
2293 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<))))
2297 (delete-directory tmp-name1
))))))
2299 (ert-deftest tramp-test17-insert-directory
()
2300 "Check `insert-directory'."
2301 (skip-unless (tramp--test-enabled))
2303 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2305 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2306 (tmp-name2 (expand-file-name "foo" tmp-name1
))
2307 ;; We test for the summary line. Keyword "total" could be localized.
2308 (process-environment
2309 (append '("LANG=C" "LANGUAGE=C" "LC_ALL=C") process-environment
)))
2312 (make-directory tmp-name1
)
2313 (write-region "foo" nil tmp-name2
)
2314 (should (file-directory-p tmp-name1
))
2315 (should (file-exists-p tmp-name2
))
2317 (insert-directory tmp-name1 nil
)
2318 (goto-char (point-min))
2319 (should (looking-at-p (regexp-quote tmp-name1
))))
2321 (insert-directory tmp-name1
"-al")
2322 (goto-char (point-min))
2324 (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1
)))))
2326 (insert-directory (file-name-as-directory tmp-name1
) "-al")
2327 (goto-char (point-min))
2329 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1
)))))
2332 (file-name-as-directory tmp-name1
) "-al" nil
'full-directory-p
)
2333 (goto-char (point-min))
2337 ;; There might be a summary line.
2338 "\\(total.+[[:digit:]]+\n\\)?"
2339 ;; We don't know in which order ".", ".." and "foo" appear.
2340 "\\(.+ \\(\\.?\\.\\|foo\\)\n\\)\\{3\\}")))))
2343 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2345 (ert-deftest tramp-test17-dired-with-wildcards
()
2346 "Check `dired' with wildcards."
2347 (skip-unless (tramp--test-enabled))
2348 (skip-unless (tramp--test-sh-p))
2349 (skip-unless (not (tramp--test-rsync-p)))
2350 ;; Since Emacs 26.1.
2351 (skip-unless (fboundp 'insert-directory-wildcard-in-dir-p
))
2353 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2355 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2357 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2358 (tmp-name3 (expand-file-name "foo" tmp-name1
))
2359 (tmp-name4 (expand-file-name "bar" tmp-name2
))
2360 (tramp-test-temporary-file-directory
2362 (if quoted
'tramp-compat-file-name-quote
'identity
)
2363 tramp-test-temporary-file-directory
))
2367 (make-directory tmp-name1
)
2368 (write-region "foo" nil tmp-name3
)
2369 (should (file-directory-p tmp-name1
))
2370 (should (file-exists-p tmp-name3
))
2371 (make-directory tmp-name2
)
2372 (write-region "foo" nil tmp-name4
)
2373 (should (file-directory-p tmp-name2
))
2374 (should (file-exists-p tmp-name4
))
2376 ;; Check for expanded directory names.
2377 (with-current-buffer
2381 "tramp-test*" tramp-test-temporary-file-directory
)))
2382 (goto-char (point-min))
2387 tmp-name1 tramp-test-temporary-file-directory
))))
2388 (goto-char (point-min))
2393 tmp-name2 tramp-test-temporary-file-directory
)))))
2394 (kill-buffer buffer
)
2396 ;; Check for expanded directory and file names.
2397 (with-current-buffer
2401 "tramp-test*/*" tramp-test-temporary-file-directory
)))
2402 (goto-char (point-min))
2407 tmp-name3 tramp-test-temporary-file-directory
))))
2408 (goto-char (point-min))
2414 tramp-test-temporary-file-directory
)))))
2415 (kill-buffer buffer
)
2417 ;; Check for special characters.
2418 (setq tmp-name3
(expand-file-name "*?" tmp-name1
))
2419 (setq tmp-name4
(expand-file-name "[a-z0-9]" tmp-name2
))
2420 (write-region "foo" nil tmp-name3
)
2421 (should (file-exists-p tmp-name3
))
2422 (write-region "foo" nil tmp-name4
)
2423 (should (file-exists-p tmp-name4
))
2425 (with-current-buffer
2429 "tramp-test*/*" tramp-test-temporary-file-directory
)))
2430 (goto-char (point-min))
2435 tmp-name3 tramp-test-temporary-file-directory
))))
2436 (goto-char (point-min))
2442 tramp-test-temporary-file-directory
)))))
2443 (kill-buffer buffer
))
2446 (ignore-errors (kill-buffer buffer
))
2447 (ignore-errors (delete-directory tmp-name1
'recursive
))
2448 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
2450 ;; Method "smb" supports `make-symbolic-link' only if the remote host
2451 ;; has CIFS capabilities. tramp-adb.el and tramp-gvfs.el do not
2452 ;; support symbolic links at all.
2453 (defmacro tramp--test-ignore-make-symbolic-link-error
(&rest body
)
2454 "Run BODY, ignoring \"make-symbolic-link not supported\" file error."
2455 (declare (indent defun
) (debug t
))
2456 `(condition-case err
2459 (unless (and (eq (car err
) 'file-error
)
2460 (string-equal (error-message-string err
)
2461 "make-symbolic-link not supported"))
2462 (signal (car err
) (cdr err
))))))
2464 (ert-deftest tramp-test18-file-attributes
()
2465 "Check `file-attributes'.
2466 This tests also `file-readable-p', `file-regular-p' and
2467 `file-ownership-preserved-p'."
2468 (skip-unless (tramp--test-enabled))
2470 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2471 ;; We must use `file-truename' for the temporary directory,
2472 ;; because it could be located on a symlinked directory. This
2473 ;; would let the test fail.
2474 (let* ((tramp-test-temporary-file-directory
2475 (file-truename tramp-test-temporary-file-directory
))
2476 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
2477 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2478 ;; File name with "//".
2482 (file-remote-p tmp-name1
)
2483 (replace-regexp-in-string
2484 "/" "//" (file-remote-p tmp-name1
'localname
))))
2488 ;; `file-ownership-preserved-p' should return t for
2489 ;; non-existing files. It is implemented only in tramp-sh.el.
2490 (when (tramp--test-sh-p)
2491 (should (file-ownership-preserved-p tmp-name1
'group
)))
2492 (write-region "foo" nil tmp-name1
)
2493 (should (file-exists-p tmp-name1
))
2494 (should (file-readable-p tmp-name1
))
2495 (should (file-regular-p tmp-name1
))
2496 (when (tramp--test-sh-p)
2497 (should (file-ownership-preserved-p tmp-name1
'group
)))
2499 ;; We do not test inodes and device numbers.
2500 (setq attr
(file-attributes tmp-name1
))
2501 (should (consp attr
))
2502 (should (null (car attr
)))
2503 (should (numberp (nth 1 attr
))) ;; Link.
2504 (should (numberp (nth 2 attr
))) ;; Uid.
2505 (should (numberp (nth 3 attr
))) ;; Gid.
2506 ;; Last access time.
2507 (should (stringp (current-time-string (nth 4 attr
))))
2508 ;; Last modification time.
2509 (should (stringp (current-time-string (nth 5 attr
))))
2510 ;; Last status change time.
2511 (should (stringp (current-time-string (nth 6 attr
))))
2512 (should (numberp (nth 7 attr
))) ;; Size.
2513 (should (stringp (nth 8 attr
))) ;; Modes.
2515 (setq attr
(file-attributes tmp-name1
'string
))
2516 (should (stringp (nth 2 attr
))) ;; Uid.
2517 (should (stringp (nth 3 attr
))) ;; Gid.
2519 (tramp--test-ignore-make-symbolic-link-error
2520 (when (tramp--test-sh-p)
2521 (should (file-ownership-preserved-p tmp-name2
'group
)))
2522 (make-symbolic-link tmp-name1 tmp-name2
)
2523 (should (file-exists-p tmp-name2
))
2524 (should (file-symlink-p tmp-name2
))
2525 (when (tramp--test-sh-p)
2526 (should (file-ownership-preserved-p tmp-name2
'group
)))
2527 (setq attr
(file-attributes tmp-name2
))
2531 (if quoted
'tramp-compat-file-name-quote
'identity
)
2533 (file-remote-p (file-truename tmp-name1
) 'localname
)))
2534 (delete-file tmp-name2
))
2536 ;; Check, that "//" in symlinks are handled properly.
2538 (let ((default-directory tramp-test-temporary-file-directory
))
2542 (tramp-file-name-localname
2543 (tramp-dissect-file-name tmp-name3
))
2544 (tramp-file-name-localname
2545 (tramp-dissect-file-name tmp-name2
)))
2547 (when (file-symlink-p tmp-name2
)
2548 (setq attr
(file-attributes tmp-name2
))
2552 (tramp-file-name-localname
2553 (tramp-dissect-file-name tmp-name3
))))
2554 (delete-file tmp-name2
))
2556 (when (tramp--test-sh-p)
2557 (should (file-ownership-preserved-p tmp-name1
'group
)))
2558 (delete-file tmp-name1
)
2559 (make-directory tmp-name1
)
2560 (should (file-exists-p tmp-name1
))
2561 (should (file-readable-p tmp-name1
))
2562 (should-not (file-regular-p tmp-name1
))
2563 (when (tramp--test-sh-p)
2564 (should (file-ownership-preserved-p tmp-name1
'group
)))
2565 (setq attr
(file-attributes tmp-name1
))
2566 (should (eq (car attr
) t
)))
2569 (ignore-errors (delete-directory tmp-name1
))
2570 (ignore-errors (delete-file tmp-name1
))
2571 (ignore-errors (delete-file tmp-name2
))))))
2573 (ert-deftest tramp-test19-directory-files-and-attributes
()
2574 "Check `directory-files-and-attributes'."
2575 (skip-unless (tramp--test-enabled))
2577 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2578 ;; `directory-files-and-attributes' contains also values for
2579 ;; "../". Ensure that this doesn't change during tests, for
2580 ;; example due to handling temporary files.
2581 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2582 (tmp-name2 (expand-file-name "bla" tmp-name1
))
2586 (make-directory tmp-name1
)
2587 (should (file-directory-p tmp-name1
))
2588 (make-directory tmp-name2
)
2589 (should (file-directory-p tmp-name2
))
2590 (write-region "foo" nil
(expand-file-name "foo" tmp-name2
))
2591 (write-region "bar" nil
(expand-file-name "bar" tmp-name2
))
2592 (write-region "boz" nil
(expand-file-name "boz" tmp-name2
))
2593 (setq attr
(directory-files-and-attributes tmp-name2
))
2594 (should (consp attr
))
2595 ;; Dumb remote shells without perl(1) or stat(1) are not
2596 ;; able to return the date correctly. They say "don't know".
2601 5 (file-attributes (expand-file-name (car elt
) tmp-name2
)))
2604 (equal (file-attributes (expand-file-name (car elt
) tmp-name2
))
2606 (setq attr
(directory-files-and-attributes tmp-name2
'full
))
2608 (unless (equal (nth 5 (file-attributes (car elt
))) '(0 0))
2610 (equal (file-attributes (car elt
)) (cdr elt
)))))
2611 (setq attr
(directory-files-and-attributes tmp-name2 nil
"^b"))
2612 (should (equal (mapcar 'car attr
) '("bar" "boz"))))
2615 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2617 (ert-deftest tramp-test20-file-modes
()
2618 "Check `file-modes'.
2619 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
2620 (skip-unless (tramp--test-enabled))
2621 (skip-unless (tramp--test-sh-p))
2623 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2624 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2627 (write-region "foo" nil tmp-name
)
2628 (should (file-exists-p tmp-name
))
2629 (set-file-modes tmp-name
#o777
)
2630 (should (= (file-modes tmp-name
) #o777
))
2631 (should (file-executable-p tmp-name
))
2632 (should (file-writable-p tmp-name
))
2633 (set-file-modes tmp-name
#o444
)
2634 (should (= (file-modes tmp-name
) #o444
))
2635 (should-not (file-executable-p tmp-name
))
2636 ;; A file is always writable for user "root".
2637 (unless (zerop (nth 2 (file-attributes tmp-name
)))
2638 (should-not (file-writable-p tmp-name
))))
2641 (ignore-errors (delete-file tmp-name
))))))
2643 (ert-deftest tramp-test21-file-links
()
2644 "Check `file-symlink-p'.
2645 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2646 (skip-unless (tramp--test-enabled))
2647 ;; The semantics has changed heavily in Emacs 26.1. We cannot test
2648 ;; older Emacsen, therefore.
2649 (skip-unless (tramp--test-emacs26-p))
2651 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2652 ;; We must use `file-truename' for the temporary directory,
2653 ;; because it could be located on a symlinked directory. This
2654 ;; would let the test fail.
2655 (let* ((tramp-test-temporary-file-directory
2656 (file-truename tramp-test-temporary-file-directory
))
2657 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
2658 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2659 (tmp-name3 (tramp--test-make-temp-name 'local quoted
))
2660 (tmp-name4 (tramp--test-make-temp-name nil quoted
))
2662 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name4
)))
2663 ;; Check `make-symbolic-link'.
2665 (tramp--test-ignore-make-symbolic-link-error
2666 (write-region "foo" nil tmp-name1
)
2667 (should (file-exists-p tmp-name1
))
2668 (make-symbolic-link tmp-name1 tmp-name2
)
2672 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2673 (file-remote-p tmp-name1
'localname
))
2674 (file-symlink-p tmp-name2
)))
2676 (make-symbolic-link tmp-name1 tmp-name2
)
2677 :type
'file-already-exists
)
2678 ;; number means interactive case.
2679 (cl-letf (((symbol-function 'yes-or-no-p
) 'ignore
))
2681 (make-symbolic-link tmp-name1 tmp-name2
0)
2682 :type
'file-already-exists
))
2683 (cl-letf (((symbol-function 'yes-or-no-p
) (lambda (_prompt) t
)))
2684 (make-symbolic-link tmp-name1 tmp-name2
0)
2688 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2689 (file-remote-p tmp-name1
'localname
))
2690 (file-symlink-p tmp-name2
))))
2691 (make-symbolic-link tmp-name1 tmp-name2
'ok-if-already-exists
)
2695 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2696 (file-remote-p tmp-name1
'localname
))
2697 (file-symlink-p tmp-name2
)))
2698 ;; If we use the local part of `tmp-name1', it shall still work.
2700 (file-remote-p tmp-name1
'localname
)
2701 tmp-name2
'ok-if-already-exists
)
2705 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2706 (file-remote-p tmp-name1
'localname
))
2707 (file-symlink-p tmp-name2
)))
2708 ;; `tmp-name3' is a local file name. Therefore, the link
2709 ;; target remains unchanged, even if quoted.
2710 (make-symbolic-link tmp-name1 tmp-name3
)
2712 (string-equal tmp-name1
(file-symlink-p tmp-name3
)))
2713 ;; Check directory as newname.
2714 (make-directory tmp-name4
)
2716 (make-symbolic-link tmp-name1 tmp-name4
)
2717 :type
'file-already-exists
)
2718 (make-symbolic-link tmp-name1
(file-name-as-directory tmp-name4
))
2722 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2723 (file-remote-p tmp-name1
'localname
))
2724 (file-symlink-p tmp-name5
)))
2725 ;; `smbclient' does not show symlinks in directories, so
2726 ;; we cannot delete a non-empty directory. We delete the
2728 (delete-file tmp-name5
))
2732 (delete-file tmp-name1
)
2733 (delete-file tmp-name2
)
2734 (delete-file tmp-name3
)
2735 (delete-directory tmp-name4
'recursive
)))
2737 ;; Check `add-name-to-file'.
2740 (write-region "foo" nil tmp-name1
)
2741 (should (file-exists-p tmp-name1
))
2742 (add-name-to-file tmp-name1 tmp-name2
)
2743 (should (file-regular-p tmp-name2
))
2745 (add-name-to-file tmp-name1 tmp-name2
)
2746 :type
'file-already-exists
)
2747 ;; A number means interactive case.
2748 (cl-letf (((symbol-function 'yes-or-no-p
) 'ignore
))
2750 (add-name-to-file tmp-name1 tmp-name2
0)
2751 :type
'file-already-exists
))
2752 (cl-letf (((symbol-function 'yes-or-no-p
) (lambda (_prompt) t
)))
2753 (add-name-to-file tmp-name1 tmp-name2
0)
2754 (should (file-regular-p tmp-name2
)))
2755 (add-name-to-file tmp-name1 tmp-name2
'ok-if-already-exists
)
2756 (should-not (file-symlink-p tmp-name2
))
2757 (should (file-regular-p tmp-name2
))
2758 ;; `tmp-name3' is a local file name.
2760 (add-name-to-file tmp-name1 tmp-name3
)
2762 ;; Check directory as newname.
2763 (make-directory tmp-name4
)
2765 (add-name-to-file tmp-name1 tmp-name4
)
2766 :type
'file-already-exists
)
2767 (add-name-to-file tmp-name1
(file-name-as-directory tmp-name4
))
2770 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name4
))))
2774 (delete-file tmp-name1
)
2775 (delete-file tmp-name2
)
2776 (delete-directory tmp-name4
'recursive
)))
2778 ;; Check `file-truename'.
2780 (tramp--test-ignore-make-symbolic-link-error
2781 (write-region "foo" nil tmp-name1
)
2782 (should (file-exists-p tmp-name1
))
2783 (should (string-equal tmp-name1
(file-truename tmp-name1
)))
2784 (make-symbolic-link tmp-name1 tmp-name2
)
2785 (should (file-symlink-p tmp-name2
))
2786 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
2788 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
)))
2789 (should (file-equal-p tmp-name1 tmp-name2
))
2790 ;; Symbolic links could look like a remote file name.
2791 ;; They must be quoted then.
2792 (delete-file tmp-name2
)
2793 (make-symbolic-link "/penguin:motd:" tmp-name2
)
2794 (should (file-symlink-p tmp-name2
))
2797 (file-truename tmp-name2
)
2798 (tramp-compat-file-name-quote
2799 (concat (file-remote-p tmp-name2
) "/penguin:motd:"))))
2800 ;; `tmp-name3' is a local file name.
2801 (make-symbolic-link tmp-name1 tmp-name3
)
2802 (should (file-symlink-p tmp-name3
))
2803 (should-not (string-equal tmp-name3
(file-truename tmp-name3
)))
2804 ;; `file-truename' returns a quoted file name for `tmp-name3'.
2805 ;; We must unquote it.
2808 (file-truename tmp-name1
)
2809 (tramp-compat-file-name-unquote (file-truename tmp-name3
)))))
2813 (delete-file tmp-name1
)
2814 (delete-file tmp-name2
)
2815 (delete-file tmp-name3
)))
2817 ;; Symbolic links could be nested.
2819 (tramp--test-ignore-make-symbolic-link-error
2820 (make-directory tmp-name1
)
2821 (should (file-directory-p tmp-name1
))
2822 (let* ((tramp-test-temporary-file-directory
2823 (file-truename tmp-name1
))
2824 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2825 (tmp-name3 tmp-name2
)
2826 (number-nesting 15))
2827 (dotimes (_ number-nesting
)
2830 (setq tmp-name3
(tramp--test-make-temp-name nil quoted
))))
2833 (file-truename tmp-name2
)
2834 (file-truename tmp-name3
)))
2836 (with-temp-buffer (insert-file-contents tmp-name2
))
2837 :type tramp-file-missing
)
2839 (with-temp-buffer (insert-file-contents tmp-name3
))
2840 :type tramp-file-missing
)
2841 ;; `directory-files' does not show symlinks to
2842 ;; non-existing targets in the "smb" case. So we remove
2843 ;; the symlinks manually.
2844 (while (stringp (setq tmp-name2
(file-symlink-p tmp-name3
)))
2845 (delete-file tmp-name3
)
2846 (setq tmp-name3
(concat (file-remote-p tmp-name3
) tmp-name2
)))))
2849 (ignore-errors (delete-directory tmp-name1
'recursive
)))
2851 ;; Detect cyclic symbolic links.
2853 (tramp--test-ignore-make-symbolic-link-error
2854 (make-symbolic-link tmp-name2 tmp-name1
)
2855 (should (file-symlink-p tmp-name1
))
2856 (make-symbolic-link tmp-name1 tmp-name2
)
2857 (should (file-symlink-p tmp-name2
))
2858 (should-error (file-truename tmp-name1
) :type
'file-error
))
2862 (delete-file tmp-name1
)
2863 (delete-file tmp-name2
)))
2865 ;; `file-truename' shall preserve trailing link of directories.
2866 (unless (file-symlink-p tramp-test-temporary-file-directory
)
2867 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory
))
2868 (dir2 (file-name-as-directory dir1
)))
2869 (should (string-equal (file-truename dir1
) (expand-file-name dir1
)))
2871 (string-equal (file-truename dir2
) (expand-file-name dir2
))))))))
2873 (ert-deftest tramp-test22-file-times
()
2874 "Check `set-file-times' and `file-newer-than-file-p'."
2875 (skip-unless (tramp--test-enabled))
2876 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
2878 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2879 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2880 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2881 (tmp-name3 (tramp--test-make-temp-name nil quoted
)))
2884 (write-region "foo" nil tmp-name1
)
2885 (should (file-exists-p tmp-name1
))
2886 (should (consp (nth 5 (file-attributes tmp-name1
))))
2887 ;; '(0 0) means don't know, and will be replaced by
2888 ;; `current-time'. Therefore, we use '(0 1). We skip the
2889 ;; test, if the remote handler is not able to set the
2891 (skip-unless (set-file-times tmp-name1
'(0 1)))
2892 ;; Dumb remote shells without perl(1) or stat(1) are not
2893 ;; able to return the date correctly. They say "don't know".
2894 (unless (equal (nth 5 (file-attributes tmp-name1
)) '(0 0))
2895 (should (equal (nth 5 (file-attributes tmp-name1
)) '(0 1)))
2896 (write-region "bla" nil tmp-name2
)
2897 (should (file-exists-p tmp-name2
))
2898 (should (file-newer-than-file-p tmp-name2 tmp-name1
))
2899 ;; `tmp-name3' does not exist.
2900 (should (file-newer-than-file-p tmp-name2 tmp-name3
))
2901 (should-not (file-newer-than-file-p tmp-name3 tmp-name1
))))
2905 (delete-file tmp-name1
)
2906 (delete-file tmp-name2
))))))
2908 (ert-deftest tramp-test23-visited-file-modtime
()
2909 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
2910 (skip-unless (tramp--test-enabled))
2912 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2913 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2916 (write-region "foo" nil tmp-name
)
2917 (should (file-exists-p tmp-name
))
2919 (insert-file-contents tmp-name
)
2920 (should (verify-visited-file-modtime))
2921 (set-visited-file-modtime '(0 1))
2922 (should (verify-visited-file-modtime))
2923 (should (equal (visited-file-modtime) '(0 1 0 0)))))
2926 (ignore-errors (delete-file tmp-name
))))))
2928 (ert-deftest tramp-test24-file-name-completion
()
2929 "Check `file-name-completion' and `file-name-all-completions'."
2930 (skip-unless (tramp--test-enabled))
2932 ;; Method and host name in completion mode. This kind of completion
2933 ;; does not work on MS Windows.
2934 (when (not (memq system-type
'(cygwin windows-nt
)))
2935 (let ((method (file-remote-p tramp-test-temporary-file-directory
'method
))
2936 (host (file-remote-p tramp-test-temporary-file-directory
'host
))
2937 (orig-syntax tramp-syntax
))
2938 (when (and (stringp host
) (string-match tramp-host-with-port-regexp host
))
2939 (setq host
(match-string 1 host
)))
2944 (if tramp--test-expensive-test
2945 (tramp-syntax-values) `(,orig-syntax
)))
2946 (tramp-change-syntax syntax
)
2947 (let ;; This is needed for the `simplified' syntax.
2949 (if (zerop (length tramp-method-regexp
))
2950 "" tramp-default-method-marker
))
2951 ;; This is needed for the `separate' syntax.
2952 (prefix-format (substring tramp-prefix-format
1)))
2953 ;; Complete method name.
2954 (unless (or (zerop (length method
))
2955 (zerop (length tramp-method-regexp
)))
2958 (concat prefix-format method tramp-postfix-method-format
)
2959 (file-name-all-completions
2960 (concat prefix-format
(substring method
0 1)) "/"))))
2961 ;; Complete host name for default method. With gvfs
2962 ;; based methods, host name will be determined as
2963 ;; host.local, so we omit the test.
2964 (let ((tramp-default-method (or method tramp-default-method
)))
2965 (unless (or (zerop (length host
))
2966 (tramp--test-gvfs-p tramp-default-method
))
2970 prefix-format method-marker tramp-postfix-method-format
2971 host tramp-postfix-host-format
)
2972 (file-name-all-completions
2974 prefix-format method-marker tramp-postfix-method-format
2975 (substring host
0 1))
2977 ;; Complete host name.
2978 (unless (or (zerop (length method
))
2979 (zerop (length tramp-method-regexp
))
2980 (zerop (length host
))
2981 (tramp--test-gvfs-p method
))
2985 prefix-format method tramp-postfix-method-format
2986 host tramp-postfix-host-format
)
2987 (file-name-all-completions
2988 (concat prefix-format method tramp-postfix-method-format
)
2992 (tramp-change-syntax orig-syntax
))))
2994 (dolist (n-e '(nil t
))
2995 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2996 (let ((non-essential n-e
)
2997 (tmp-name (tramp--test-make-temp-name nil quoted
)))
3002 (make-directory tmp-name
)
3003 (should (file-directory-p tmp-name
))
3004 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
3005 (should (file-exists-p (expand-file-name "foo" tmp-name
)))
3006 (write-region "bar" nil
(expand-file-name "bold" tmp-name
))
3007 (should (file-exists-p (expand-file-name "bold" tmp-name
)))
3008 (make-directory (expand-file-name "boz" tmp-name
))
3009 (should (file-directory-p (expand-file-name "boz" tmp-name
)))
3010 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
3011 (should (equal (file-name-completion "foo" tmp-name
) t
))
3012 (should (equal (file-name-completion "b" tmp-name
) "bo"))
3013 (should-not (file-name-completion "a" tmp-name
))
3016 (file-name-completion "b" tmp-name
'file-directory-p
) "boz/"))
3018 (equal (file-name-all-completions "fo" tmp-name
) '("foo")))
3021 (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
3023 (should-not (file-name-all-completions "a" tmp-name
))
3024 ;; `completion-regexp-list' restricts the completion to
3025 ;; files which match all expressions in this list.
3026 (let ((completion-regexp-list
3027 `(,directory-files-no-dot-files-regexp
"b")))
3029 (equal (file-name-completion "" tmp-name
) "bo"))
3032 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
3034 ;; `file-name-completion' ignores file names that end in
3035 ;; any string in `completion-ignored-extensions'.
3036 (let ((completion-ignored-extensions '(".ext")))
3037 (write-region "foo" nil
(expand-file-name "foo.ext" tmp-name
))
3038 (should (file-exists-p (expand-file-name "foo.ext" tmp-name
)))
3039 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
3040 (should (equal (file-name-completion "foo" tmp-name
) t
))
3042 (equal (file-name-completion "foo." tmp-name
) "foo.ext"))
3043 (should (equal (file-name-completion "foo.ext" tmp-name
) t
))
3044 ;; `file-name-all-completions' is not affected.
3047 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
3048 '("../" "./" "bold" "boz/" "foo" "foo.ext")))))
3051 (ignore-errors (delete-directory tmp-name
'recursive
)))))))
3053 (ert-deftest tramp-test25-load
()
3055 (skip-unless (tramp--test-enabled))
3057 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3058 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
3061 (load tmp-name
'noerror
'nomessage
)
3062 (should-not (featurep 'tramp-test-load
))
3063 (write-region "(provide 'tramp-test-load)" nil tmp-name
)
3064 ;; `load' in lread.c does not pass `must-suffix'. Why?
3066 ;; (load tmp-name nil 'nomessage 'nosuffix 'must-suffix)
3067 ;; :type 'file-error)
3068 (load tmp-name nil
'nomessage
'nosuffix
)
3069 (should (featurep 'tramp-test-load
)))
3073 (and (featurep 'tramp-test-load
) (unload-feature 'tramp-test-load
))
3074 (delete-file tmp-name
))))))
3076 (ert-deftest tramp-test26-process-file
()
3077 "Check `process-file'."
3078 :tags
'(:expensive-test
)
3079 (skip-unless (tramp--test-enabled))
3080 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
3082 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3083 (let* ((tmp-name (tramp--test-make-temp-name nil quoted
))
3084 (fnnd (file-name-nondirectory tmp-name
))
3085 (default-directory tramp-test-temporary-file-directory
)
3086 kill-buffer-query-functions
)
3089 ;; We cannot use "/bin/true" and "/bin/false"; those paths
3090 ;; do not exist on hydra.
3091 (should (zerop (process-file "true")))
3092 (should-not (zerop (process-file "false")))
3093 (should-not (zerop (process-file "binary-does-not-exist")))
3095 (write-region "foo" nil tmp-name
)
3096 (should (file-exists-p tmp-name
))
3097 (should (zerop (process-file "ls" nil t nil fnnd
)))
3098 ;; `ls' could produce colorized output.
3099 (goto-char (point-min))
3101 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3102 (replace-match "" nil nil
))
3103 (should (string-equal (format "%s\n" fnnd
) (buffer-string)))
3104 (should-not (get-buffer-window (current-buffer) t
))
3106 ;; Second run. The output must be appended.
3107 (goto-char (point-max))
3108 (should (zerop (process-file "ls" nil t t fnnd
)))
3109 ;; `ls' could produce colorized output.
3110 (goto-char (point-min))
3112 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3113 (replace-match "" nil nil
))
3115 (string-equal (format "%s\n%s\n" fnnd fnnd
) (buffer-string)))
3116 ;; A non-nil DISPLAY must not raise the buffer.
3117 (should-not (get-buffer-window (current-buffer) t
))))
3120 (ignore-errors (delete-file tmp-name
))))))
3122 (ert-deftest tramp-test27-start-file-process
()
3123 "Check `start-file-process'."
3124 :tags
'(:expensive-test
)
3125 (skip-unless (tramp--test-enabled))
3126 (skip-unless (tramp--test-sh-p))
3128 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3129 (let ((default-directory tramp-test-temporary-file-directory
)
3130 (tmp-name (tramp--test-make-temp-name nil quoted
))
3131 kill-buffer-query-functions proc
)
3134 (setq proc
(start-file-process "test1" (current-buffer) "cat"))
3135 (should (processp proc
))
3136 (should (equal (process-status proc
) 'run
))
3137 (process-send-string proc
"foo")
3138 (process-send-eof proc
)
3140 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3141 (while (< (- (point-max) (point-min)) (length "foo"))
3142 (accept-process-output proc
0.1)))
3143 (should (string-equal (buffer-string) "foo")))
3146 (ignore-errors (delete-process proc
)))
3150 (write-region "foo" nil tmp-name
)
3151 (should (file-exists-p tmp-name
))
3154 "test2" (current-buffer)
3155 "cat" (file-name-nondirectory tmp-name
)))
3156 (should (processp proc
))
3158 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3159 (while (< (- (point-max) (point-min)) (length "foo"))
3160 (accept-process-output proc
0.1)))
3161 (should (string-equal (buffer-string) "foo")))
3165 (delete-process proc
)
3166 (delete-file tmp-name
)))
3170 (setq proc
(start-file-process "test3" (current-buffer) "cat"))
3171 (should (processp proc
))
3172 (should (equal (process-status proc
) 'run
))
3175 (lambda (p s
) (with-current-buffer (process-buffer p
) (insert s
))))
3176 (process-send-string proc
"foo")
3177 (process-send-eof proc
)
3179 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3180 (while (< (- (point-max) (point-min)) (length "foo"))
3181 (accept-process-output proc
0.1)))
3182 (should (string-equal (buffer-string) "foo")))
3185 (ignore-errors (delete-process proc
))))))
3187 (ert-deftest tramp-test28-interrupt-process
()
3188 "Check `interrupt-process'."
3189 :tags
'(:expensive-test
)
3190 (skip-unless (tramp--test-enabled))
3191 (skip-unless (tramp--test-sh-p))
3192 ;; Since Emacs 26.1.
3193 (skip-unless (boundp 'interrupt-process-functions
))
3195 (let ((default-directory tramp-test-temporary-file-directory
)
3196 kill-buffer-query-functions proc
)
3199 (setq proc
(start-file-process "test" (current-buffer) "sleep" "10"))
3200 (should (processp proc
))
3201 (should (process-live-p proc
))
3202 (should (equal (process-status proc
) 'run
))
3203 (should (numberp (process-get proc
'remote-pid
)))
3204 (should (interrupt-process proc
))
3205 ;; Let the process accept the interrupt.
3206 (accept-process-output proc
1 nil
0)
3207 (should-not (process-live-p proc
))
3208 ;; An interrupted process cannot be interrupted, again.
3209 (should-error (interrupt-process proc
) :type
'error
))
3212 (ignore-errors (delete-process proc
)))))
3214 (ert-deftest tramp-test29-shell-command
()
3215 "Check `shell-command'."
3216 :tags
'(:expensive-test
)
3217 (skip-unless (tramp--test-enabled))
3218 (skip-unless (tramp--test-sh-p))
3220 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3221 (let ((tmp-name (tramp--test-make-temp-name nil quoted
))
3222 (default-directory tramp-test-temporary-file-directory
)
3223 ;; Suppress nasty messages.
3225 kill-buffer-query-functions
)
3228 (write-region "foo" nil tmp-name
)
3229 (should (file-exists-p tmp-name
))
3231 (format "ls %s" (file-name-nondirectory tmp-name
))
3233 ;; `ls' could produce colorized output.
3234 (goto-char (point-min))
3236 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3237 (replace-match "" nil nil
))
3240 (format "%s\n" (file-name-nondirectory tmp-name
))
3244 (ignore-errors (delete-file tmp-name
)))
3248 (write-region "foo" nil tmp-name
)
3249 (should (file-exists-p tmp-name
))
3250 (async-shell-command
3251 (format "ls %s" (file-name-nondirectory tmp-name
))
3254 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
3255 (while (< (- (point-max) (point-min))
3256 (1+ (length (file-name-nondirectory tmp-name
))))
3257 (accept-process-output
3258 (get-buffer-process (current-buffer)) 0.1)))
3259 ;; `ls' could produce colorized output.
3260 (goto-char (point-min))
3262 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3263 (replace-match "" nil nil
))
3264 ;; There might be a nasty "Process *Async Shell* finished" message.
3265 (goto-char (point-min))
3267 (narrow-to-region (point-min) (point))
3270 (format "%s\n" (file-name-nondirectory tmp-name
))
3274 (ignore-errors (delete-file tmp-name
)))
3278 (write-region "foo" nil tmp-name
)
3279 (should (file-exists-p tmp-name
))
3280 (async-shell-command "read line; ls $line" (current-buffer))
3281 (process-send-string
3282 (get-buffer-process (current-buffer))
3283 (format "%s\n" (file-name-nondirectory tmp-name
)))
3285 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
3286 (while (< (- (point-max) (point-min))
3287 (1+ (length (file-name-nondirectory tmp-name
))))
3288 (accept-process-output
3289 (get-buffer-process (current-buffer)) 0.1)))
3290 ;; `ls' could produce colorized output.
3291 (goto-char (point-min))
3293 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3294 (replace-match "" nil nil
))
3295 ;; There might be a nasty "Process *Async Shell* finished" message.
3296 (goto-char (point-min))
3298 (narrow-to-region (point-min) (point))
3301 (format "%s\n" (file-name-nondirectory tmp-name
))
3305 (ignore-errors (delete-file tmp-name
))))))
3307 (defun tramp--test-shell-command-to-string-asynchronously (command)
3308 "Like `shell-command-to-string', but for asynchronous processes."
3310 (async-shell-command command
(current-buffer))
3312 (while (get-buffer-process (current-buffer))
3313 (accept-process-output (get-buffer-process (current-buffer)) 0.1)))
3314 (accept-process-output nil
0.1)
3315 (buffer-substring-no-properties (point-min) (point-max))))
3317 ;; This test is inspired by Bug#23952.
3318 (ert-deftest tramp-test30-environment-variables
()
3319 "Check that remote processes set / unset environment variables properly."
3320 :tags
'(:expensive-test
)
3321 (skip-unless (tramp--test-enabled))
3322 (skip-unless (tramp--test-sh-p))
3324 (dolist (this-shell-command-to-string
3326 shell-command-to-string
3328 tramp--test-shell-command-to-string-asynchronously
))
3330 (let ((default-directory tramp-test-temporary-file-directory
)
3331 (shell-file-name "/bin/sh")
3332 (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
3333 kill-buffer-query-functions
)
3337 (let ((process-environment
3338 (cons (concat envvar
"=foo") process-environment
)))
3344 this-shell-command-to-string
3345 (format "echo -n ${%s:?bla}" envvar
))))))
3348 ;; Set the empty value.
3349 (let ((process-environment
3350 (cons (concat envvar
"=") process-environment
)))
3356 this-shell-command-to-string
3357 (format "echo -n ${%s:?bla}" envvar
))))
3361 (regexp-quote envvar
)
3362 (funcall this-shell-command-to-string
"set")))))
3364 ;; We force a reconnect, in order to have a clean environment.
3365 (tramp-cleanup-connection
3366 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
3367 'keep-debug
'keep-password
)
3369 ;; Unset the variable.
3370 (let ((tramp-remote-process-environment
3371 (cons (concat envvar
"=foo")
3372 tramp-remote-process-environment
)))
3373 ;; Set the initial value, we want to unset below.
3378 this-shell-command-to-string
3379 (format "echo -n ${%s:?bla}" envvar
))))
3380 (let ((process-environment
3381 (cons envvar process-environment
)))
3382 ;; Variable is unset.
3387 this-shell-command-to-string
3388 (format "echo -n ${%s:?bla}" envvar
))))
3389 ;; Variable is unset.
3392 (regexp-quote envvar
)
3393 (funcall this-shell-command-to-string
"set")))))))))
3395 ;; This test is inspired by Bug#27009.
3396 (ert-deftest tramp-test30-environment-variables-and-port-numbers
()
3397 "Check that two connections with separate ports are different."
3398 (skip-unless (tramp--test-enabled))
3399 ;; We test it only for the mock-up connection; otherwise there might
3400 ;; be problems with the used ports.
3403 (eq tramp-syntax
'default
)
3405 "mock" (file-remote-p tramp-test-temporary-file-directory
'method
))))
3407 ;; We force a reconnect, in order to have a clean environment.
3408 (dolist (dir `(,tramp-test-temporary-file-directory
3409 "/mock:localhost#11111:" "/mock:localhost#22222:"))
3410 (tramp-cleanup-connection
3411 (tramp-dissect-file-name dir
) 'keep-debug
'keep-password
))
3414 (dolist (port '(11111 22222))
3415 (let* ((default-directory
3416 (format "/mock:localhost#%d:%s" port temporary-file-directory
))
3417 (shell-file-name "/bin/sh")
3418 (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
3419 ;; We cannot use `process-environment', because this
3420 ;; would be applied in `process-file'.
3421 (tramp-remote-process-environment
3423 (format "%s=%d" envvar port
)
3424 tramp-remote-process-environment
)))
3427 (number-to-string port
)
3428 (shell-command-to-string (format "echo -n $%s" envvar
))))))
3431 (dolist (dir '("/mock:localhost#11111:" "/mock:localhost#22222:"))
3432 (tramp-cleanup-connection (tramp-dissect-file-name dir
)))))
3434 ;; The functions were introduced in Emacs 26.1.
3435 (ert-deftest tramp-test31-explicit-shell-file-name
()
3436 "Check that connection-local `explicit-shell-file-name' is set."
3437 :tags
'(:expensive-test
)
3438 (skip-unless (tramp--test-enabled))
3439 (skip-unless (tramp--test-sh-p))
3440 ;; Since Emacs 26.1.
3441 (skip-unless (and (fboundp 'connection-local-set-profile-variables
)
3442 (fboundp 'connection-local-set-profiles
)))
3444 ;; `connection-local-set-profile-variables' and
3445 ;; `connection-local-set-profiles' exist since Emacs 26. We don't
3446 ;; want to see compiler warnings for older Emacsen.
3447 (let ((default-directory tramp-test-temporary-file-directory
)
3448 explicit-shell-file-name kill-buffer-query-functions
)
3451 ;; `shell-mode' would ruin our test, because it deletes all
3452 ;; buffer local variables.
3453 (put 'explicit-shell-file-name
'permanent-local t
)
3454 ;; Declare connection-local variable `explicit-shell-file-name'.
3456 (connection-local-set-profile-variables
3458 '((explicit-shell-file-name .
"/bin/sh")
3459 (explicit-sh-args .
("-i"))))
3460 (connection-local-set-profiles
3461 `(:application tramp
3462 :protocol
,(file-remote-p default-directory
'method
)
3463 :user
,(file-remote-p default-directory
'user
)
3464 :machine
,(file-remote-p default-directory
'host
))
3467 ;; Run interactive shell. Since the default directory is
3468 ;; remote, `explicit-shell-file-name' shall be set in order
3469 ;; to avoid a question.
3470 (with-current-buffer (get-buffer-create "*shell*")
3471 (ignore-errors (kill-process (current-buffer)))
3472 (should-not explicit-shell-file-name
)
3473 (call-interactively 'shell
)
3474 (should explicit-shell-file-name
)))
3476 (put 'explicit-shell-file-name
'permanent-local nil
)
3477 (kill-buffer "*shell*"))))
3479 (ert-deftest tramp-test32-vc-registered
()
3480 "Check `vc-registered'."
3481 :tags
'(:expensive-test
)
3482 (skip-unless (tramp--test-enabled))
3483 (skip-unless (tramp--test-sh-p))
3485 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3486 (let* ((default-directory tramp-test-temporary-file-directory
)
3487 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
3488 (tmp-name2 (expand-file-name "foo" tmp-name1
))
3489 (tramp-remote-process-environment tramp-remote-process-environment
)
3490 (vc-handled-backends
3491 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3493 ((tramp-find-executable
3494 v vc-git-program
(tramp-get-remote-path v
))
3496 ((tramp-find-executable
3497 v vc-hg-program
(tramp-get-remote-path v
))
3499 ((tramp-find-executable
3500 v vc-bzr-program
(tramp-get-remote-path v
))
3501 (setq tramp-remote-process-environment
3502 (cons (format "BZR_HOME=%s"
3503 (file-remote-p tmp-name1
'localname
))
3504 tramp-remote-process-environment
))
3505 ;; We must force a reconnect, in order to activate $BZR_HOME.
3506 (tramp-cleanup-connection
3507 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
3508 'keep-debug
'keep-password
)
3511 ;; Suppress nasty messages.
3512 (inhibit-message t
))
3513 (skip-unless vc-handled-backends
)
3514 (unless quoted
(tramp--test-message "%s" vc-handled-backends
))
3518 (make-directory tmp-name1
)
3519 (write-region "foo" nil tmp-name2
)
3520 (should (file-directory-p tmp-name1
))
3521 (should (file-exists-p tmp-name2
))
3522 (should-not (vc-registered tmp-name1
))
3523 (should-not (vc-registered tmp-name2
))
3525 (let ((default-directory tmp-name1
))
3526 ;; Create empty repository, and register the file.
3527 ;; Sometimes, creation of repository fails (bzr!); we
3528 ;; skip the test then.
3530 (vc-create-repo (car vc-handled-backends
))
3531 (error (skip-unless nil
)))
3532 ;; The structure of VC-FILESET is not documented. Let's
3533 ;; hope it won't change.
3536 (list (car vc-handled-backends
)
3537 (list (file-name-nondirectory tmp-name2
))))
3538 ;; `vc-register' has changed its arguments in Emacs 25.1.
3541 nil
(list (car vc-handled-backends
)
3542 (list (file-name-nondirectory tmp-name2
))))))
3543 ;; vc-git uses an own process sentinel, Tramp's sentinel
3544 ;; for flushing the cache isn't used.
3545 (dired-uncache (concat (file-remote-p default-directory
) "/"))
3546 (should (vc-registered (file-name-nondirectory tmp-name2
)))))
3549 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
3551 (ert-deftest tramp-test33-make-auto-save-file-name
()
3552 "Check `make-auto-save-file-name'."
3553 (skip-unless (tramp--test-enabled))
3555 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3556 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3557 (tmp-name2 (tramp--test-make-temp-name nil quoted
)))
3561 ;; Use default `auto-save-file-name-transforms' mechanism.
3562 (let (tramp-auto-save-directory)
3564 (setq buffer-file-name tmp-name1
)
3567 (make-auto-save-file-name)
3568 ;; This is taken from original `make-auto-save-file-name'.
3569 ;; We call `convert-standard-filename', because on
3570 ;; MS Windows the (local) colons must be replaced by
3571 ;; exclamation marks.
3572 (convert-standard-filename
3576 (subst-char-in-string
3577 ?
/ ?
! (replace-regexp-in-string "!" "!!" tmp-name1
)))
3578 temporary-file-directory
))))))
3581 (let (tramp-auto-save-directory auto-save-file-name-transforms
)
3583 (setq buffer-file-name tmp-name1
)
3586 (make-auto-save-file-name)
3588 (if quoted
'tramp-compat-file-name-quote
'identity
)
3590 (format "#%s#" (file-name-nondirectory tmp-name1
))
3591 tramp-test-temporary-file-directory
))))))
3593 ;; TODO: The following two cases don't work yet.
3595 ;; Use default `tramp-auto-save-directory' mechanism.
3596 (let ((tramp-auto-save-directory tmp-name2
))
3598 (setq buffer-file-name tmp-name1
)
3601 (make-auto-save-file-name)
3602 ;; This is taken from Tramp.
3606 (tramp-subst-strs-in-string
3613 (tramp-compat-file-name-unquote tmp-name1
)))
3615 (should (file-directory-p tmp-name2
))))
3617 ;; Relative file names shall work, too.
3618 (let ((tramp-auto-save-directory "."))
3620 (setq buffer-file-name tmp-name1
3621 default-directory tmp-name2
)
3624 (make-auto-save-file-name)
3625 ;; This is taken from Tramp.
3629 (tramp-subst-strs-in-string
3636 (tramp-compat-file-name-unquote tmp-name1
)))
3638 (should (file-directory-p tmp-name2
)))))
3642 (ignore-errors (delete-file tmp-name1
))
3643 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
3645 ;; The functions were introduced in Emacs 26.1.
3646 (ert-deftest tramp-test34-make-nearby-temp-file
()
3647 "Check `make-nearby-temp-file' and `temporary-file-directory'."
3648 (skip-unless (tramp--test-enabled))
3649 ;; Since Emacs 26.1.
3651 (and (fboundp 'make-nearby-temp-file
) (fboundp 'temporary-file-directory
)))
3653 ;; `make-nearby-temp-file' and `temporary-file-directory' exists
3654 ;; since Emacs 26. We don't want to see compiler warnings for older
3656 (let ((default-directory tramp-test-temporary-file-directory
)
3658 ;; The remote host shall know a temporary file directory.
3659 (should (stringp (with-no-warnings (temporary-file-directory))))
3662 (file-remote-p default-directory
)
3663 (file-remote-p (with-no-warnings (temporary-file-directory)))))
3665 ;; The temporary file shall be located on the remote host.
3666 (setq tmp-file
(with-no-warnings (make-nearby-temp-file "tramp-test")))
3667 (should (file-exists-p tmp-file
))
3668 (should (file-regular-p tmp-file
))
3671 (file-remote-p default-directory
)
3672 (file-remote-p tmp-file
)))
3673 (delete-file tmp-file
)
3674 (should-not (file-exists-p tmp-file
))
3676 (setq tmp-file
(with-no-warnings (make-nearby-temp-file "tramp-test" 'dir
)))
3677 (should (file-exists-p tmp-file
))
3678 (should (file-directory-p tmp-file
))
3679 (delete-directory tmp-file
)
3680 (should-not (file-exists-p tmp-file
))))
3682 (defun tramp--test-emacs26-p ()
3683 "Check for Emacs version >= 26.1.
3684 Some semantics has been changed for there, w/o new functions or
3685 variables, so we check function Emacs version directly."
3686 (>= emacs-major-version
26))
3688 (defun tramp--test-adb-p ()
3689 "Check, whether the remote host runs Android.
3690 This requires restrictions of file name syntax."
3691 (tramp-adb-file-name-p tramp-test-temporary-file-directory
))
3693 (defun tramp--test-docker-p ()
3694 "Check, whether the docker method is used.
3695 This does not support some special file names."
3697 "docker" (file-remote-p tramp-test-temporary-file-directory
'method
)))
3699 (defun tramp--test-ftp-p ()
3700 "Check, whether an FTP-like method is used.
3701 This does not support globbing characters in file names (yet)."
3702 ;; Globbing characters are ??, ?* and ?\[.
3704 "ftp$" (file-remote-p tramp-test-temporary-file-directory
'method
)))
3706 (defun tramp--test-gvfs-p (&optional method
)
3707 "Check, whether the remote host runs a GVFS based method.
3708 This requires restrictions of file name syntax."
3709 (or (member method tramp-gvfs-methods
)
3710 (tramp-gvfs-file-name-p tramp-test-temporary-file-directory
)))
3712 (defun tramp--test-hpux-p ()
3713 "Check, whether the remote host runs HP-UX.
3714 Several special characters do not work properly there."
3715 ;; We must refill the cache. `file-truename' does it.
3716 (with-parsed-tramp-file-name
3717 (file-truename tramp-test-temporary-file-directory
) nil
3718 (string-match "^HP-UX" (tramp-get-connection-property v
"uname" ""))))
3720 (defun tramp--test-rsync-p ()
3721 "Check, whether the rsync method is used.
3722 This does not support special file names."
3724 "rsync" (file-remote-p tramp-test-temporary-file-directory
'method
)))
3726 (defun tramp--test-sh-p ()
3727 "Check, whether the remote host runs a based method from tramp-sh.el."
3729 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
3730 'tramp-sh-file-name-handler
))
3732 (defun tramp--test-windows-nt-and-batch ()
3733 "Check, whether the locale host runs MS Windows in batch mode.
3734 This does not support special characters."
3735 (and (eq system-type
'windows-nt
) noninteractive
))
3737 (defun tramp--test-windows-nt-and-pscp-psftp-p ()
3738 "Check, whether the locale host runs MS Windows, and ps{cp,ftp} is used.
3739 This does not support utf8 based file transfer."
3740 (and (eq system-type
'windows-nt
)
3742 (regexp-opt '("pscp" "psftp"))
3743 (file-remote-p tramp-test-temporary-file-directory
'method
))))
3745 (defun tramp--test-windows-nt-or-smb-p ()
3746 "Check, whether the locale or remote host runs MS Windows.
3747 This requires restrictions of file name syntax."
3748 (or (eq system-type
'windows-nt
)
3749 (tramp-smb-file-name-p tramp-test-temporary-file-directory
)))
3751 (defun tramp--test-check-files (&rest files
)
3752 "Run a simple but comprehensive test over every file in FILES."
3753 ;; TODO: The quoted case does not work.
3754 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
3756 ;; We must use `file-truename' for the temporary directory,
3757 ;; because it could be located on a symlinked directory. This
3758 ;; would let the test fail.
3759 (let* ((tramp-test-temporary-file-directory
3760 (file-truename tramp-test-temporary-file-directory
))
3761 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
3762 (tmp-name2 (tramp--test-make-temp-name 'local quoted
))
3763 (files (delq nil files
))
3764 (process-environment process-environment
))
3767 (make-directory tmp-name1
)
3768 (make-directory tmp-name2
)
3771 (let* ((file1 (expand-file-name elt tmp-name1
))
3772 (file2 (expand-file-name elt tmp-name2
))
3773 (file3 (expand-file-name (concat elt
"foo") tmp-name1
)))
3774 (write-region elt nil file1
)
3775 (should (file-exists-p file1
))
3777 ;; Check file contents.
3779 (insert-file-contents file1
)
3780 (should (string-equal (buffer-string) elt
)))
3782 ;; Copy file both directions.
3783 (copy-file file1
(file-name-as-directory tmp-name2
))
3784 (should (file-exists-p file2
))
3786 (should-not (file-exists-p file1
))
3787 (copy-file file2
(file-name-as-directory tmp-name1
))
3788 (should (file-exists-p file1
))
3790 (tramp--test-ignore-make-symbolic-link-error
3791 (make-symbolic-link file1 file3
)
3792 (should (file-symlink-p file3
))
3795 (expand-file-name file1
) (file-truename file3
)))
3799 (if quoted
'tramp-compat-file-name-quote
'identity
)
3800 (car (file-attributes file3
)))
3801 (file-remote-p (file-truename file1
) 'localname
)))
3802 ;; Check file contents.
3804 (insert-file-contents file3
)
3805 (should (string-equal (buffer-string) elt
)))
3806 (delete-file file3
))))
3808 ;; Check file names.
3809 (should (equal (directory-files
3810 tmp-name1 nil directory-files-no-dot-files-regexp
)
3811 (sort (copy-sequence files
) 'string-lessp
)))
3812 (should (equal (directory-files
3813 tmp-name2 nil directory-files-no-dot-files-regexp
)
3814 (sort (copy-sequence files
) 'string-lessp
)))
3816 ;; `substitute-in-file-name' could return different
3817 ;; values. For `adb', there could be strange file
3818 ;; permissions preventing overwriting a file. We don't
3819 ;; care in this testcase.
3822 (substitute-in-file-name (expand-file-name elt tmp-name1
)))
3824 (substitute-in-file-name
3825 (expand-file-name elt tmp-name2
))))
3826 (ignore-errors (write-region elt nil file1
))
3827 (should (file-exists-p file1
))
3828 (ignore-errors (write-region elt nil file2 nil
'nomessage
))
3829 (should (file-exists-p file2
))))
3831 (should (equal (directory-files
3832 tmp-name1 nil directory-files-no-dot-files-regexp
)
3834 tmp-name2 nil directory-files-no-dot-files-regexp
)))
3836 ;; Check directory creation. We use a subdirectory "foo"
3837 ;; in order to avoid conflicts with previous file name tests.
3839 (let* ((elt1 (concat elt
"foo"))
3840 (file1 (expand-file-name (concat "foo/" elt
) tmp-name1
))
3841 (file2 (expand-file-name elt file1
))
3842 (file3 (expand-file-name elt1 file1
)))
3843 (make-directory file1
'parents
)
3844 (should (file-directory-p file1
))
3845 (write-region elt nil file2
)
3846 (should (file-exists-p file2
))
3850 file1 nil directory-files-no-dot-files-regexp
)
3854 (caar (directory-files-and-attributes
3855 file1 nil directory-files-no-dot-files-regexp
))
3858 ;; Check symlink in `directory-files-and-attributes'.
3859 ;; It does not work in the "smb" case, only relative
3860 ;; symlinks to existing files are shown there.
3861 (tramp--test-ignore-make-symbolic-link-error
3863 (tramp-smb-file-name-p tramp-test-temporary-file-directory
)
3864 (make-symbolic-link file2 file3
)
3865 (should (file-symlink-p file3
))
3868 (caar (directory-files-and-attributes
3869 file1 nil
(regexp-quote elt1
)))
3874 (if quoted
'tramp-compat-file-name-quote
'identity
)
3875 (cadr (car (directory-files-and-attributes
3876 file1 nil
(regexp-quote elt1
)))))
3877 (file-remote-p (file-truename file2
) 'localname
)))
3879 (should-not (file-exists-p file3
))))
3882 (should-not (file-exists-p file2
))
3883 (delete-directory file1
)
3884 (should-not (file-exists-p file1
))))
3886 ;; Check, that environment variables are set correctly.
3887 (when (and tramp--test-expensive-test
(tramp--test-sh-p))
3889 (let ((envvar (concat "VAR_" (upcase (md5 elt
))))
3890 (default-directory tramp-test-temporary-file-directory
)
3891 (process-environment process-environment
))
3893 ;; The value of PS1 could confuse Tramp's detection
3894 ;; of process output. So we unset it temporarily.
3897 (should (zerop (process-file "env" nil t nil
)))
3898 (goto-char (point-min))
3903 (regexp-quote envvar
)
3904 (regexp-quote (getenv envvar
))))))))))
3907 (ignore-errors (delete-directory tmp-name1
'recursive
))
3908 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
3910 (defun tramp--test-special-characters ()
3911 "Perform the test in `tramp-test35-special-characters*'."
3912 ;; Newlines, slashes and backslashes in file names are not
3913 ;; supported. So we don't test. And we don't test the tab
3914 ;; character on Windows or Cygwin, because the backslash is
3915 ;; interpreted as a path separator, preventing "\t" from being
3916 ;; expanded to <TAB>.
3917 (tramp--test-check-files
3918 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3920 (if (or (tramp--test-adb-p)
3921 (tramp--test-docker-p)
3922 (eq system-type
'cygwin
))
3929 (unless (or (tramp--test-ftp-p)
3930 (tramp--test-gvfs-p)
3931 (tramp--test-windows-nt-or-smb-p))
3933 (unless (or (tramp--test-ftp-p)
3934 (tramp--test-gvfs-p)
3935 (tramp--test-windows-nt-or-smb-p))
3937 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3941 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3944 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3947 (unless (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3950 (unless (or (tramp--test-ftp-p) (tramp--test-gvfs-p)) "[foo]bar[baz]")
3953 ;; These tests are inspired by Bug#17238.
3954 (ert-deftest tramp-test35-special-characters
()
3955 "Check special characters in file names."
3956 (skip-unless (tramp--test-enabled))
3957 (skip-unless (not (tramp--test-rsync-p)))
3958 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3960 (tramp--test-special-characters))
3962 (ert-deftest tramp-test35-special-characters-with-stat
()
3963 "Check special characters in file names.
3964 Use the `stat' command."
3965 :tags
'(:expensive-test
)
3966 (skip-unless (tramp--test-enabled))
3967 (skip-unless (tramp--test-sh-p))
3968 (skip-unless (not (tramp--test-rsync-p)))
3969 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3970 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3971 (skip-unless (tramp-get-remote-stat v
)))
3973 (let ((tramp-connection-properties
3975 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3977 tramp-connection-properties
)))
3978 (tramp--test-special-characters)))
3980 (ert-deftest tramp-test35-special-characters-with-perl
()
3981 "Check special characters in file names.
3982 Use the `perl' command."
3983 :tags
'(:expensive-test
)
3984 (skip-unless (tramp--test-enabled))
3985 (skip-unless (tramp--test-sh-p))
3986 (skip-unless (not (tramp--test-rsync-p)))
3987 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3988 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3989 (skip-unless (tramp-get-remote-perl v
)))
3991 (let ((tramp-connection-properties
3993 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3995 ;; See `tramp-sh-handle-file-truename'.
3996 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3998 tramp-connection-properties
)))
3999 (tramp--test-special-characters)))
4001 (ert-deftest tramp-test35-special-characters-with-ls
()
4002 "Check special characters in file names.
4003 Use the `ls' command."
4004 :tags
'(:expensive-test
)
4005 (skip-unless (tramp--test-enabled))
4006 (skip-unless (tramp--test-sh-p))
4007 (skip-unless (not (tramp--test-rsync-p)))
4008 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4009 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4011 (let ((tramp-connection-properties
4013 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4015 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4017 ;; See `tramp-sh-handle-file-truename'.
4018 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4020 tramp-connection-properties
)))
4021 (tramp--test-special-characters)))
4023 (defun tramp--test-utf8 ()
4024 "Perform the test in `tramp-test36-utf8*'."
4025 (let* ((utf8 (if (and (eq system-type
'darwin
)
4026 (memq 'utf-8-hfs
(coding-system-list)))
4028 (coding-system-for-read utf8
)
4029 (coding-system-for-write utf8
)
4030 (file-name-coding-system
4031 (coding-system-change-eol-conversion utf8
'unix
)))
4032 (tramp--test-check-files
4033 (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ")
4034 (unless (tramp--test-hpux-p)
4035 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
4037 "Автостопом по гала́ктике")))
4039 (ert-deftest tramp-test36-utf8
()
4040 "Check UTF8 encoding in file names and file contents."
4041 (skip-unless (tramp--test-enabled))
4042 (skip-unless (not (tramp--test-docker-p)))
4043 (skip-unless (not (tramp--test-rsync-p)))
4044 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4045 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4049 (ert-deftest tramp-test36-utf8-with-stat
()
4050 "Check UTF8 encoding in file names and file contents.
4051 Use the `stat' command."
4052 :tags
'(:expensive-test
)
4053 (skip-unless (tramp--test-enabled))
4054 (skip-unless (tramp--test-sh-p))
4055 (skip-unless (not (tramp--test-docker-p)))
4056 (skip-unless (not (tramp--test-rsync-p)))
4057 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4058 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4059 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4060 (skip-unless (tramp-get-remote-stat v
)))
4062 (let ((tramp-connection-properties
4064 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4066 tramp-connection-properties
)))
4067 (tramp--test-utf8)))
4069 (ert-deftest tramp-test36-utf8-with-perl
()
4070 "Check UTF8 encoding in file names and file contents.
4071 Use the `perl' command."
4072 :tags
'(:expensive-test
)
4073 (skip-unless (tramp--test-enabled))
4074 (skip-unless (tramp--test-sh-p))
4075 (skip-unless (not (tramp--test-docker-p)))
4076 (skip-unless (not (tramp--test-rsync-p)))
4077 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4078 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4079 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4080 (skip-unless (tramp-get-remote-perl v
)))
4082 (let ((tramp-connection-properties
4084 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4086 ;; See `tramp-sh-handle-file-truename'.
4087 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4089 tramp-connection-properties
)))
4090 (tramp--test-utf8)))
4092 (ert-deftest tramp-test36-utf8-with-ls
()
4093 "Check UTF8 encoding in file names and file contents.
4094 Use the `ls' command."
4095 :tags
'(:expensive-test
)
4096 (skip-unless (tramp--test-enabled))
4097 (skip-unless (tramp--test-sh-p))
4098 (skip-unless (not (tramp--test-docker-p)))
4099 (skip-unless (not (tramp--test-rsync-p)))
4100 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4101 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4103 (let ((tramp-connection-properties
4105 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4107 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4109 ;; See `tramp-sh-handle-file-truename'.
4110 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4112 tramp-connection-properties
)))
4113 (tramp--test-utf8)))
4115 (ert-deftest tramp-test37-file-system-info
()
4116 "Check that `file-system-info' returns proper values."
4117 (skip-unless (tramp--test-enabled))
4118 ;; Since Emacs 27.1.
4119 (skip-unless (fboundp 'file-system-info
))
4121 ;; `file-system-info' exists since Emacs 27. We don't
4122 ;; want to see compiler warnings for older Emacsen.
4123 (let ((fsi (with-no-warnings
4124 (file-system-info tramp-test-temporary-file-directory
))))
4126 (should (and (consp fsi
)
4128 (numberp (nth 0 fsi
))
4129 (numberp (nth 1 fsi
))
4130 (numberp (nth 2 fsi
))))))
4132 (defun tramp--test-timeout-handler ()
4134 (ert-fail (format "`%s' timed out" (ert-test-name (ert-running-test)))))
4136 ;; This test is inspired by Bug#16928.
4137 (ert-deftest tramp-test38-asynchronous-requests
()
4138 "Check parallel asynchronous requests.
4139 Such requests could arrive from timers, process filters and
4140 process sentinels. They shall not disturb each other."
4141 :tags
'(:expensive-test
)
4142 (skip-unless (tramp--test-enabled))
4143 (skip-unless (tramp--test-sh-p))
4145 ;; This test could be blocked on hydra. So we set a timeout of 300
4146 ;; seconds, and we send a SIGUSR1 signal after 300 seconds.
4147 (with-timeout (300 (tramp--test-timeout-handler))
4148 (define-key special-event-map
[sigusr1] 'tramp--test-timeout-handler)
4149 (tramp--test-instrument-test-case (if (getenv "EMACS_HYDRA_CI") 10 0)
4150 (let* (;; For the watchdog.
4151 (default-directory (expand-file-name temporary-file-directory))
4154 "*watchdog*" nil shell-file-name shell-command-switch
4155 (format "sleep 300; kill -USR1 %d" (emacs-pid))))
4156 (tmp-name (tramp--test-make-temp-name))
4157 (default-directory tmp-name)
4158 ;; Do not cache Tramp properties.
4159 (remote-file-name-inhibit-cache t)
4160 (process-file-side-effects t)
4161 ;; Suppress nasty messages.
4163 ;; Do not run delayed timers.
4164 (timer-max-repeats 0)
4165 ;; Number of asynchronous processes for test.
4167 ;; On hydra, timings are bad.
4170 ((getenv "EMACS_HYDRA_CI") 10)
4172 ;; We must distinguish due to performance reasons.
4175 ((string-equal "mock" (file-remote-p tmp-name 'method))
4177 (t 'file-attributes)))
4178 timer buffers kill-buffer-query-functions)
4182 (make-directory tmp-name)
4184 ;; Setup a timer in order to raise an ordinary command
4185 ;; again and again. `vc-registered' is well suited,
4186 ;; because there are many checks.
4193 (let ((time (float-time))
4194 (default-directory tmp-name)
4196 (buffer-name (nth (random (length buffers)) buffers))))
4197 (tramp--test-message
4198 "Start timer %s %s" file (current-time-string))
4199 (funcall timer-operation file)
4200 ;; Adjust timer if it takes too much time.
4201 (when (> (- (float-time) time) timer-repeat)
4202 (setq timer-repeat (* 1.5 timer-repeat))
4203 (setf (timer--repeat-delay timer) timer-repeat)
4204 (tramp--test-message "Increase timer %s" timer-repeat))
4205 (tramp--test-message
4206 "Stop timer %s %s" file (current-time-string)))))))
4208 ;; Create temporary buffers. The number of buffers
4209 ;; corresponds to the number of processes; it could be
4210 ;; increased in order to make pressure on Tramp.
4211 (dotimes (_ number-proc)
4212 (setq buffers (cons (generate-new-buffer "foo") buffers)))
4214 ;; Open asynchronous processes. Set process filter and sentinel.
4215 (dolist (buf buffers)
4217 (sit-for 0.01 'nodisp)
4219 (start-file-process-shell-command
4220 (buffer-name buf) buf
4222 "(read line && echo $line >$line);"
4223 "(read line && cat $line);"
4224 "(read line && rm $line)")))
4225 (file (expand-file-name (buffer-name buf))))
4226 ;; Remember the file name. Add counter.
4227 (process-put proc 'foo file)
4228 (process-put proc 'bar 0)
4229 ;; Add process filter.
4232 (lambda (proc string)
4233 (with-current-buffer (process-buffer proc)
4235 (unless (zerop (length string))
4236 (should (file-attributes (process-get proc 'foo))))))
4237 ;; Add process sentinel.
4238 (set-process-sentinel
4240 (lambda (proc _state)
4241 (should-not (file-attributes (process-get proc 'foo)))))))
4243 ;; Send a string. Use a random order of the buffers. Mix
4244 ;; with regular operation.
4245 (let ((buffers (copy-sequence buffers)))
4248 (sit-for 0.01 'nodisp)
4249 (let* ((buf (nth (random (length buffers)) buffers))
4250 (proc (get-buffer-process buf))
4251 (file (process-get proc 'foo))
4252 (count (process-get proc 'bar)))
4253 (tramp--test-message
4254 "Start action %d %s %s" count buf (current-time-string))
4255 ;; Regular operation prior process action.
4257 (should-not (file-attributes file))
4258 (should (file-attributes file)))
4259 ;; Send string to process.
4260 (process-send-string proc (format "%s\n" (buffer-name buf)))
4261 (accept-process-output proc 0.1 nil 0)
4262 ;; Give the watchdog a chance.
4263 (read-event nil nil 0.01)
4264 ;; Regular operation post process action.
4266 (should-not (file-attributes file))
4267 (should (file-attributes file)))
4268 (tramp--test-message
4269 "Stop action %d %s %s" count buf (current-time-string))
4270 (process-put proc 'bar (1+ count))
4271 (unless (process-live-p proc)
4272 (setq buffers (delq buf buffers))))))
4274 ;; Checks. All process output shall exists in the
4275 ;; respective buffers. All created files shall be
4277 (tramp--test-message "Check %s" (current-time-string))
4278 (dolist (buf buffers)
4279 (with-current-buffer buf
4280 (should (string-equal (format "%s\n" buf) (buffer-string)))))
4283 tmp-name nil directory-files-no-dot-files-regexp)))
4286 (define-key special-event-map [sigusr1] 'ignore
)
4287 (ignore-errors (quit-process watchdog
))
4288 (dolist (buf buffers
)
4289 (ignore-errors (delete-process (get-buffer-process buf
)))
4290 (ignore-errors (kill-buffer buf
)))
4291 (ignore-errors (cancel-timer timer
))
4292 (ignore-errors (delete-directory tmp-name
'recursive
)))))))
4294 (ert-deftest tramp-test39-recursive-load
()
4295 "Check that Tramp does not fail due to recursive load."
4296 (skip-unless (tramp--test-enabled))
4298 (let ((default-directory (expand-file-name temporary-file-directory
)))
4302 "(expand-file-name %S)" tramp-test-temporary-file-directory
)
4304 "(let ((default-directory %S)) (expand-file-name %S))"
4305 tramp-test-temporary-file-directory
4306 temporary-file-directory
)))
4310 (shell-command-to-string
4312 "%s -batch -Q -L %s --eval %s"
4313 (expand-file-name invocation-name invocation-directory
)
4314 (mapconcat 'shell-quote-argument load-path
" -L ")
4315 (shell-quote-argument code
))))))))
4317 (ert-deftest tramp-test40-remote-load-path
()
4318 "Check that Tramp autoloads its packages with remote `load-path'."
4319 ;; `tramp-cleanup-all-connections' is autoloaded from tramp-cmds.el.
4320 ;; It shall still work, when a remote file name is in the
4322 (let ((default-directory (expand-file-name temporary-file-directory
))
4324 "(let ((force-load-messages t) \
4325 (load-path (cons \"/foo:bar:\" load-path))) \
4326 (tramp-cleanup-all-connections))"))
4332 "tramp-cmds" (file-name-directory (locate-library "tramp"))))
4333 (shell-command-to-string
4335 "%s -batch -Q -L %s -l tramp-sh --eval %s"
4336 (expand-file-name invocation-name invocation-directory
)
4337 (mapconcat 'shell-quote-argument load-path
" -L ")
4338 (shell-quote-argument code
)))))))
4340 (ert-deftest tramp-test41-unload
()
4341 "Check that Tramp and its subpackages unload completely.
4342 Since it unloads Tramp, it shall be the last test to run."
4343 :tags
'(:expensive-test
)
4344 (skip-unless noninteractive
)
4346 (when (featurep 'tramp
)
4347 (unload-feature 'tramp
'force
)
4348 ;; No Tramp feature must be left.
4349 (should-not (featurep 'tramp
))
4350 (should-not (all-completions "tramp" (delq 'tramp-tests features
)))
4351 ;; `file-name-handler-alist' must be clean.
4352 (should-not (all-completions "tramp" (mapcar 'cdr file-name-handler-alist
)))
4353 ;; There shouldn't be left a bound symbol, except buffer-local
4354 ;; variables, and autoload functions. We do not regard our test
4355 ;; symbols, and the Tramp unload hooks.
4358 (and (or (and (boundp x
) (null (local-variable-if-set-p x
)))
4359 (and (functionp x
) (null (autoloadp (symbol-function x
)))))
4360 (string-match "^tramp" (symbol-name x
))
4361 (not (string-match "^tramp--?test" (symbol-name x
)))
4362 (not (string-match "unload-hook$" (symbol-name x
)))
4363 (ert-fail (format "`%s' still bound" x
)))))
4364 ;; The defstruct `tramp-file-name' and all its internal functions
4366 (should-not (cl--find-class 'tramp-file-name
))
4370 (string-match "tramp-file-name" (symbol-name x
))
4371 (ert-fail (format "Structure function `%s' still exists" x
)))))
4372 ;; There shouldn't be left a hook function containing a Tramp
4373 ;; function. We do not regard the Tramp unload hooks.
4377 (string-match "-\\(hook\\|function\\)s?$" (symbol-name x
))
4378 (not (string-match "unload-hook$" (symbol-name x
)))
4379 (consp (symbol-value x
))
4380 (ignore-errors (all-completions "tramp" (symbol-value x
)))
4381 (ert-fail (format "Hook `%s' still contains Tramp function" x
)))))))
4385 ;; * dired-compress-file
4388 ;; * file-name-case-insensitive-p
4389 ;; * file-selinux-context
4390 ;; * find-backup-file-name
4392 ;; * set-file-selinux-context
4394 ;; * Work on skipped tests. Make a comment, when it is impossible.
4395 ;; * Fix `tramp-test05-expand-file-name-relative' in `expand-file-name'.
4396 ;; * Fix `tramp-test06-directory-file-name' for `ftp'.
4397 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
4398 ;; * Fix `tramp-test28-interrupt-process', timeout doesn't work reliably.
4399 ;; * Fix Bug#16928 in `tramp-test38-asynchronous-requests'.
4401 (defun tramp-test-all (&optional interactive
)
4402 "Run all tests for \\[tramp]."
4405 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
) "^tramp"))
4407 (provide 'tramp-tests
)
4408 ;;; tramp-tests.el ends here