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 `http://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
)
57 ;; There is no default value on w32 systems, which could work out of the box.
58 (defconst tramp-test-temporary-file-directory
60 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
61 ((eq system-type
'windows-nt
) null-device
)
65 (tramp-login-program "sh")
66 (tramp-login-args (("-i")))
67 (tramp-remote-shell "/bin/sh")
68 (tramp-remote-shell-args ("-c"))
69 (tramp-connection-timeout 10)))
71 'tramp-default-host-alist
72 `("\\`mock\\'" nil
,(system-name)))
73 (format "/mock::%s" temporary-file-directory
)))
74 "Temporary directory for Tramp tests.")
76 (setq password-cache-expiry nil
78 tramp-cache-read-persistent-data t
;; For auth-sources.
79 tramp-copy-size-limit nil
80 tramp-message-show-message nil
81 tramp-persistency-file-name nil
)
83 ;; This shall happen on hydra only.
84 (when (getenv "NIX_STORE")
85 (add-to-list 'tramp-remote-path
'tramp-own-remote-path
))
87 (defvar tramp--test-expensive-test
89 (string-equal (getenv "SELECTOR") "(quote (not (tag :expensive-test)))"))
90 "Whether expensive tests are run.")
92 (defvar tramp--test-enabled-checked nil
93 "Cached result of `tramp--test-enabled'.
94 If the function did run, the value is a cons cell, the `cdr'
97 (defun tramp--test-enabled ()
98 "Whether remote file access is enabled."
99 (unless (consp tramp--test-enabled-checked
)
101 tramp--test-enabled-checked
105 (file-remote-p tramp-test-temporary-file-directory
)
106 (file-directory-p tramp-test-temporary-file-directory
)
107 (file-writable-p tramp-test-temporary-file-directory
))))))
109 (when (cdr tramp--test-enabled-checked
)
110 ;; Cleanup connection.
112 (tramp-cleanup-connection
113 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
114 nil
'keep-password
)))
117 (cdr tramp--test-enabled-checked
))
119 (defun tramp--test-make-temp-name (&optional local quoted
)
120 "Create a temporary file name for test.
121 If LOCAL is non-nil, a local file is created.
122 If QUOTED is non-nil, the local part of the file is quoted."
124 (if quoted
'tramp-compat-file-name-quote
'identity
)
126 (make-temp-name "tramp-test")
127 (if local temporary-file-directory tramp-test-temporary-file-directory
))))
129 (defmacro tramp--instrument-test-case
(verbose &rest body
)
130 "Run BODY with `tramp-verbose' equal VERBOSE.
131 Print the the content of the Tramp debug buffer, if BODY does not
132 eval properly in `should' or `should-not'. `should-error' is not
133 handled properly. BODY shall not contain a timeout."
134 (declare (indent 1) (debug (natnump body
)))
135 `(let ((tramp-verbose ,verbose
)
136 (tramp-debug-on-error t
)
137 (debug-ignored-errors
138 (cons "^make-symbolic-link not supported$" debug-ignored-errors
)))
141 (when (> tramp-verbose
3)
142 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
143 (with-current-buffer (tramp-get-connection-buffer v
)
144 (message "%s" (buffer-string)))
145 (with-current-buffer (tramp-get-debug-buffer v
)
146 (message "%s" (buffer-string))))))))
148 (ert-deftest tramp-test00-availability
()
149 "Test availability of Tramp functions."
150 :expected-result
(if (tramp--test-enabled) :passed
:failed
)
151 (message "Remote directory: `%s'" tramp-test-temporary-file-directory
)
152 (should (ignore-errors
154 (file-remote-p tramp-test-temporary-file-directory
)
155 (file-directory-p tramp-test-temporary-file-directory
)
156 (file-writable-p tramp-test-temporary-file-directory
)))))
158 (ert-deftest tramp-test01-file-name-syntax
()
159 "Check remote file name syntax."
161 (should (tramp-tramp-file-p "/method::"))
162 (should (tramp-tramp-file-p "/method:host:"))
163 (should (tramp-tramp-file-p "/method:user@:"))
164 (should (tramp-tramp-file-p "/method:user@host:"))
165 (should (tramp-tramp-file-p "/method:user@email@host:"))
168 (should (tramp-tramp-file-p "/method:host#1234:"))
169 (should (tramp-tramp-file-p "/method:user@host#1234:"))
171 ;; Using an IPv4 address.
172 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
173 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
175 ;; Using an IPv6 address.
176 (should (tramp-tramp-file-p "/method:[::1]:"))
177 (should (tramp-tramp-file-p "/method:user@[::1]:"))
179 ;; Local file name part.
180 (should (tramp-tramp-file-p "/method:::"))
181 (should (tramp-tramp-file-p "/method::/:"))
182 (should (tramp-tramp-file-p "/method::/path/to/file"))
183 (should (tramp-tramp-file-p "/method::/:/path/to/file"))
184 (should (tramp-tramp-file-p "/method::file"))
185 (should (tramp-tramp-file-p "/method::/:file"))
188 (should (tramp-tramp-file-p "/method1:|method2::"))
189 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
190 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
191 (should (tramp-tramp-file-p
192 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
195 (should-not (tramp-tramp-file-p nil
))
196 (should-not (tramp-tramp-file-p 'symbol
))
198 (should-not (tramp-tramp-file-p "/host:"))
199 (should-not (tramp-tramp-file-p "/user@host:"))
200 (should-not (tramp-tramp-file-p "/1.2.3.4:"))
201 (should-not (tramp-tramp-file-p "/[]:"))
202 (should-not (tramp-tramp-file-p "/[::1]:"))
203 (should-not (tramp-tramp-file-p "/host:/:"))
204 (should-not (tramp-tramp-file-p "/host1|host2:"))
205 (should-not (tramp-tramp-file-p "/user1@host1|user2@host2:"))
206 ;; Quote with "/:" suppresses file name handlers.
207 (should-not (tramp-tramp-file-p "/::"))
208 (should-not (tramp-tramp-file-p "/:@:"))
209 (should-not (tramp-tramp-file-p "/:[]:"))
210 ;; Methods shall be at least two characters on MS Windows, except
211 ;; the default method.
212 (let ((system-type 'windows-nt
))
213 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
214 (should-not (tramp-tramp-file-p "/c::/path/to/file"))
215 (should (tramp-tramp-file-p "/-::/path/to/file")))
216 (let ((system-type 'gnu
/linux
))
217 (should (tramp-tramp-file-p "/-:h:/path/to/file"))
218 (should (tramp-tramp-file-p "/m::/path/to/file"))))
220 (ert-deftest tramp-test01-file-name-syntax-simplified
()
221 "Check simplified file name syntax."
222 :tags
'(:expensive-test
)
223 (let ((syntax tramp-syntax
))
226 (tramp-change-syntax 'simplified
)
228 (should (tramp-tramp-file-p "/host:"))
229 (should (tramp-tramp-file-p "/user@:"))
230 (should (tramp-tramp-file-p "/user@host:"))
231 (should (tramp-tramp-file-p "/user@email@host:"))
234 (should (tramp-tramp-file-p "/host#1234:"))
235 (should (tramp-tramp-file-p "/user@host#1234:"))
237 ;; Using an IPv4 address.
238 (should (tramp-tramp-file-p "/1.2.3.4:"))
239 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
241 ;; Using an IPv6 address.
242 (should (tramp-tramp-file-p "/[::1]:"))
243 (should (tramp-tramp-file-p "/user@[::1]:"))
245 ;; Local file name part.
246 (should (tramp-tramp-file-p "/host::"))
247 (should (tramp-tramp-file-p "/host:/:"))
248 (should (tramp-tramp-file-p "/host:/path/to/file"))
249 (should (tramp-tramp-file-p "/host:/:/path/to/file"))
250 (should (tramp-tramp-file-p "/host:file"))
251 (should (tramp-tramp-file-p "/host:/:file"))
254 (should (tramp-tramp-file-p "/host1|host2:"))
255 (should (tramp-tramp-file-p "/user1@host1|user2@host2:"))
256 (should (tramp-tramp-file-p "/user1@host1|user2@host2|user3@host3:"))
259 (should-not (tramp-tramp-file-p nil
))
260 (should-not (tramp-tramp-file-p 'symbol
))
261 ;; Quote with "/:" suppresses file name handlers.
262 (should-not (tramp-tramp-file-p "/::"))
263 (should-not (tramp-tramp-file-p "/:@:"))
264 (should-not (tramp-tramp-file-p "/:[]:")))
267 (tramp-change-syntax syntax
))))
269 (ert-deftest tramp-test01-file-name-syntax-separate
()
270 "Check separate file name syntax."
271 :tags
'(:expensive-test
)
272 (let ((syntax tramp-syntax
))
275 (tramp-change-syntax 'separate
)
277 (should (tramp-tramp-file-p "/[method/]"))
278 (should (tramp-tramp-file-p "/[method/host]"))
279 (should (tramp-tramp-file-p "/[method/user@]"))
280 (should (tramp-tramp-file-p "/[method/user@host]"))
281 (should (tramp-tramp-file-p "/[method/user@email@host]"))
284 (should (tramp-tramp-file-p "/[method/host#1234]"))
285 (should (tramp-tramp-file-p "/[method/user@host#1234]"))
287 ;; Using an IPv4 address.
288 (should (tramp-tramp-file-p "/[method/1.2.3.4]"))
289 (should (tramp-tramp-file-p "/[method/user@1.2.3.4]"))
291 ;; Using an IPv6 address.
292 (should (tramp-tramp-file-p "/[method/::1]"))
293 (should (tramp-tramp-file-p "/[method/user@::1]"))
295 ;; Local file name part.
296 (should (tramp-tramp-file-p "/[method/]"))
297 (should (tramp-tramp-file-p "/[method/]/:"))
298 (should (tramp-tramp-file-p "/[method/]/path/to/file"))
299 (should (tramp-tramp-file-p "/[method/]/:/path/to/file"))
300 (should (tramp-tramp-file-p "/[method/]file"))
301 (should (tramp-tramp-file-p "/[method/]/:file"))
304 (should (tramp-tramp-file-p "/[method1/|method2/]"))
305 (should (tramp-tramp-file-p "/[method1/host1|method2/host2]"))
308 "/[method1/user1@host1|method2/user2@host2]"))
311 "/[method1/user1@host1|method2/user2@host2|method3/user3@host3]"))
314 (should-not (tramp-tramp-file-p nil
))
315 (should-not (tramp-tramp-file-p 'symbol
))
317 (should-not (tramp-tramp-file-p "/host:"))
318 (should-not (tramp-tramp-file-p "/user@host:"))
319 (should-not (tramp-tramp-file-p "/1.2.3.4:"))
320 (should-not (tramp-tramp-file-p "/host:/:"))
321 (should-not (tramp-tramp-file-p "/host1|host2:"))
322 (should-not (tramp-tramp-file-p "/user1@host1|user2@host2:"))
323 ;; Quote with "/:" suppresses file name handlers.
324 (should-not (tramp-tramp-file-p "/:[]")))
327 (tramp-change-syntax syntax
))))
329 (ert-deftest tramp-test02-file-name-dissect
()
330 "Check remote file name components."
331 (let ((tramp-default-method "default-method")
332 (tramp-default-user "default-user")
333 (tramp-default-host "default-host"))
334 ;; Expand `tramp-default-user' and `tramp-default-host'.
335 (should (string-equal
336 (file-remote-p "/method::")
337 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
338 (should (string-equal (file-remote-p "/method::" 'method
) "method"))
339 (should (string-equal (file-remote-p "/method::" 'user
) "default-user"))
340 (should (string-equal (file-remote-p "/method::" 'host
) "default-host"))
341 (should (string-equal (file-remote-p "/method::" 'localname
) ""))
342 (should (string-equal (file-remote-p "/method::" 'hop
) nil
))
344 ;; Expand `tramp-default-method' and `tramp-default-user'.
345 (should (string-equal
346 (file-remote-p "/-:host:")
347 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
348 (should (string-equal (file-remote-p "/-:host:" 'method
) "default-method"))
349 (should (string-equal (file-remote-p "/-:host:" 'user
) "default-user"))
350 (should (string-equal (file-remote-p "/-:host:" 'host
) "host"))
351 (should (string-equal (file-remote-p "/-:host:" 'localname
) ""))
352 (should (string-equal (file-remote-p "/-:host:" 'hop
) nil
))
354 ;; Expand `tramp-default-method' and `tramp-default-host'.
355 (should (string-equal
356 (file-remote-p "/-:user@:")
357 (format "/%s:%s@%s:" "default-method" "user" "default-host")))
358 (should (string-equal (file-remote-p "/-:user@:" 'method
) "default-method"))
359 (should (string-equal (file-remote-p "/-:user@:" 'user
) "user"))
360 (should (string-equal (file-remote-p "/-:user@:" 'host
) "default-host"))
361 (should (string-equal (file-remote-p "/-:user@:" 'localname
) ""))
362 (should (string-equal (file-remote-p "/-:user@:" 'hop
) nil
))
364 ;; Expand `tramp-default-method'.
365 (should (string-equal
366 (file-remote-p "/-:user@host:")
367 (format "/%s:%s@%s:" "default-method" "user" "host")))
368 (should (string-equal
369 (file-remote-p "/-:user@host:" 'method
) "default-method"))
370 (should (string-equal (file-remote-p "/-:user@host:" 'user
) "user"))
371 (should (string-equal (file-remote-p "/-:user@host:" 'host
) "host"))
372 (should (string-equal (file-remote-p "/-:user@host:" 'localname
) ""))
373 (should (string-equal (file-remote-p "/-:user@host:" 'hop
) nil
))
375 ;; Expand `tramp-default-user'.
376 (should (string-equal
377 (file-remote-p "/method:host:")
378 (format "/%s:%s@%s:" "method" "default-user" "host")))
379 (should (string-equal (file-remote-p "/method:host:" 'method
) "method"))
380 (should (string-equal (file-remote-p "/method:host:" 'user
) "default-user"))
381 (should (string-equal (file-remote-p "/method:host:" 'host
) "host"))
382 (should (string-equal (file-remote-p "/method:host:" 'localname
) ""))
383 (should (string-equal (file-remote-p "/method:host:" 'hop
) nil
))
385 ;; Expand `tramp-default-host'.
386 (should (string-equal
387 (file-remote-p "/method:user@:")
388 (format "/%s:%s@%s:" "method" "user" "default-host")))
389 (should (string-equal (file-remote-p "/method:user@:" 'method
) "method"))
390 (should (string-equal (file-remote-p "/method:user@:" 'user
) "user"))
391 (should (string-equal (file-remote-p "/method:user@:" 'host
)
393 (should (string-equal (file-remote-p "/method:user@:" 'localname
) ""))
394 (should (string-equal (file-remote-p "/method:user@:" 'hop
) nil
))
397 (should (string-equal
398 (file-remote-p "/method:user@host:")
399 (format "/%s:%s@%s:" "method" "user" "host")))
400 (should (string-equal
401 (file-remote-p "/method:user@host:" 'method
) "method"))
402 (should (string-equal (file-remote-p "/method:user@host:" 'user
) "user"))
403 (should (string-equal (file-remote-p "/method:user@host:" 'host
) "host"))
404 (should (string-equal (file-remote-p "/method:user@host:" 'localname
) ""))
405 (should (string-equal (file-remote-p "/method:user@host:" 'hop
) nil
))
408 (should (string-equal
409 (file-remote-p "/method:user@email@host:")
410 (format "/%s:%s@%s:" "method" "user@email" "host")))
411 (should (string-equal
412 (file-remote-p "/method:user@email@host:" 'method
) "method"))
413 (should (string-equal
414 (file-remote-p "/method:user@email@host:" 'user
) "user@email"))
415 (should (string-equal
416 (file-remote-p "/method:user@email@host:" 'host
) "host"))
417 (should (string-equal
418 (file-remote-p "/method:user@email@host:" 'localname
) ""))
419 (should (string-equal
420 (file-remote-p "/method:user@email@host:" 'hop
) nil
))
422 ;; Expand `tramp-default-method' and `tramp-default-user'.
423 (should (string-equal
424 (file-remote-p "/-:host#1234:")
425 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
426 (should (string-equal
427 (file-remote-p "/-:host#1234:" 'method
) "default-method"))
428 (should (string-equal (file-remote-p "/-:host#1234:" 'user
) "default-user"))
429 (should (string-equal (file-remote-p "/-:host#1234:" 'host
) "host#1234"))
430 (should (string-equal (file-remote-p "/-:host#1234:" 'localname
) ""))
431 (should (string-equal (file-remote-p "/-:host#1234:" 'hop
) nil
))
433 ;; Expand `tramp-default-method'.
434 (should (string-equal
435 (file-remote-p "/-:user@host#1234:")
436 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
437 (should (string-equal
438 (file-remote-p "/-:user@host#1234:" 'method
) "default-method"))
439 (should (string-equal (file-remote-p "/-:user@host#1234:" 'user
) "user"))
440 (should (string-equal (file-remote-p "/-:user@host#1234:" 'host
) "host#1234"))
441 (should (string-equal (file-remote-p "/-:user@host#1234:" 'localname
) ""))
442 (should (string-equal (file-remote-p "/-:user@host#1234:" 'hop
) nil
))
444 ;; Expand `tramp-default-user'.
445 (should (string-equal
446 (file-remote-p "/method:host#1234:")
447 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
448 (should (string-equal
449 (file-remote-p "/method:host#1234:" 'method
) "method"))
450 (should (string-equal
451 (file-remote-p "/method:host#1234:" 'user
) "default-user"))
452 (should (string-equal
453 (file-remote-p "/method:host#1234:" 'host
) "host#1234"))
454 (should (string-equal (file-remote-p "/method:host#1234:" 'localname
) ""))
455 (should (string-equal (file-remote-p "/method:host#1234:" 'hop
) nil
))
458 (should (string-equal
459 (file-remote-p "/method:user@host#1234:")
460 (format "/%s:%s@%s:" "method" "user" "host#1234")))
461 (should (string-equal
462 (file-remote-p "/method:user@host#1234:" 'method
) "method"))
463 (should (string-equal
464 (file-remote-p "/method:user@host#1234:" 'user
) "user"))
465 (should (string-equal
466 (file-remote-p "/method:user@host#1234:" 'host
) "host#1234"))
467 (should (string-equal
468 (file-remote-p "/method:user@host#1234:" 'localname
) ""))
469 (should (string-equal
470 (file-remote-p "/method:user@host#1234:" 'hop
) nil
))
472 ;; Expand `tramp-default-method' and `tramp-default-user'.
473 (should (string-equal
474 (file-remote-p "/-:1.2.3.4:")
475 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
476 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'method
) "default-method"))
477 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'user
) "default-user"))
478 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'host
) "1.2.3.4"))
479 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'localname
) ""))
480 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'hop
) nil
))
482 ;; Expand `tramp-default-method'.
483 (should (string-equal
484 (file-remote-p "/-:user@1.2.3.4:")
485 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
486 (should (string-equal
487 (file-remote-p "/-:user@1.2.3.4:" 'method
) "default-method"))
488 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'user
) "user"))
489 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'host
) "1.2.3.4"))
490 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'localname
) ""))
491 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'hop
) nil
))
493 ;; Expand `tramp-default-user'.
494 (should (string-equal
495 (file-remote-p "/method:1.2.3.4:")
496 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
497 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method
) "method"))
498 (should (string-equal
499 (file-remote-p "/method:1.2.3.4:" 'user
) "default-user"))
500 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host
) "1.2.3.4"))
501 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname
) ""))
502 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'hop
) nil
))
505 (should (string-equal
506 (file-remote-p "/method:user@1.2.3.4:")
507 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
508 (should (string-equal
509 (file-remote-p "/method:user@1.2.3.4:" 'method
) "method"))
510 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user
) "user"))
511 (should (string-equal
512 (file-remote-p "/method:user@1.2.3.4:" 'host
) "1.2.3.4"))
513 (should (string-equal
514 (file-remote-p "/method:user@1.2.3.4:" 'localname
) ""))
515 (should (string-equal
516 (file-remote-p "/method:user@1.2.3.4:" 'hop
) nil
))
518 ;; Expand `tramp-default-method', `tramp-default-user' and
519 ;; `tramp-default-host'.
520 (should (string-equal
521 (file-remote-p "/-:[]:")
523 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
524 (should (string-equal (file-remote-p "/-:[]:" 'method
) "default-method"))
525 (should (string-equal (file-remote-p "/-:[]:" 'user
) "default-user"))
526 (should (string-equal (file-remote-p "/-:[]:" 'host
) "default-host"))
527 (should (string-equal (file-remote-p "/-:[]:" 'localname
) ""))
528 (should (string-equal (file-remote-p "/-:[]:" 'hop
) nil
))
530 ;; Expand `tramp-default-method' and `tramp-default-user'.
531 (let ((tramp-default-host "::1"))
532 (should (string-equal
533 (file-remote-p "/-:[]:")
534 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
535 (should (string-equal (file-remote-p "/-:[]:" 'method
) "default-method"))
536 (should (string-equal (file-remote-p "/-:[]:" 'user
) "default-user"))
537 (should (string-equal (file-remote-p "/-:[]:" 'host
) "::1"))
538 (should (string-equal (file-remote-p "/-:[]:" 'localname
) ""))
539 (should (string-equal (file-remote-p "/-:[]:" 'hop
) nil
)))
541 ;; Expand `tramp-default-method' and `tramp-default-user'.
542 (should (string-equal
543 (file-remote-p "/-:[::1]:")
544 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
545 (should (string-equal (file-remote-p "/-:[::1]:" 'method
) "default-method"))
546 (should (string-equal (file-remote-p "/-:[::1]:" 'user
) "default-user"))
547 (should (string-equal (file-remote-p "/-:[::1]:" 'host
) "::1"))
548 (should (string-equal (file-remote-p "/-:[::1]:" 'localname
) ""))
549 (should (string-equal (file-remote-p "/-:[::1]:" 'hop
) nil
))
551 ;; Expand `tramp-default-method'.
552 (should (string-equal
553 (file-remote-p "/-:user@[::1]:")
554 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
555 (should (string-equal
556 (file-remote-p "/-:user@[::1]:" 'method
) "default-method"))
557 (should (string-equal (file-remote-p "/-:user@[::1]:" 'user
) "user"))
558 (should (string-equal (file-remote-p "/-:user@[::1]:" 'host
) "::1"))
559 (should (string-equal (file-remote-p "/-:user@[::1]:" 'localname
) ""))
560 (should (string-equal (file-remote-p "/-:user@[::1]:" 'hop
) nil
))
562 ;; Expand `tramp-default-user'.
563 (should (string-equal
564 (file-remote-p "/method:[::1]:")
565 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
566 (should (string-equal (file-remote-p "/method:[::1]:" 'method
) "method"))
567 (should (string-equal
568 (file-remote-p "/method:[::1]:" 'user
) "default-user"))
569 (should (string-equal (file-remote-p "/method:[::1]:" 'host
) "::1"))
570 (should (string-equal (file-remote-p "/method:[::1]:" 'localname
) ""))
571 (should (string-equal (file-remote-p "/method:[::1]:" 'hop
) nil
))
574 (should (string-equal
575 (file-remote-p "/method:user@[::1]:")
576 (format "/%s:%s@%s:" "method" "user" "[::1]")))
577 (should (string-equal
578 (file-remote-p "/method:user@[::1]:" 'method
) "method"))
579 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user
) "user"))
580 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host
) "::1"))
581 (should (string-equal
582 (file-remote-p "/method:user@[::1]:" 'localname
) ""))
583 (should (string-equal (file-remote-p "/method:user@[::1]:" 'hop
) nil
))
585 ;; Local file name part.
586 (should (string-equal (file-remote-p "/-:host:/:" 'localname
) "/:"))
587 (should (string-equal (file-remote-p "/method:::" 'localname
) ":"))
588 (should (string-equal (file-remote-p "/method:: " 'localname
) " "))
589 (should (string-equal (file-remote-p "/method::file" 'localname
) "file"))
590 (should (string-equal
591 (file-remote-p "/method::/path/to/file" 'localname
)
597 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
598 (format "/%s:%s@%s|%s:%s@%s:"
599 "method1" "user1" "host1" "method2" "user2" "host2")))
603 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method
)
608 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user
)
613 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host
)
618 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname
)
623 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'hop
)
625 "method1" "user1" "host1")))
631 "/method1:user1@host1"
632 "|method2:user2@host2"
633 "|method3:user3@host3:/path/to/file"))
634 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
635 "method1" "user1" "host1"
636 "method2" "user2" "host2"
637 "method3" "user3" "host3")))
642 "/method1:user1@host1"
643 "|method2:user2@host2"
644 "|method3:user3@host3:/path/to/file")
651 "/method1:user1@host1"
652 "|method2:user2@host2"
653 "|method3:user3@host3:/path/to/file")
660 "/method1:user1@host1"
661 "|method2:user2@host2"
662 "|method3:user3@host3:/path/to/file")
669 "/method1:user1@host1"
670 "|method2:user2@host2"
671 "|method3:user3@host3:/path/to/file")
678 "/method1:user1@host1"
679 "|method2:user2@host2"
680 "|method3:user3@host3:/path/to/file")
682 (format "%s:%s@%s|%s:%s@%s|"
683 "method1" "user1" "host1" "method2" "user2" "host2")))))
685 (ert-deftest tramp-test02-file-name-dissect-simplified
()
686 "Check simplified file name components."
687 :tags
'(:expensive-test
)
688 (let ((tramp-default-method "default-method")
689 (tramp-default-user "default-user")
690 (tramp-default-host "default-host")
691 (syntax tramp-syntax
))
694 (tramp-change-syntax 'simplified
)
695 ;; Expand `tramp-default-method' and `tramp-default-user'.
696 (should (string-equal
697 (file-remote-p "/host:")
698 (format "/%s@%s:" "default-user" "host")))
699 (should (string-equal
700 (file-remote-p "/host:" 'method
) "default-method"))
701 (should (string-equal (file-remote-p "/host:" 'user
) "default-user"))
702 (should (string-equal (file-remote-p "/host:" 'host
) "host"))
703 (should (string-equal (file-remote-p "/host:" 'localname
) ""))
704 (should (string-equal (file-remote-p "/host:" 'hop
) nil
))
706 ;; Expand `tramp-default-method' and `tramp-default-host'.
707 (should (string-equal
708 (file-remote-p "/user@:")
709 (format "/%s@%s:" "user" "default-host")))
710 (should (string-equal
711 (file-remote-p "/user@:" 'method
) "default-method"))
712 (should (string-equal (file-remote-p "/user@:" 'user
) "user"))
713 (should (string-equal (file-remote-p "/user@:" 'host
) "default-host"))
714 (should (string-equal (file-remote-p "/user@:" 'localname
) ""))
715 (should (string-equal (file-remote-p "/user@:" 'hop
) nil
))
717 ;; Expand `tramp-default-method'.
718 (should (string-equal
719 (file-remote-p "/user@host:")
720 (format "/%s@%s:" "user" "host")))
721 (should (string-equal
722 (file-remote-p "/user@host:" 'method
) "default-method"))
723 (should (string-equal (file-remote-p "/user@host:" 'user
) "user"))
724 (should (string-equal (file-remote-p "/user@host:" 'host
) "host"))
725 (should (string-equal (file-remote-p "/user@host:" 'localname
) ""))
726 (should (string-equal (file-remote-p "/user@host:" 'hop
) nil
))
729 (should (string-equal
730 (file-remote-p "/user@email@host:")
731 (format "/%s@%s:" "user@email" "host")))
732 (should (string-equal
734 "/user@email@host:" 'method
) "default-method"))
735 (should (string-equal
736 (file-remote-p "/user@email@host:" 'user
) "user@email"))
737 (should (string-equal
738 (file-remote-p "/user@email@host:" 'host
) "host"))
739 (should (string-equal
740 (file-remote-p "/user@email@host:" 'localname
) ""))
741 (should (string-equal
742 (file-remote-p "/user@email@host:" 'hop
) nil
))
744 ;; Expand `tramp-default-method' and `tramp-default-user'.
745 (should (string-equal
746 (file-remote-p "/host#1234:")
747 (format "/%s@%s:" "default-user" "host#1234")))
748 (should (string-equal
749 (file-remote-p "/host#1234:" 'method
) "default-method"))
750 (should (string-equal
751 (file-remote-p "/host#1234:" 'user
) "default-user"))
752 (should (string-equal
753 (file-remote-p "/host#1234:" 'host
) "host#1234"))
754 (should (string-equal (file-remote-p "/host#1234:" 'localname
) ""))
755 (should (string-equal (file-remote-p "/host#1234:" 'hop
) nil
))
757 ;; Expand `tramp-default-method'.
758 (should (string-equal
759 (file-remote-p "/user@host#1234:")
760 (format "/%s@%s:" "user" "host#1234")))
761 (should (string-equal
762 (file-remote-p "/user@host#1234:" 'method
) "default-method"))
763 (should (string-equal
764 (file-remote-p "/user@host#1234:" 'user
) "user"))
765 (should (string-equal
766 (file-remote-p "/user@host#1234:" 'host
) "host#1234"))
767 (should (string-equal
768 (file-remote-p "/user@host#1234:" 'localname
) ""))
769 (should (string-equal (file-remote-p "/user@host#1234:" 'hop
) nil
))
771 ;; Expand `tramp-default-method' and `tramp-default-user'.
772 (should (string-equal
773 (file-remote-p "/1.2.3.4:")
774 (format "/%s@%s:" "default-user" "1.2.3.4")))
775 (should (string-equal
776 (file-remote-p "/1.2.3.4:" 'method
) "default-method"))
777 (should (string-equal
778 (file-remote-p "/1.2.3.4:" 'user
) "default-user"))
779 (should (string-equal (file-remote-p "/1.2.3.4:" 'host
) "1.2.3.4"))
780 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname
) ""))
781 (should (string-equal (file-remote-p "/1.2.3.4:" 'hop
) nil
))
783 ;; Expand `tramp-default-method'.
784 (should (string-equal
785 (file-remote-p "/user@1.2.3.4:")
786 (format "/%s@%s:" "user" "1.2.3.4")))
787 (should (string-equal
788 (file-remote-p "/user@1.2.3.4:" 'method
) "default-method"))
789 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user
) "user"))
790 (should (string-equal
791 (file-remote-p "/user@1.2.3.4:" 'host
) "1.2.3.4"))
792 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname
) ""))
793 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'hop
) nil
))
795 ;; Expand `tramp-default-method', `tramp-default-user' and
796 ;; `tramp-default-host'.
797 (should (string-equal
798 (file-remote-p "/[]:")
800 "/%s@%s:" "default-user" "default-host")))
801 (should (string-equal
802 (file-remote-p "/[]:" 'method
) "default-method"))
803 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
804 (should (string-equal (file-remote-p "/[]:" 'host
) "default-host"))
805 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
806 (should (string-equal (file-remote-p "/[]:" 'hop
) nil
))
808 ;; Expand `tramp-default-method' and `tramp-default-user'.
809 (let ((tramp-default-host "::1"))
810 (should (string-equal
811 (file-remote-p "/[]:")
812 (format "/%s@%s:" "default-user" "[::1]")))
813 (should (string-equal
814 (file-remote-p "/[]:" 'method
) "default-method"))
815 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
816 (should (string-equal (file-remote-p "/[]:" 'host
) "::1"))
817 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
818 (should (string-equal (file-remote-p "/[]:" 'hop
) nil
)))
820 ;; Expand `tramp-default-method' and `tramp-default-user'.
821 (should (string-equal
822 (file-remote-p "/[::1]:")
823 (format "/%s@%s:" "default-user" "[::1]")))
824 (should (string-equal
825 (file-remote-p "/[::1]:" 'method
) "default-method"))
826 (should (string-equal (file-remote-p "/[::1]:" 'user
) "default-user"))
827 (should (string-equal (file-remote-p "/[::1]:" 'host
) "::1"))
828 (should (string-equal (file-remote-p "/[::1]:" 'localname
) ""))
829 (should (string-equal (file-remote-p "/[::1]:" 'hop
) nil
))
831 ;; Expand `tramp-default-method'.
832 (should (string-equal
833 (file-remote-p "/user@[::1]:")
834 (format "/%s@%s:" "user" "[::1]")))
835 (should (string-equal
836 (file-remote-p "/user@[::1]:" 'method
) "default-method"))
837 (should (string-equal (file-remote-p "/user@[::1]:" 'user
) "user"))
838 (should (string-equal (file-remote-p "/user@[::1]:" 'host
) "::1"))
839 (should (string-equal (file-remote-p "/user@[::1]:" 'localname
) ""))
840 (should (string-equal (file-remote-p "/user@[::1]:" 'hop
) nil
))
842 ;; Local file name part.
843 (should (string-equal (file-remote-p "/host:/:" 'localname
) "/:"))
844 (should (string-equal (file-remote-p "/host::" 'localname
) ":"))
845 (should (string-equal (file-remote-p "/host: " 'localname
) " "))
846 (should (string-equal (file-remote-p "/host:file" 'localname
) "file"))
847 (should (string-equal
848 (file-remote-p "/host:/path/to/file" 'localname
)
854 (file-remote-p "/user1@host1|user2@host2:/path/to/file")
855 (format "/%s@%s|%s@%s:" "user1" "host1" "user2" "host2")))
859 "/user1@host1|user2@host2:/path/to/file" 'method
)
864 "/user1@host1|user2@host2:/path/to/file" 'user
)
869 "/user1@host1|user2@host2:/path/to/file" 'host
)
874 "/user1@host1|user2@host2:/path/to/file" 'localname
)
879 "/user1@host1|user2@host2:/path/to/file" 'hop
)
880 (format "%s@%s|" "user1" "host1")))
888 "|user3@host3:/path/to/file"))
889 (format "/%s@%s|%s@%s|%s@%s:"
899 "|user3@host3:/path/to/file")
908 "|user3@host3:/path/to/file")
917 "|user3@host3:/path/to/file")
926 "|user3@host3:/path/to/file")
935 "|user3@host3:/path/to/file")
937 (format "%s@%s|%s@%s|"
938 "user1" "host1" "user2" "host2"))))
941 (tramp-change-syntax syntax
))))
943 (ert-deftest tramp-test02-file-name-dissect-separate
()
944 "Check separate file name components."
945 :tags
'(:expensive-test
)
946 (let ((tramp-default-method "default-method")
947 (tramp-default-user "default-user")
948 (tramp-default-host "default-host")
949 (syntax tramp-syntax
))
952 (tramp-change-syntax 'separate
)
953 ;; Expand `tramp-default-user' and `tramp-default-host'.
954 (should (string-equal
955 (file-remote-p "/[method/]")
957 "/[%s/%s@%s]" "method" "default-user" "default-host")))
958 (should (string-equal (file-remote-p "/[method/]" 'method
) "method"))
959 (should (string-equal
960 (file-remote-p "/[method/]" 'user
) "default-user"))
961 (should (string-equal
962 (file-remote-p "/[method/]" 'host
) "default-host"))
963 (should (string-equal (file-remote-p "/[method/]" 'localname
) ""))
964 (should (string-equal (file-remote-p "/[method/]" 'hop
) nil
))
966 ;; Expand `tramp-default-method' and `tramp-default-user'.
967 (should (string-equal
968 (file-remote-p "/[/host]")
970 "/[%s/%s@%s]" "default-method" "default-user" "host")))
971 (should (string-equal
972 (file-remote-p "/[/host]" 'method
) "default-method"))
973 (should (string-equal
974 (file-remote-p "/[/host]" 'user
) "default-user"))
975 (should (string-equal (file-remote-p "/[/host]" 'host
) "host"))
976 (should (string-equal (file-remote-p "/[/host]" 'localname
) ""))
977 (should (string-equal (file-remote-p "/[/host]" 'hop
) nil
))
979 ;; Expand `tramp-default-method' and `tramp-default-host'.
980 (should (string-equal
981 (file-remote-p "/[/user@]")
983 "/[%s/%s@%s]" "default-method" "user" "default-host")))
984 (should (string-equal
985 (file-remote-p "/[/user@]" 'method
) "default-method"))
986 (should (string-equal (file-remote-p "/[/user@]" 'user
) "user"))
987 (should (string-equal
988 (file-remote-p "/[/user@]" 'host
) "default-host"))
989 (should (string-equal (file-remote-p "/[/user@]" 'localname
) ""))
990 (should (string-equal (file-remote-p "/[/user@]" 'hop
) nil
))
992 ;; Expand `tramp-default-method'.
993 (should (string-equal
994 (file-remote-p "/[/user@host]")
995 (format "/[%s/%s@%s]" "default-method" "user" "host")))
996 (should (string-equal
997 (file-remote-p "/[/user@host]" 'method
) "default-method"))
998 (should (string-equal (file-remote-p "/[/user@host]" 'user
) "user"))
999 (should (string-equal (file-remote-p "/[/user@host]" 'host
) "host"))
1000 (should (string-equal (file-remote-p "/[/user@host]" 'localname
) ""))
1001 (should (string-equal (file-remote-p "/[/user@host]" 'hop
) nil
))
1003 ;; Expand `tramp-default-method' and `tramp-default-user'.
1004 (should (string-equal
1005 (file-remote-p "/[-/host]")
1007 "/[%s/%s@%s]" "default-method" "default-user" "host")))
1008 (should (string-equal
1009 (file-remote-p "/[-/host]" 'method
) "default-method"))
1010 (should (string-equal
1011 (file-remote-p "/[-/host]" 'user
) "default-user"))
1012 (should (string-equal (file-remote-p "/[-/host]" 'host
) "host"))
1013 (should (string-equal (file-remote-p "/[-/host]" 'localname
) ""))
1014 (should (string-equal (file-remote-p "/[-/host]" 'hop
) nil
))
1016 ;; Expand `tramp-default-method' and `tramp-default-host'.
1017 (should (string-equal
1018 (file-remote-p "/[-/user@]")
1020 "/[%s/%s@%s]" "default-method" "user" "default-host")))
1021 (should (string-equal
1022 (file-remote-p "/[-/user@]" 'method
) "default-method"))
1023 (should (string-equal (file-remote-p "/[-/user@]" 'user
) "user"))
1024 (should (string-equal
1025 (file-remote-p "/[-/user@]" 'host
) "default-host"))
1026 (should (string-equal (file-remote-p "/[-/user@]" 'localname
) ""))
1027 (should (string-equal (file-remote-p "/[-/user@]" 'hop
) nil
))
1029 ;; Expand `tramp-default-method'.
1030 (should (string-equal
1031 (file-remote-p "/[-/user@host]")
1032 (format "/[%s/%s@%s]" "default-method" "user" "host")))
1033 (should (string-equal
1034 (file-remote-p "/[-/user@host]" 'method
) "default-method"))
1035 (should (string-equal (file-remote-p "/[-/user@host]" 'user
) "user"))
1036 (should (string-equal (file-remote-p "/[-/user@host]" 'host
) "host"))
1037 (should (string-equal (file-remote-p "/[-/user@host]" 'localname
) ""))
1038 (should (string-equal (file-remote-p "/[-/user@host]" 'hop
) nil
))
1040 ;; Expand `tramp-default-user'.
1041 (should (string-equal
1042 (file-remote-p "/[method/host]")
1043 (format "/[%s/%s@%s]" "method" "default-user" "host")))
1044 (should (string-equal
1045 (file-remote-p "/[method/host]" 'method
) "method"))
1046 (should (string-equal
1047 (file-remote-p "/[method/host]" 'user
) "default-user"))
1048 (should (string-equal (file-remote-p "/[method/host]" 'host
) "host"))
1049 (should (string-equal (file-remote-p "/[method/host]" 'localname
) ""))
1050 (should (string-equal (file-remote-p "/[method/host]" 'hop
) nil
))
1052 ;; Expand `tramp-default-host'.
1053 (should (string-equal
1054 (file-remote-p "/[method/user@]")
1055 (format "/[%s/%s@%s]" "method" "user" "default-host")))
1056 (should (string-equal
1057 (file-remote-p "/[method/user@]" 'method
) "method"))
1058 (should (string-equal (file-remote-p "/[method/user@]" 'user
) "user"))
1059 (should (string-equal
1060 (file-remote-p "/[method/user@]" 'host
) "default-host"))
1061 (should (string-equal
1062 (file-remote-p "/[method/user@]" 'localname
) ""))
1063 (should (string-equal (file-remote-p "/[method/user@]" 'hop
) nil
))
1066 (should (string-equal
1067 (file-remote-p "/[method/user@host]")
1068 (format "/[%s/%s@%s]" "method" "user" "host")))
1069 (should (string-equal
1070 (file-remote-p "/[method/user@host]" 'method
) "method"))
1071 (should (string-equal
1072 (file-remote-p "/[method/user@host]" 'user
) "user"))
1073 (should (string-equal
1074 (file-remote-p "/[method/user@host]" 'host
) "host"))
1075 (should (string-equal
1076 (file-remote-p "/[method/user@host]" 'localname
) ""))
1077 (should (string-equal
1078 (file-remote-p "/[method/user@host]" 'hop
) nil
))
1081 (should (string-equal
1082 (file-remote-p "/[method/user@email@host]")
1083 (format "/[%s/%s@%s]" "method" "user@email" "host")))
1084 (should (string-equal
1086 "/[method/user@email@host]" 'method
) "method"))
1087 (should (string-equal
1089 "/[method/user@email@host]" 'user
) "user@email"))
1090 (should (string-equal
1091 (file-remote-p "/[method/user@email@host]" 'host
) "host"))
1092 (should (string-equal
1093 (file-remote-p "/[method/user@email@host]" 'localname
) ""))
1094 (should (string-equal
1095 (file-remote-p "/[method/user@email@host]" 'hop
) nil
))
1097 ;; Expand `tramp-default-method' and `tramp-default-user'.
1098 (should (string-equal
1099 (file-remote-p "/[/host#1234]")
1101 "/[%s/%s@%s]" "default-method" "default-user" "host#1234")))
1102 (should (string-equal
1103 (file-remote-p "/[/host#1234]" 'method
) "default-method"))
1104 (should (string-equal
1105 (file-remote-p "/[/host#1234]" 'user
) "default-user"))
1106 (should (string-equal
1107 (file-remote-p "/[/host#1234]" 'host
) "host#1234"))
1108 (should (string-equal (file-remote-p "/[/host#1234]" 'localname
) ""))
1109 (should (string-equal (file-remote-p "/[/host#1234]" 'hop
) nil
))
1111 ;; Expand `tramp-default-method'.
1112 (should (string-equal
1113 (file-remote-p "/[/user@host#1234]")
1114 (format "/[%s/%s@%s]" "default-method" "user" "host#1234")))
1115 (should (string-equal
1117 "/[/user@host#1234]" 'method
) "default-method"))
1118 (should (string-equal
1120 "/[/user@host#1234]" 'user
) "user"))
1121 (should (string-equal
1122 (file-remote-p "/[/user@host#1234]" 'host
) "host#1234"))
1123 (should (string-equal
1124 (file-remote-p "/[/user@host#1234]" 'localname
) ""))
1125 (should (string-equal (file-remote-p "/[/user@host#1234]" '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-user'.
1158 (should (string-equal
1159 (file-remote-p "/[method/host#1234]")
1160 (format "/[%s/%s@%s]" "method" "default-user" "host#1234")))
1161 (should (string-equal
1162 (file-remote-p "/[method/host#1234]" 'method
) "method"))
1163 (should (string-equal
1164 (file-remote-p "/[method/host#1234]" 'user
) "default-user"))
1165 (should (string-equal
1166 (file-remote-p "/[method/host#1234]" 'host
) "host#1234"))
1167 (should (string-equal
1168 (file-remote-p "/[method/host#1234]" 'localname
) ""))
1169 (should (string-equal (file-remote-p "/[method/host#1234]" 'hop
) nil
))
1172 (should (string-equal
1173 (file-remote-p "/[method/user@host#1234]")
1174 (format "/[%s/%s@%s]" "method" "user" "host#1234")))
1175 (should (string-equal
1176 (file-remote-p "/[method/user@host#1234]" 'method
) "method"))
1177 (should (string-equal
1178 (file-remote-p "/[method/user@host#1234]" 'user
) "user"))
1179 (should (string-equal
1181 "/[method/user@host#1234]" 'host
) "host#1234"))
1182 (should (string-equal
1183 (file-remote-p "/[method/user@host#1234]" 'localname
) ""))
1184 (should (string-equal
1185 (file-remote-p "/[method/user@host#1234]" 'hop
) nil
))
1187 ;; Expand `tramp-default-method' and `tramp-default-user'.
1188 (should (string-equal
1189 (file-remote-p "/[/1.2.3.4]")
1191 "/[%s/%s@%s]" "default-method" "default-user" "1.2.3.4")))
1192 (should (string-equal
1193 (file-remote-p "/[/1.2.3.4]" 'method
) "default-method"))
1194 (should (string-equal
1195 (file-remote-p "/[/1.2.3.4]" 'user
) "default-user"))
1196 (should (string-equal
1197 (file-remote-p "/[/1.2.3.4]" 'host
) "1.2.3.4"))
1198 (should (string-equal (file-remote-p "/[/1.2.3.4]" 'localname
) ""))
1199 (should (string-equal (file-remote-p "/[/1.2.3.4]" 'hop
) nil
))
1201 ;; Expand `tramp-default-method'.
1202 (should (string-equal
1203 (file-remote-p "/[/user@1.2.3.4]")
1204 (format "/[%s/%s@%s]" "default-method" "user" "1.2.3.4")))
1205 (should (string-equal
1207 "/[/user@1.2.3.4]" 'method
) "default-method"))
1208 (should (string-equal
1209 (file-remote-p "/[/user@1.2.3.4]" 'user
) "user"))
1210 (should (string-equal
1211 (file-remote-p "/[/user@1.2.3.4]" 'host
) "1.2.3.4"))
1212 (should (string-equal
1213 (file-remote-p "/[/user@1.2.3.4]" 'localname
) ""))
1214 (should (string-equal (file-remote-p "/[/user@1.2.3.4]" 'hop
) nil
))
1216 ;; Expand `tramp-default-method' and `tramp-default-user'.
1217 (should (string-equal
1218 (file-remote-p "/[-/1.2.3.4]")
1220 "/[%s/%s@%s]" "default-method" "default-user" "1.2.3.4")))
1221 (should (string-equal
1222 (file-remote-p "/[-/1.2.3.4]" 'method
) "default-method"))
1223 (should (string-equal
1224 (file-remote-p "/[-/1.2.3.4]" 'user
) "default-user"))
1225 (should (string-equal
1226 (file-remote-p "/[-/1.2.3.4]" 'host
) "1.2.3.4"))
1227 (should (string-equal (file-remote-p "/[-/1.2.3.4]" 'localname
) ""))
1228 (should (string-equal (file-remote-p "/[-/1.2.3.4]" 'hop
) nil
))
1230 ;; Expand `tramp-default-method'.
1231 (should (string-equal
1232 (file-remote-p "/[-/user@1.2.3.4]")
1233 (format "/[%s/%s@%s]" "default-method" "user" "1.2.3.4")))
1234 (should (string-equal
1236 "/[-/user@1.2.3.4]" 'method
) "default-method"))
1237 (should (string-equal
1238 (file-remote-p "/[-/user@1.2.3.4]" 'user
) "user"))
1239 (should (string-equal
1240 (file-remote-p "/[-/user@1.2.3.4]" 'host
) "1.2.3.4"))
1241 (should (string-equal
1242 (file-remote-p "/[-/user@1.2.3.4]" 'localname
) ""))
1243 (should (string-equal (file-remote-p "/[-/user@1.2.3.4]" 'hop
) nil
))
1245 ;; Expand `tramp-default-user'.
1246 (should (string-equal
1247 (file-remote-p "/[method/1.2.3.4]")
1248 (format "/[%s/%s@%s]" "method" "default-user" "1.2.3.4")))
1249 (should (string-equal
1250 (file-remote-p "/[method/1.2.3.4]" 'method
) "method"))
1251 (should (string-equal
1252 (file-remote-p "/[method/1.2.3.4]" 'user
) "default-user"))
1253 (should (string-equal
1254 (file-remote-p "/[method/1.2.3.4]" 'host
) "1.2.3.4"))
1255 (should (string-equal
1256 (file-remote-p "/[method/1.2.3.4]" 'localname
) ""))
1257 (should (string-equal (file-remote-p "/[method/1.2.3.4]" 'hop
) nil
))
1260 (should (string-equal
1261 (file-remote-p "/[method/user@1.2.3.4]")
1262 (format "/[%s/%s@%s]" "method" "user" "1.2.3.4")))
1263 (should (string-equal
1264 (file-remote-p "/[method/user@1.2.3.4]" 'method
) "method"))
1265 (should (string-equal
1266 (file-remote-p "/[method/user@1.2.3.4]" 'user
) "user"))
1267 (should (string-equal
1268 (file-remote-p "/[method/user@1.2.3.4]" 'host
) "1.2.3.4"))
1269 (should (string-equal
1270 (file-remote-p "/[method/user@1.2.3.4]" 'localname
) ""))
1271 (should (string-equal
1272 (file-remote-p "/[method/user@1.2.3.4]" 'hop
) nil
))
1274 ;; Expand `tramp-default-method', `tramp-default-user' and
1275 ;; `tramp-default-host'.
1276 (should (string-equal
1277 (file-remote-p "/[/]")
1280 "default-method" "default-user" "default-host")))
1281 (should (string-equal
1282 (file-remote-p "/[/]" 'method
) "default-method"))
1283 (should (string-equal (file-remote-p "/[/]" 'user
) "default-user"))
1284 (should (string-equal (file-remote-p "/[/]" 'host
) "default-host"))
1285 (should (string-equal (file-remote-p "/[/]" 'localname
) ""))
1286 (should (string-equal (file-remote-p "/[/]" 'hop
) nil
))
1288 ;; Expand `tramp-default-method' and `tramp-default-user'.
1289 (let ((tramp-default-host "::1"))
1290 (should (string-equal
1291 (file-remote-p "/[/]")
1294 "default-method" "default-user" "::1")))
1295 (should (string-equal
1296 (file-remote-p "/[/]" 'method
) "default-method"))
1297 (should (string-equal (file-remote-p "/[/]" 'user
) "default-user"))
1298 (should (string-equal (file-remote-p "/[/]" 'host
) "::1"))
1299 (should (string-equal (file-remote-p "/[/]" 'localname
) ""))
1300 (should (string-equal (file-remote-p "/[/]" 'hop
) nil
)))
1302 ;; Expand `tramp-default-method' and `tramp-default-user'.
1303 (should (string-equal
1304 (file-remote-p "/[/::1]")
1306 "/[%s/%s@%s]" "default-method" "default-user" "::1")))
1307 (should (string-equal
1308 (file-remote-p "/[/::1]" 'method
) "default-method"))
1309 (should (string-equal
1310 (file-remote-p "/[/::1]" 'user
) "default-user"))
1311 (should (string-equal (file-remote-p "/[/::1]" 'host
) "::1"))
1312 (should (string-equal (file-remote-p "/[/::1]" 'localname
) ""))
1313 (should (string-equal (file-remote-p "/[/::1]" 'hop
) nil
))
1315 ;; Expand `tramp-default-method'.
1316 (should (string-equal
1317 (file-remote-p "/[/user@::1]")
1318 (format "/[%s/%s@%s]" "default-method" "user" "::1")))
1319 (should (string-equal
1320 (file-remote-p "/[/user@::1]" 'method
) "default-method"))
1321 (should (string-equal (file-remote-p "/[/user@::1]" 'user
) "user"))
1322 (should (string-equal (file-remote-p "/[/user@::1]" 'host
) "::1"))
1323 (should (string-equal (file-remote-p "/[/user@::1]" 'localname
) ""))
1324 (should (string-equal (file-remote-p "/[/user@::1]" 'hop
) nil
))
1326 ;; Expand `tramp-default-method', `tramp-default-user' and
1327 ;; `tramp-default-host'.
1328 (should (string-equal
1329 (file-remote-p "/[-/]")
1332 "default-method" "default-user" "default-host")))
1333 (should (string-equal
1334 (file-remote-p "/[-/]" 'method
) "default-method"))
1335 (should (string-equal (file-remote-p "/[-/]" 'user
) "default-user"))
1336 (should (string-equal (file-remote-p "/[-/]" 'host
) "default-host"))
1337 (should (string-equal (file-remote-p "/[-/]" 'localname
) ""))
1338 (should (string-equal (file-remote-p "/[-/]" 'hop
) nil
))
1340 ;; Expand `tramp-default-method' and `tramp-default-user'.
1341 (let ((tramp-default-host "::1"))
1342 (should (string-equal
1343 (file-remote-p "/[-/]")
1346 "default-method" "default-user" "::1")))
1347 (should (string-equal
1348 (file-remote-p "/[-/]" 'method
) "default-method"))
1349 (should (string-equal (file-remote-p "/[-/]" 'user
) "default-user"))
1350 (should (string-equal (file-remote-p "/[-/]" 'host
) "::1"))
1351 (should (string-equal (file-remote-p "/[-/]" 'localname
) ""))
1352 (should (string-equal (file-remote-p "/[-/]" 'hop
) nil
)))
1354 ;; Expand `tramp-default-method' and `tramp-default-user'.
1355 (should (string-equal
1356 (file-remote-p "/[-/::1]")
1358 "/[%s/%s@%s]" "default-method" "default-user" "::1")))
1359 (should (string-equal
1360 (file-remote-p "/[-/::1]" 'method
) "default-method"))
1361 (should (string-equal
1362 (file-remote-p "/[-/::1]" 'user
) "default-user"))
1363 (should (string-equal (file-remote-p "/[-/::1]" 'host
) "::1"))
1364 (should (string-equal (file-remote-p "/[-/::1]" 'localname
) ""))
1365 (should (string-equal (file-remote-p "/[-/::1]" 'hop
) nil
))
1367 ;; Expand `tramp-default-method'.
1368 (should (string-equal
1369 (file-remote-p "/[-/user@::1]")
1370 (format "/[%s/%s@%s]" "default-method" "user" "::1")))
1371 (should (string-equal
1372 (file-remote-p "/[-/user@::1]" 'method
) "default-method"))
1373 (should (string-equal (file-remote-p "/[-/user@::1]" 'user
) "user"))
1374 (should (string-equal (file-remote-p "/[-/user@::1]" 'host
) "::1"))
1375 (should (string-equal (file-remote-p "/[-/user@::1]" 'localname
) ""))
1376 (should (string-equal (file-remote-p "/[-/user@::1]" 'hop
) nil
))
1378 ;; Expand `tramp-default-user'.
1379 (should (string-equal
1380 (file-remote-p "/[method/::1]")
1381 (format "/[%s/%s@%s]" "method" "default-user" "::1")))
1382 (should (string-equal
1383 (file-remote-p "/[method/::1]" 'method
) "method"))
1384 (should (string-equal
1385 (file-remote-p "/[method/::1]" 'user
) "default-user"))
1386 (should (string-equal (file-remote-p "/[method/::1]" 'host
) "::1"))
1387 (should (string-equal (file-remote-p "/[method/::1]" 'localname
) ""))
1388 (should (string-equal (file-remote-p "/[method/::1]" 'hop
) nil
))
1391 (should (string-equal
1392 (file-remote-p "/[method/user@::1]")
1393 (format "/[%s/%s@%s]" "method" "user" "::1")))
1394 (should (string-equal
1395 (file-remote-p "/[method/user@::1]" 'method
) "method"))
1396 (should (string-equal
1397 (file-remote-p "/[method/user@::1]" 'user
) "user"))
1398 (should (string-equal
1399 (file-remote-p "/[method/user@::1]" 'host
) "::1"))
1400 (should (string-equal
1401 (file-remote-p "/[method/user@::1]" 'localname
) ""))
1402 (should (string-equal (file-remote-p "/[method/user@::1]" 'hop
) nil
))
1404 ;; Local file name part.
1405 (should (string-equal (file-remote-p "/[/host]/:" 'localname
) "/:"))
1406 (should (string-equal (file-remote-p "/[-/host]/:" 'localname
) "/:"))
1407 (should (string-equal (file-remote-p "/[method/]:" 'localname
) ":"))
1408 (should (string-equal (file-remote-p "/[method/] " 'localname
) " "))
1409 (should (string-equal
1410 (file-remote-p "/[method/]file" 'localname
) "file"))
1411 (should (string-equal
1412 (file-remote-p "/[method/]/path/to/file" 'localname
)
1419 "/[method1/user1@host1|method2/user2@host2]/path/to/file")
1420 (format "/[%s/%s@%s|%s/%s@%s]"
1421 "method1" "user1" "host1" "method2" "user2" "host2")))
1425 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'method
)
1430 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'user
)
1435 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'host
)
1440 "/[method1/user1@host1|method2/user2@host2]/path/to/file"
1446 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'hop
)
1448 "method1" "user1" "host1")))
1454 "/[method1/user1@host1"
1455 "|method2/user2@host2"
1456 "|method3/user3@host3]/path/to/file"))
1457 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1458 "method1" "user1" "host1"
1459 "method2" "user2" "host2"
1460 "method3" "user3" "host3")))
1465 "/[method1/user1@host1"
1466 "|method2/user2@host2"
1467 "|method3/user3@host3]/path/to/file")
1474 "/[method1/user1@host1"
1475 "|method2/user2@host2"
1476 "|method3/user3@host3]/path/to/file")
1483 "/[method1/user1@host1"
1484 "|method2/user2@host2"
1485 "|method3/user3@host3]/path/to/file")
1492 "/[method1/user1@host1"
1493 "|method2/user2@host2"
1494 "|method3/user3@host3]/path/to/file")
1501 "/[method1/user1@host1"
1502 "|method2/user2@host2"
1503 "|method3/user3@host3]/path/to/file")
1505 (format "%s/%s@%s|%s/%s@%s|"
1506 "method1" "user1" "host1" "method2" "user2" "host2"))))
1509 (tramp-change-syntax syntax
))))
1511 (ert-deftest tramp-test03-file-name-defaults
()
1512 "Check default values for some methods."
1513 ;; Default values in tramp-adb.el.
1514 (should (string-equal (file-remote-p "/adb::" 'host
) ""))
1515 ;; Default values in tramp-ftp.el.
1516 (should (string-equal (file-remote-p "/-:ftp.host:" 'method
) "ftp"))
1517 (dolist (u '("ftp" "anonymous"))
1518 (should (string-equal (file-remote-p (format "/-:%s@:" u
) 'method
) "ftp")))
1519 ;; Default values in tramp-gvfs.el.
1520 (when (and (load "tramp-gvfs" 'noerror
'nomessage
)
1521 (symbol-value 'tramp-gvfs-enabled
))
1522 (should (string-equal (file-remote-p "/synce::" 'user
) nil
)))
1523 ;; Default values in tramp-sh.el.
1524 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
1526 (string-equal (file-remote-p (format "/-:root@%s:" h
) 'method
) "su")))
1527 (dolist (m '("su" "sudo" "ksu"))
1528 (should (string-equal (file-remote-p (format "/%s::" m
) 'user
) "root")))
1529 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
1531 (string-equal (file-remote-p (format "/%s::" m
) 'user
) (user-login-name))))
1532 ;; Default values in tramp-smb.el.
1533 (should (string-equal (file-remote-p "/smb::" 'user
) nil
)))
1535 (ert-deftest tramp-test04-substitute-in-file-name
()
1536 "Check `substitute-in-file-name'."
1537 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
1540 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
1542 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
1543 ;; Quoting local part.
1546 (substitute-in-file-name "/method:host:/://foo") "/method:host:/://foo"))
1549 (substitute-in-file-name "/method:host:/:/path//foo")
1550 "/method:host:/:/path//foo"))
1553 (substitute-in-file-name "/method:host:/:/path///foo")
1554 "/method:host:/:/path///foo"))
1558 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
1560 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
1561 ;; Quoting local part.
1564 (substitute-in-file-name "/method:host:/:/path/~/foo")
1565 "/method:host:/:/path/~/foo"))
1568 (substitute-in-file-name "/method:host:/:/path//~/foo")
1569 "/method:host:/:/path//~/foo"))
1571 (let (process-environment)
1574 (substitute-in-file-name "/method:host:/path/$FOO")
1575 "/method:host:/path/$FOO"))
1576 (setenv "FOO" "bla")
1579 (substitute-in-file-name "/method:host:/path/$FOO")
1580 "/method:host:/path/bla"))
1583 (substitute-in-file-name "/method:host:/path/$$FOO")
1584 "/method:host:/path/$FOO"))
1585 ;; Quoting local part.
1588 (substitute-in-file-name "/method:host:/:/path/$FOO")
1589 "/method:host:/:/path/$FOO"))
1590 (setenv "FOO" "bla")
1593 (substitute-in-file-name "/method:host:/:/path/$FOO")
1594 "/method:host:/:/path/$FOO"))
1597 (substitute-in-file-name "/method:host:/:/path/$$FOO")
1598 "/method:host:/:/path/$$FOO"))))
1600 (ert-deftest tramp-test05-expand-file-name
()
1601 "Check `expand-file-name'."
1604 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
1607 (expand-file-name "/method:host:/path/../file") "/method:host:/file"))
1608 ;; Quoting local part.
1611 (expand-file-name "/method:host:/:/path/./file")
1612 "/method:host:/:/path/file"))
1615 (expand-file-name "/method:host:/:/path/../file") "/method:host:/:/file"))
1618 (expand-file-name "/method:host:/:/~/path/./file")
1619 "/method:host:/:/~/path/file")))
1621 ;; The following test is inspired by Bug#26911. It is rather a bug in
1622 ;; `expand-file-name', and it fails for all Emacs versions. Test
1623 ;; added for later, when it is fixed.
1624 (ert-deftest tramp-test05-expand-file-name-relative
()
1625 "Check `expand-file-name'."
1626 ;; Mark as failed until bug has been fixed.
1627 :expected-result
:failed
1628 (skip-unless (tramp--test-enabled))
1629 ;; These are the methods the test doesn't fail.
1630 (when (or (tramp--test-adb-p) (tramp--test-gvfs-p)
1631 (tramp-smb-file-name-p tramp-test-temporary-file-directory
))
1632 (setf (ert-test-expected-result-type
1633 (ert-get-test 'tramp-test05-expand-file-name-relative
))
1638 (let ((default-directory
1640 (file-remote-p tramp-test-temporary-file-directory
) "/path")))
1641 (expand-file-name ".." "./"))
1642 (concat (file-remote-p tramp-test-temporary-file-directory
) "/"))))
1644 (ert-deftest tramp-test06-directory-file-name
()
1645 "Check `directory-file-name'.
1646 This checks also `file-name-as-directory', `file-name-directory',
1647 `file-name-nondirectory' and `unhandled-file-name-directory'."
1650 (directory-file-name "/method:host:/path/to/file")
1651 "/method:host:/path/to/file"))
1654 (directory-file-name "/method:host:/path/to/file/")
1655 "/method:host:/path/to/file"))
1658 (file-name-as-directory "/method:host:/path/to/file")
1659 "/method:host:/path/to/file/"))
1662 (file-name-as-directory "/method:host:/path/to/file/")
1663 "/method:host:/path/to/file/"))
1666 (file-name-directory "/method:host:/path/to/file")
1667 "/method:host:/path/to/"))
1670 (file-name-directory "/method:host:/path/to/file/")
1671 "/method:host:/path/to/file/"))
1673 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
1675 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
1677 (unhandled-file-name-directory "/method:host:/path/to/file"))
1680 (when (tramp--test-enabled) ;; Packages like tramp-gvfs.el might be disabled.
1681 (dolist (n-e '(nil t
))
1682 ;; We must clear `tramp-default-method'. On hydra, it is "ftp",
1683 ;; which ruins the tests.
1684 (let ((non-essential n-e
)
1685 tramp-default-method
)
1690 (file-remote-p tramp-test-temporary-file-directory
'method
))
1693 (file-remote-p tramp-test-temporary-file-directory
'host
))))
1694 (should (string-equal (directory-file-name file
) file
))
1697 (file-name-as-directory file
)
1698 (if (tramp-completion-mode-p)
1699 file
(concat file
"./"))))
1700 (should (string-equal (file-name-directory file
) file
))
1701 (should (string-equal (file-name-nondirectory file
) "")))))))
1703 (ert-deftest tramp-test07-file-exists-p
()
1704 "Check `file-exist-p', `write-region' and `delete-file'."
1705 (skip-unless (tramp--test-enabled))
1707 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1708 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1709 (should-not (file-exists-p tmp-name
))
1710 (write-region "foo" nil tmp-name
)
1711 (should (file-exists-p tmp-name
))
1712 (delete-file tmp-name
)
1713 (should-not (file-exists-p tmp-name
)))))
1715 (ert-deftest tramp-test08-file-local-copy
()
1716 "Check `file-local-copy'."
1717 (skip-unless (tramp--test-enabled))
1719 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1720 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
1724 (write-region "foo" nil tmp-name1
)
1725 (should (setq tmp-name2
(file-local-copy tmp-name1
)))
1727 (insert-file-contents tmp-name2
)
1728 (should (string-equal (buffer-string) "foo")))
1729 ;; Check also that a file transfer with compression works.
1730 (let ((default-directory tramp-test-temporary-file-directory
)
1731 (tramp-copy-size-limit 4)
1732 (tramp-inline-compress-start-size 2))
1733 (delete-file tmp-name2
)
1734 (should (setq tmp-name2
(file-local-copy tmp-name1
)))))
1738 (delete-file tmp-name1
)
1739 (delete-file tmp-name2
))))))
1741 (ert-deftest tramp-test09-insert-file-contents
()
1742 "Check `insert-file-contents'."
1743 (skip-unless (tramp--test-enabled))
1745 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1746 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1749 (write-region "foo" nil tmp-name
)
1751 (insert-file-contents tmp-name
)
1752 (should (string-equal (buffer-string) "foo"))
1753 (insert-file-contents tmp-name
)
1754 (should (string-equal (buffer-string) "foofoo"))
1756 (insert-file-contents tmp-name nil
1 3)
1757 (should (string-equal (buffer-string) "oofoofoo"))
1759 (insert-file-contents tmp-name nil nil nil
'replace
)
1760 (should (string-equal (buffer-string) "foo"))))
1763 (ignore-errors (delete-file tmp-name
))))))
1765 (ert-deftest tramp-test10-write-region
()
1766 "Check `write-region'."
1767 (skip-unless (tramp--test-enabled))
1769 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1770 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1773 ;; Write buffer. Use absolute and relative file name.
1776 (write-region nil nil tmp-name
))
1778 (insert-file-contents tmp-name
)
1779 (should (string-equal (buffer-string) "foo")))
1780 (delete-file tmp-name
)
1783 (should-not (file-exists-p tmp-name
))
1784 (let ((default-directory (file-name-directory tmp-name
)))
1785 (should-not (file-exists-p (file-name-nondirectory tmp-name
)))
1786 (write-region nil nil
(file-name-nondirectory tmp-name
))
1787 (should (file-exists-p (file-name-nondirectory tmp-name
))))
1788 (should (file-exists-p tmp-name
)))
1790 (insert-file-contents tmp-name
)
1791 (should (string-equal (buffer-string) "foo")))
1796 (write-region nil nil tmp-name
'append
))
1798 (insert-file-contents tmp-name
)
1799 (should (string-equal (buffer-string) "foobla")))
1802 (write-region nil nil tmp-name
3))
1804 (insert-file-contents tmp-name
)
1805 (should (string-equal (buffer-string) "foobaz")))
1808 (write-region "foo" nil tmp-name
)
1810 (insert-file-contents tmp-name
)
1811 (should (string-equal (buffer-string) "foo")))
1815 (insert "123456789")
1816 (write-region 3 5 tmp-name
))
1818 (insert-file-contents tmp-name
)
1819 (should (string-equal (buffer-string) "34"))))
1822 (ignore-errors (delete-file tmp-name
))))))
1824 (ert-deftest tramp-test11-copy-file
()
1825 "Check `copy-file'."
1826 (skip-unless (tramp--test-enabled))
1828 ;; TODO: The quoted case does not work.
1829 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
1831 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
1832 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
1833 (tmp-name3 (tramp--test-make-temp-name nil quoted
))
1834 (tmp-name4 (tramp--test-make-temp-name 'local quoted
))
1835 (tmp-name5 (tramp--test-make-temp-name 'local quoted
)))
1837 ;; Copy on remote side.
1840 (write-region "foo" nil tmp-name1
)
1841 (copy-file tmp-name1 tmp-name2
)
1842 (should (file-exists-p tmp-name2
))
1844 (insert-file-contents tmp-name2
)
1845 (should (string-equal (buffer-string) "foo")))
1846 (should-error (copy-file tmp-name1 tmp-name2
))
1847 (copy-file tmp-name1 tmp-name2
'ok
)
1848 (make-directory tmp-name3
)
1849 (copy-file tmp-name1 tmp-name3
)
1852 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name3
))))
1855 (ignore-errors (delete-file tmp-name1
))
1856 (ignore-errors (delete-file tmp-name2
))
1857 (ignore-errors (delete-directory tmp-name3
'recursive
)))
1859 ;; Copy from remote side to local side.
1862 (write-region "foo" nil tmp-name1
)
1863 (copy-file tmp-name1 tmp-name4
)
1864 (should (file-exists-p tmp-name4
))
1866 (insert-file-contents tmp-name4
)
1867 (should (string-equal (buffer-string) "foo")))
1868 (should-error (copy-file tmp-name1 tmp-name4
))
1869 (copy-file tmp-name1 tmp-name4
'ok
)
1870 (make-directory tmp-name5
)
1871 (copy-file tmp-name1 tmp-name5
)
1874 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name5
))))
1877 (ignore-errors (delete-file tmp-name1
))
1878 (ignore-errors (delete-file tmp-name4
))
1879 (ignore-errors (delete-directory tmp-name5
'recursive
)))
1881 ;; Copy from local side to remote side.
1884 (write-region "foo" nil tmp-name4 nil
'nomessage
)
1885 (copy-file tmp-name4 tmp-name1
)
1886 (should (file-exists-p tmp-name1
))
1888 (insert-file-contents tmp-name1
)
1889 (should (string-equal (buffer-string) "foo")))
1890 (should-error (copy-file tmp-name4 tmp-name1
))
1891 (copy-file tmp-name4 tmp-name1
'ok
)
1892 (make-directory tmp-name3
)
1893 (copy-file tmp-name4 tmp-name3
)
1896 (expand-file-name (file-name-nondirectory tmp-name4
) tmp-name3
))))
1899 (ignore-errors (delete-file tmp-name1
))
1900 (ignore-errors (delete-file tmp-name4
))
1901 (ignore-errors (delete-directory tmp-name3
'recursive
))))))
1903 (ert-deftest tramp-test12-rename-file
()
1904 "Check `rename-file'."
1905 (skip-unless (tramp--test-enabled))
1907 ;; TODO: The quoted case does not work.
1908 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
1910 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
1911 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
1912 (tmp-name3 (tramp--test-make-temp-name nil quoted
))
1913 (tmp-name4 (tramp--test-make-temp-name 'local quoted
))
1914 (tmp-name5 (tramp--test-make-temp-name 'local quoted
)))
1916 ;; Rename on remote side.
1919 (write-region "foo" nil tmp-name1
)
1920 (rename-file tmp-name1 tmp-name2
)
1921 (should-not (file-exists-p tmp-name1
))
1922 (should (file-exists-p tmp-name2
))
1924 (insert-file-contents tmp-name2
)
1925 (should (string-equal (buffer-string) "foo")))
1926 (write-region "foo" nil tmp-name1
)
1927 (should-error (rename-file tmp-name1 tmp-name2
))
1928 (rename-file tmp-name1 tmp-name2
'ok
)
1929 (should-not (file-exists-p tmp-name1
))
1930 (write-region "foo" nil tmp-name1
)
1931 (make-directory tmp-name3
)
1932 (rename-file tmp-name1 tmp-name3
)
1933 (should-not (file-exists-p tmp-name1
))
1936 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name3
))))
1939 (ignore-errors (delete-file tmp-name1
))
1940 (ignore-errors (delete-file tmp-name2
))
1941 (ignore-errors (delete-directory tmp-name3
'recursive
)))
1943 ;; Rename from remote side to local side.
1946 (write-region "foo" nil tmp-name1
)
1947 (rename-file tmp-name1 tmp-name4
)
1948 (should-not (file-exists-p tmp-name1
))
1949 (should (file-exists-p tmp-name4
))
1951 (insert-file-contents tmp-name4
)
1952 (should (string-equal (buffer-string) "foo")))
1953 (write-region "foo" nil tmp-name1
)
1954 (should-error (rename-file tmp-name1 tmp-name4
))
1955 (rename-file tmp-name1 tmp-name4
'ok
)
1956 (should-not (file-exists-p tmp-name1
))
1957 (write-region "foo" nil tmp-name1
)
1958 (make-directory tmp-name5
)
1959 (rename-file tmp-name1 tmp-name5
)
1960 (should-not (file-exists-p tmp-name1
))
1963 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name5
))))
1966 (ignore-errors (delete-file tmp-name1
))
1967 (ignore-errors (delete-file tmp-name4
))
1968 (ignore-errors (delete-directory tmp-name5
'recursive
)))
1970 ;; Rename from local side to remote side.
1973 (write-region "foo" nil tmp-name4 nil
'nomessage
)
1974 (rename-file tmp-name4 tmp-name1
)
1975 (should-not (file-exists-p tmp-name4
))
1976 (should (file-exists-p tmp-name1
))
1978 (insert-file-contents tmp-name1
)
1979 (should (string-equal (buffer-string) "foo")))
1980 (write-region "foo" nil tmp-name4 nil
'nomessage
)
1981 (should-error (rename-file tmp-name4 tmp-name1
))
1982 (rename-file tmp-name4 tmp-name1
'ok
)
1983 (should-not (file-exists-p tmp-name4
))
1984 (write-region "foo" nil tmp-name4 nil
'nomessage
)
1985 (make-directory tmp-name3
)
1986 (rename-file tmp-name4 tmp-name3
)
1987 (should-not (file-exists-p tmp-name4
))
1990 (expand-file-name (file-name-nondirectory tmp-name4
) tmp-name3
))))
1993 (ignore-errors (delete-file tmp-name1
))
1994 (ignore-errors (delete-file tmp-name4
))
1995 (ignore-errors (delete-directory tmp-name3
'recursive
))))))
1997 (ert-deftest tramp-test13-make-directory
()
1998 "Check `make-directory'.
1999 This tests also `file-directory-p' and `file-accessible-directory-p'."
2000 (skip-unless (tramp--test-enabled))
2002 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2003 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2004 (tmp-name2 (expand-file-name "foo/bar" tmp-name1
)))
2007 (make-directory tmp-name1
)
2008 (should (file-directory-p tmp-name1
))
2009 (should (file-accessible-directory-p tmp-name1
))
2010 (should-error (make-directory tmp-name2
))
2011 (make-directory tmp-name2
'parents
)
2012 (should (file-directory-p tmp-name2
))
2013 (should (file-accessible-directory-p tmp-name2
)))
2016 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2018 (ert-deftest tramp-test14-delete-directory
()
2019 "Check `delete-directory'."
2020 (skip-unless (tramp--test-enabled))
2022 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2023 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2024 ;; Delete empty directory.
2025 (make-directory tmp-name
)
2026 (should (file-directory-p tmp-name
))
2027 (delete-directory tmp-name
)
2028 (should-not (file-directory-p tmp-name
))
2029 ;; Delete non-empty directory.
2030 (make-directory tmp-name
)
2031 (should (file-directory-p tmp-name
))
2032 (write-region "foo" nil
(expand-file-name "bla" tmp-name
))
2033 (should (file-exists-p (expand-file-name "bla" tmp-name
)))
2034 (should-error (delete-directory tmp-name
))
2035 (delete-directory tmp-name
'recursive
)
2036 (should-not (file-directory-p tmp-name
)))))
2038 (ert-deftest tramp-test15-copy-directory
()
2039 "Check `copy-directory'."
2040 (skip-unless (tramp--test-enabled))
2042 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2043 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2044 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2045 (tmp-name3 (expand-file-name
2046 (file-name-nondirectory tmp-name1
) tmp-name2
))
2047 (tmp-name4 (expand-file-name "foo" tmp-name1
))
2048 (tmp-name5 (expand-file-name "foo" tmp-name2
))
2049 (tmp-name6 (expand-file-name "foo" tmp-name3
)))
2051 ;; Copy complete directory.
2054 ;; Copy empty directory.
2055 (make-directory tmp-name1
)
2056 (write-region "foo" nil tmp-name4
)
2057 (should (file-directory-p tmp-name1
))
2058 (should (file-exists-p tmp-name4
))
2059 (copy-directory tmp-name1 tmp-name2
)
2060 (should (file-directory-p tmp-name2
))
2061 (should (file-exists-p tmp-name5
))
2062 ;; Target directory does exist already.
2063 (copy-directory tmp-name1 tmp-name2
)
2064 (should (file-directory-p tmp-name3
))
2065 (should (file-exists-p tmp-name6
)))
2069 (delete-directory tmp-name1
'recursive
)
2070 (delete-directory tmp-name2
'recursive
)))
2072 ;; Copy directory contents.
2075 ;; Copy empty directory.
2076 (make-directory tmp-name1
)
2077 (write-region "foo" nil tmp-name4
)
2078 (should (file-directory-p tmp-name1
))
2079 (should (file-exists-p tmp-name4
))
2080 (copy-directory tmp-name1 tmp-name2 nil
'parents
'contents
)
2081 (should (file-directory-p tmp-name2
))
2082 (should (file-exists-p tmp-name5
))
2083 ;; Target directory does exist already.
2084 (delete-file tmp-name5
)
2085 (should-not (file-exists-p tmp-name5
))
2086 (copy-directory tmp-name1 tmp-name2 nil
'parents
'contents
)
2087 (should (file-directory-p tmp-name2
))
2088 (should (file-exists-p tmp-name5
))
2089 (should-not (file-directory-p tmp-name3
))
2090 (should-not (file-exists-p tmp-name6
)))
2094 (delete-directory tmp-name1
'recursive
)
2095 (delete-directory tmp-name2
'recursive
))))))
2097 (ert-deftest tramp-test16-directory-files
()
2098 "Check `directory-files'."
2099 (skip-unless (tramp--test-enabled))
2101 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2103 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2104 (tmp-name2 (expand-file-name "bla" tmp-name1
))
2105 (tmp-name3 (expand-file-name "foo" tmp-name1
)))
2108 (make-directory tmp-name1
)
2109 (write-region "foo" nil tmp-name2
)
2110 (write-region "bla" nil tmp-name3
)
2111 (should (file-directory-p tmp-name1
))
2112 (should (file-exists-p tmp-name2
))
2113 (should (file-exists-p tmp-name3
))
2114 (should (equal (directory-files tmp-name1
) '("." ".." "bla" "foo")))
2115 (should (equal (directory-files tmp-name1
'full
)
2116 `(,(concat tmp-name1
"/.")
2117 ,(concat tmp-name1
"/..")
2118 ,tmp-name2
,tmp-name3
)))
2119 (should (equal (directory-files
2120 tmp-name1 nil directory-files-no-dot-files-regexp
)
2122 (should (equal (directory-files
2123 tmp-name1
'full directory-files-no-dot-files-regexp
)
2124 `(,tmp-name2
,tmp-name3
))))
2127 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2129 (ert-deftest tramp-test17-insert-directory
()
2130 "Check `insert-directory'."
2131 (skip-unless (tramp--test-enabled))
2133 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2135 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2136 (tmp-name2 (expand-file-name "foo" tmp-name1
))
2137 ;; We test for the summary line. Keyword "total" could be localized.
2138 (process-environment
2139 (append '("LANG=C" "LANGUAGE=C" "LC_ALL=C") process-environment
)))
2142 (make-directory tmp-name1
)
2143 (write-region "foo" nil tmp-name2
)
2144 (should (file-directory-p tmp-name1
))
2145 (should (file-exists-p tmp-name2
))
2147 (insert-directory tmp-name1 nil
)
2148 (goto-char (point-min))
2149 (should (looking-at-p (regexp-quote tmp-name1
))))
2151 (insert-directory tmp-name1
"-al")
2152 (goto-char (point-min))
2154 (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1
)))))
2156 (insert-directory (file-name-as-directory tmp-name1
) "-al")
2157 (goto-char (point-min))
2159 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1
)))))
2162 (file-name-as-directory tmp-name1
) "-al" nil
'full-directory-p
)
2163 (goto-char (point-min))
2167 ;; There might be a summary line.
2168 "\\(total.+[[:digit:]]+\n\\)?"
2169 ;; We don't know in which order ".", ".." and "foo" appear.
2170 "\\(.+ \\(\\.?\\.\\|foo\\)\n\\)\\{3\\}")))))
2173 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2175 (ert-deftest tramp-test18-file-attributes
()
2176 "Check `file-attributes'.
2177 This tests also `file-readable-p', `file-regular-p' and
2178 `file-ownership-preserved-p'."
2179 (skip-unless (tramp--test-enabled))
2181 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2182 ;; We must use `file-truename' for the temporary directory,
2183 ;; because it could be located on a symlinked directory. This
2184 ;; would let the test fail.
2185 (let* ((tramp-test-temporary-file-directory
2186 (file-truename tramp-test-temporary-file-directory
))
2187 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
2188 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2189 ;; File name with "//".
2193 (file-remote-p tmp-name1
)
2194 (replace-regexp-in-string
2195 "/" "//" (file-remote-p tmp-name1
'localname
))))
2199 ;; `file-ownership-preserved-p' should return t for
2200 ;; non-existing files. It is implemented only in tramp-sh.el.
2201 (when (tramp--test-sh-p)
2202 (should (file-ownership-preserved-p tmp-name1
'group
)))
2203 (write-region "foo" nil tmp-name1
)
2204 (should (file-exists-p tmp-name1
))
2205 (should (file-readable-p tmp-name1
))
2206 (should (file-regular-p tmp-name1
))
2207 (when (tramp--test-sh-p)
2208 (should (file-ownership-preserved-p tmp-name1
'group
)))
2210 ;; We do not test inodes and device numbers.
2211 (setq attr
(file-attributes tmp-name1
))
2212 (should (consp attr
))
2213 (should (null (car attr
)))
2214 (should (numberp (nth 1 attr
))) ;; Link.
2215 (should (numberp (nth 2 attr
))) ;; Uid.
2216 (should (numberp (nth 3 attr
))) ;; Gid.
2217 ;; Last access time.
2218 (should (stringp (current-time-string (nth 4 attr
))))
2219 ;; Last modification time.
2220 (should (stringp (current-time-string (nth 5 attr
))))
2221 ;; Last status change time.
2222 (should (stringp (current-time-string (nth 6 attr
))))
2223 (should (numberp (nth 7 attr
))) ;; Size.
2224 (should (stringp (nth 8 attr
))) ;; Modes.
2226 (setq attr
(file-attributes tmp-name1
'string
))
2227 (should (stringp (nth 2 attr
))) ;; Uid.
2228 (should (stringp (nth 3 attr
))) ;; Gid.
2232 (when (tramp--test-sh-p)
2233 (should (file-ownership-preserved-p tmp-name2
'group
)))
2234 (make-symbolic-link tmp-name1 tmp-name2
)
2235 (should (file-exists-p tmp-name2
))
2236 (should (file-symlink-p tmp-name2
))
2237 (when (tramp--test-sh-p)
2238 (should (file-ownership-preserved-p tmp-name2
'group
)))
2239 (setq attr
(file-attributes tmp-name2
))
2243 (if quoted
'tramp-compat-file-name-quote
'identity
)
2245 (file-remote-p (file-truename tmp-name1
) 'localname
)))
2246 (delete-file tmp-name2
))
2248 (should (string-equal (error-message-string err
)
2249 "make-symbolic-link not supported"))))
2251 ;; Check, that "//" in symlinks are handled properly.
2253 (let ((default-directory tramp-test-temporary-file-directory
))
2257 (tramp-file-name-localname
2258 (tramp-dissect-file-name tmp-name3
))
2259 (tramp-file-name-localname
2260 (tramp-dissect-file-name tmp-name2
)))
2262 (when (file-symlink-p tmp-name2
)
2263 (setq attr
(file-attributes tmp-name2
))
2267 (tramp-file-name-localname
2268 (tramp-dissect-file-name tmp-name3
))))
2269 (delete-file tmp-name2
))
2271 (when (tramp--test-sh-p)
2272 (should (file-ownership-preserved-p tmp-name1
'group
)))
2273 (delete-file tmp-name1
)
2274 (make-directory tmp-name1
)
2275 (should (file-exists-p tmp-name1
))
2276 (should (file-readable-p tmp-name1
))
2277 (should-not (file-regular-p tmp-name1
))
2278 (when (tramp--test-sh-p)
2279 (should (file-ownership-preserved-p tmp-name1
'group
)))
2280 (setq attr
(file-attributes tmp-name1
))
2281 (should (eq (car attr
) t
)))
2284 (ignore-errors (delete-directory tmp-name1
))
2285 (ignore-errors (delete-file tmp-name1
))
2286 (ignore-errors (delete-file tmp-name2
))))))
2288 (ert-deftest tramp-test19-directory-files-and-attributes
()
2289 "Check `directory-files-and-attributes'."
2290 (skip-unless (tramp--test-enabled))
2292 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2293 ;; `directory-files-and-attributes' contains also values for
2294 ;; "../". Ensure that this doesn't change during tests, for
2295 ;; example due to handling temporary files.
2296 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2297 (tmp-name2 (expand-file-name "bla" tmp-name1
))
2301 (make-directory tmp-name1
)
2302 (should (file-directory-p tmp-name1
))
2303 (make-directory tmp-name2
)
2304 (should (file-directory-p tmp-name2
))
2305 (write-region "foo" nil
(expand-file-name "foo" tmp-name2
))
2306 (write-region "bar" nil
(expand-file-name "bar" tmp-name2
))
2307 (write-region "boz" nil
(expand-file-name "boz" tmp-name2
))
2308 (setq attr
(directory-files-and-attributes tmp-name2
))
2309 (should (consp attr
))
2310 ;; Dumb remote shells without perl(1) or stat(1) are not
2311 ;; able to return the date correctly. They say "don't know".
2316 5 (file-attributes (expand-file-name (car elt
) tmp-name2
)))
2319 (equal (file-attributes (expand-file-name (car elt
) tmp-name2
))
2321 (setq attr
(directory-files-and-attributes tmp-name2
'full
))
2323 (unless (equal (nth 5 (file-attributes (car elt
))) '(0 0))
2325 (equal (file-attributes (car elt
)) (cdr elt
)))))
2326 (setq attr
(directory-files-and-attributes tmp-name2 nil
"^b"))
2327 (should (equal (mapcar 'car attr
) '("bar" "boz"))))
2330 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2332 (ert-deftest tramp-test20-file-modes
()
2333 "Check `file-modes'.
2334 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
2335 (skip-unless (tramp--test-enabled))
2336 (skip-unless (tramp--test-sh-p))
2338 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2339 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2342 (write-region "foo" nil tmp-name
)
2343 (should (file-exists-p tmp-name
))
2344 (set-file-modes tmp-name
#o777
)
2345 (should (= (file-modes tmp-name
) #o777
))
2346 (should (file-executable-p tmp-name
))
2347 (should (file-writable-p tmp-name
))
2348 (set-file-modes tmp-name
#o444
)
2349 (should (= (file-modes tmp-name
) #o444
))
2350 (should-not (file-executable-p tmp-name
))
2351 ;; A file is always writable for user "root".
2352 (unless (zerop (nth 2 (file-attributes tmp-name
)))
2353 (should-not (file-writable-p tmp-name
))))
2356 (ignore-errors (delete-file tmp-name
))))))
2358 (ert-deftest tramp-test21-file-links
()
2359 "Check `file-symlink-p'.
2360 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2361 (skip-unless (tramp--test-enabled))
2363 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2364 ;; We must use `file-truename' for the temporary directory,
2365 ;; because it could be located on a symlinked directory. This
2366 ;; would let the test fail.
2367 (let* ((tramp-test-temporary-file-directory
2368 (file-truename tramp-test-temporary-file-directory
))
2369 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
2370 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2371 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
2373 ;; Check `make-symbolic-link'.
2376 (write-region "foo" nil tmp-name1
)
2377 (should (file-exists-p tmp-name1
))
2378 ;; Method "smb" supports `make-symbolic-link' only if the
2379 ;; remote host has CIFS capabilities. tramp-adb.el and
2380 ;; tramp-gvfs.el do not support symbolic links at all.
2382 (make-symbolic-link tmp-name1 tmp-name2
)
2385 (not (string-equal (error-message-string err
)
2386 "make-symbolic-link not supported")))))
2387 (should (file-symlink-p tmp-name2
))
2388 (should-error (make-symbolic-link tmp-name1 tmp-name2
))
2389 (make-symbolic-link tmp-name1 tmp-name2
'ok-if-already-exists
)
2390 (should (file-symlink-p tmp-name2
))
2391 ;; `tmp-name3' is a local file name.
2392 (should-error (make-symbolic-link tmp-name1 tmp-name3
)))
2396 (delete-file tmp-name1
)
2397 (delete-file tmp-name2
)))
2399 ;; Check `add-name-to-file'.
2402 (write-region "foo" nil tmp-name1
)
2403 (should (file-exists-p tmp-name1
))
2404 (add-name-to-file tmp-name1 tmp-name2
)
2405 (should-not (file-symlink-p tmp-name2
))
2406 (should-error (add-name-to-file tmp-name1 tmp-name2
))
2407 (add-name-to-file tmp-name1 tmp-name2
'ok-if-already-exists
)
2408 (should-not (file-symlink-p tmp-name2
))
2409 ;; `tmp-name3' is a local file name.
2410 (should-error (add-name-to-file tmp-name1 tmp-name3
)))
2414 (delete-file tmp-name1
)
2415 (delete-file tmp-name2
)))
2417 ;; Check `file-truename'.
2420 (write-region "foo" nil tmp-name1
)
2421 (should (file-exists-p tmp-name1
))
2422 (make-symbolic-link tmp-name1 tmp-name2
)
2423 (should (file-symlink-p tmp-name2
))
2424 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
2426 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
)))
2427 (should (file-equal-p tmp-name1 tmp-name2
)))
2429 (delete-file tmp-name1
)
2430 (delete-file tmp-name2
)))
2432 ;; `file-truename' shall preserve trailing link of directories.
2433 (unless (file-symlink-p tramp-test-temporary-file-directory
)
2434 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory
))
2435 (dir2 (file-name-as-directory dir1
)))
2436 (should (string-equal (file-truename dir1
) (expand-file-name dir1
)))
2438 (string-equal (file-truename dir2
) (expand-file-name dir2
))))))))
2440 (ert-deftest tramp-test22-file-times
()
2441 "Check `set-file-times' and `file-newer-than-file-p'."
2442 (skip-unless (tramp--test-enabled))
2443 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
2445 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2446 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2447 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2448 (tmp-name3 (tramp--test-make-temp-name nil quoted
)))
2451 (write-region "foo" nil tmp-name1
)
2452 (should (file-exists-p tmp-name1
))
2453 (should (consp (nth 5 (file-attributes tmp-name1
))))
2454 ;; '(0 0) means don't know, and will be replaced by
2455 ;; `current-time'. Therefore, we use '(0 1). We skip the
2456 ;; test, if the remote handler is not able to set the
2458 (skip-unless (set-file-times tmp-name1
'(0 1)))
2459 ;; Dumb remote shells without perl(1) or stat(1) are not
2460 ;; able to return the date correctly. They say "don't know".
2461 (unless (equal (nth 5 (file-attributes tmp-name1
)) '(0 0))
2462 (should (equal (nth 5 (file-attributes tmp-name1
)) '(0 1)))
2463 (write-region "bla" nil tmp-name2
)
2464 (should (file-exists-p tmp-name2
))
2465 (should (file-newer-than-file-p tmp-name2 tmp-name1
))
2466 ;; `tmp-name3' does not exist.
2467 (should (file-newer-than-file-p tmp-name2 tmp-name3
))
2468 (should-not (file-newer-than-file-p tmp-name3 tmp-name1
))))
2472 (delete-file tmp-name1
)
2473 (delete-file tmp-name2
))))))
2475 (ert-deftest tramp-test23-visited-file-modtime
()
2476 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
2477 (skip-unless (tramp--test-enabled))
2479 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2480 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2483 (write-region "foo" nil tmp-name
)
2484 (should (file-exists-p tmp-name
))
2486 (insert-file-contents tmp-name
)
2487 (should (verify-visited-file-modtime))
2488 (set-visited-file-modtime '(0 1))
2489 (should (verify-visited-file-modtime))
2490 (should (equal (visited-file-modtime) '(0 1 0 0)))))
2493 (ignore-errors (delete-file tmp-name
))))))
2495 (ert-deftest tramp-test24-file-name-completion
()
2496 "Check `file-name-completion' and `file-name-all-completions'."
2497 (skip-unless (tramp--test-enabled))
2499 ;; Method and host name in completion mode. This kind of completion
2500 ;; does not work on MS Windows.
2501 (when (not (memq system-type
'(cygwin windows-nt
)))
2502 (let ((method (file-remote-p tramp-test-temporary-file-directory
'method
))
2503 (host (file-remote-p tramp-test-temporary-file-directory
'host
))
2504 (orig-syntax tramp-syntax
))
2505 (when (and (stringp host
) (string-match tramp-host-with-port-regexp host
))
2506 (setq host
(match-string 1 host
)))
2511 (if tramp--test-expensive-test
2512 (tramp-syntax-values) `(,orig-syntax
)))
2513 (tramp-change-syntax syntax
)
2514 (let ;; This is needed for the `simplified' syntax.
2516 (if (zerop (length (tramp-method-regexp)))
2517 "" tramp-default-method-marker
))
2518 ;; This is needed for the `separate' syntax.
2519 (prefix-format (substring (tramp-prefix-format) 1)))
2520 ;; Complete method name.
2521 (unless (or (zerop (length method
))
2522 (zerop (length (tramp-method-regexp))))
2525 (concat prefix-format method
(tramp-postfix-method-format))
2526 (file-name-all-completions
2527 (concat prefix-format
(substring method
0 1)) "/"))))
2528 ;; Complete host name for default method. With gvfs
2529 ;; based methods, host name will be determined as
2530 ;; host.local, so we omit the test.
2531 (let ((tramp-default-method (or method tramp-default-method
)))
2532 (unless (or (zerop (length host
))
2533 (tramp--test-gvfs-p tramp-default-method
))
2537 prefix-format method-marker
(tramp-postfix-method-format)
2538 host
(tramp-postfix-host-format))
2539 (file-name-all-completions
2541 prefix-format method-marker
(tramp-postfix-method-format)
2542 (substring host
0 1))
2544 ;; Complete host name.
2545 (unless (or (zerop (length method
))
2546 (zerop (length (tramp-method-regexp)))
2547 (zerop (length host
))
2548 (tramp--test-gvfs-p method
))
2552 prefix-format method
(tramp-postfix-method-format)
2553 host
(tramp-postfix-host-format))
2554 (file-name-all-completions
2555 (concat prefix-format method
(tramp-postfix-method-format))
2559 (tramp-change-syntax orig-syntax
))))
2561 (dolist (n-e '(nil t
))
2562 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2563 (let ((non-essential n-e
)
2564 (tmp-name (tramp--test-make-temp-name nil quoted
)))
2569 (make-directory tmp-name
)
2570 (should (file-directory-p tmp-name
))
2571 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
2572 (should (file-exists-p (expand-file-name "foo" tmp-name
)))
2573 (write-region "bar" nil
(expand-file-name "bold" tmp-name
))
2574 (should (file-exists-p (expand-file-name "bold" tmp-name
)))
2575 (make-directory (expand-file-name "boz" tmp-name
))
2576 (should (file-directory-p (expand-file-name "boz" tmp-name
)))
2577 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
2578 (should (equal (file-name-completion "foo" tmp-name
) t
))
2579 (should (equal (file-name-completion "b" tmp-name
) "bo"))
2580 (should-not (file-name-completion "a" tmp-name
))
2583 (file-name-completion "b" tmp-name
'file-directory-p
) "boz/"))
2585 (equal (file-name-all-completions "fo" tmp-name
) '("foo")))
2588 (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
2590 (should-not (file-name-all-completions "a" tmp-name
))
2591 ;; `completion-regexp-list' restricts the completion to
2592 ;; files which match all expressions in this list.
2593 (let ((completion-regexp-list
2594 `(,directory-files-no-dot-files-regexp
"b")))
2596 (equal (file-name-completion "" tmp-name
) "bo"))
2599 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
2601 ;; `file-name-completion' ignores file names that end in
2602 ;; any string in `completion-ignored-extensions'.
2603 (let ((completion-ignored-extensions '(".ext")))
2604 (write-region "foo" nil
(expand-file-name "foo.ext" tmp-name
))
2605 (should (file-exists-p (expand-file-name "foo.ext" tmp-name
)))
2606 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
2607 (should (equal (file-name-completion "foo" tmp-name
) t
))
2609 (equal (file-name-completion "foo." tmp-name
) "foo.ext"))
2610 (should (equal (file-name-completion "foo.ext" tmp-name
) t
))
2611 ;; `file-name-all-completions' is not affected.
2614 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
2615 '("../" "./" "bold" "boz/" "foo" "foo.ext")))))
2618 (ignore-errors (delete-directory tmp-name
'recursive
)))))))
2620 (ert-deftest tramp-test25-load
()
2622 (skip-unless (tramp--test-enabled))
2624 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2625 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2628 (load tmp-name
'noerror
'nomessage
)
2629 (should-not (featurep 'tramp-test-load
))
2630 (write-region "(provide 'tramp-test-load)" nil tmp-name
)
2631 ;; `load' in lread.c does not pass `must-suffix'. Why?
2633 ;; (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
2634 (load tmp-name nil
'nomessage
'nosuffix
)
2635 (should (featurep 'tramp-test-load
)))
2639 (and (featurep 'tramp-test-load
) (unload-feature 'tramp-test-load
))
2640 (delete-file tmp-name
))))))
2642 (ert-deftest tramp-test26-process-file
()
2643 "Check `process-file'."
2644 :tags
'(:expensive-test
)
2645 (skip-unless (tramp--test-enabled))
2646 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
2648 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2649 (let* ((tmp-name (tramp--test-make-temp-name nil quoted
))
2650 (fnnd (file-name-nondirectory tmp-name
))
2651 (default-directory tramp-test-temporary-file-directory
)
2652 kill-buffer-query-functions
)
2655 ;; We cannot use "/bin/true" and "/bin/false"; those paths
2656 ;; do not exist on hydra.
2657 (should (zerop (process-file "true")))
2658 (should-not (zerop (process-file "false")))
2659 (should-not (zerop (process-file "binary-does-not-exist")))
2661 (write-region "foo" nil tmp-name
)
2662 (should (file-exists-p tmp-name
))
2663 (should (zerop (process-file "ls" nil t nil fnnd
)))
2664 ;; `ls' could produce colorized output.
2665 (goto-char (point-min))
2667 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
2668 (replace-match "" nil nil
))
2669 (should (string-equal (format "%s\n" fnnd
) (buffer-string)))
2670 (should-not (get-buffer-window (current-buffer) t
))
2672 ;; Second run. The output must be appended.
2673 (goto-char (point-max))
2674 (should (zerop (process-file "ls" nil t t fnnd
)))
2675 ;; `ls' could produce colorized output.
2676 (goto-char (point-min))
2678 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
2679 (replace-match "" nil nil
))
2681 (string-equal (format "%s\n%s\n" fnnd fnnd
) (buffer-string)))
2682 ;; A non-nil DISPLAY must not raise the buffer.
2683 (should-not (get-buffer-window (current-buffer) t
))))
2686 (ignore-errors (delete-file tmp-name
))))))
2688 (ert-deftest tramp-test27-start-file-process
()
2689 "Check `start-file-process'."
2690 :tags
'(:expensive-test
)
2691 (skip-unless (tramp--test-enabled))
2692 (skip-unless (tramp--test-sh-p))
2694 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2695 (let ((default-directory tramp-test-temporary-file-directory
)
2696 (tmp-name (tramp--test-make-temp-name nil quoted
))
2697 kill-buffer-query-functions proc
)
2700 (setq proc
(start-file-process "test1" (current-buffer) "cat"))
2701 (should (processp proc
))
2702 (should (equal (process-status proc
) 'run
))
2703 (process-send-string proc
"foo")
2704 (process-send-eof proc
)
2706 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
2707 (while (< (- (point-max) (point-min)) (length "foo"))
2708 (accept-process-output proc
0.1)))
2709 (should (string-equal (buffer-string) "foo")))
2712 (ignore-errors (delete-process proc
)))
2716 (write-region "foo" nil tmp-name
)
2717 (should (file-exists-p tmp-name
))
2720 "test2" (current-buffer)
2721 "cat" (file-name-nondirectory tmp-name
)))
2722 (should (processp proc
))
2724 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
2725 (while (< (- (point-max) (point-min)) (length "foo"))
2726 (accept-process-output proc
0.1)))
2727 (should (string-equal (buffer-string) "foo")))
2731 (delete-process proc
)
2732 (delete-file tmp-name
)))
2736 (setq proc
(start-file-process "test3" (current-buffer) "cat"))
2737 (should (processp proc
))
2738 (should (equal (process-status proc
) 'run
))
2741 (lambda (p s
) (with-current-buffer (process-buffer p
) (insert s
))))
2742 (process-send-string proc
"foo")
2743 (process-send-eof proc
)
2745 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
2746 (while (< (- (point-max) (point-min)) (length "foo"))
2747 (accept-process-output proc
0.1)))
2748 (should (string-equal (buffer-string) "foo")))
2751 (ignore-errors (delete-process proc
))))))
2753 (ert-deftest tramp-test28-shell-command
()
2754 "Check `shell-command'."
2755 :tags
'(:expensive-test
)
2756 (skip-unless (tramp--test-enabled))
2757 (skip-unless (tramp--test-sh-p))
2759 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2760 (let ((tmp-name (tramp--test-make-temp-name nil quoted
))
2761 (default-directory tramp-test-temporary-file-directory
)
2762 kill-buffer-query-functions
)
2765 (write-region "foo" nil tmp-name
)
2766 (should (file-exists-p tmp-name
))
2768 (format "ls %s" (file-name-nondirectory tmp-name
))
2770 ;; `ls' could produce colorized output.
2771 (goto-char (point-min))
2773 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
2774 (replace-match "" nil nil
))
2777 (format "%s\n" (file-name-nondirectory tmp-name
))
2781 (ignore-errors (delete-file tmp-name
)))
2785 (write-region "foo" nil tmp-name
)
2786 (should (file-exists-p tmp-name
))
2787 (async-shell-command
2788 (format "ls %s" (file-name-nondirectory tmp-name
))
2790 (set-process-sentinel (get-buffer-process (current-buffer)) nil
)
2792 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
2793 (while (< (- (point-max) (point-min))
2794 (1+ (length (file-name-nondirectory tmp-name
))))
2795 (accept-process-output
2796 (get-buffer-process (current-buffer)) 0.1)))
2797 ;; `ls' could produce colorized output.
2798 (goto-char (point-min))
2800 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
2801 (replace-match "" nil nil
))
2802 ;; There might be a nasty "Process *Async Shell* finished" message.
2803 (goto-char (point-min))
2805 (narrow-to-region (point-min) (point))
2808 (format "%s\n" (file-name-nondirectory tmp-name
))
2812 (ignore-errors (delete-file tmp-name
)))
2816 (write-region "foo" nil tmp-name
)
2817 (should (file-exists-p tmp-name
))
2818 (async-shell-command "read line; ls $line" (current-buffer))
2819 (set-process-sentinel (get-buffer-process (current-buffer)) nil
)
2820 (process-send-string
2821 (get-buffer-process (current-buffer))
2822 (format "%s\n" (file-name-nondirectory tmp-name
)))
2824 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
2825 (while (< (- (point-max) (point-min))
2826 (1+ (length (file-name-nondirectory tmp-name
))))
2827 (accept-process-output
2828 (get-buffer-process (current-buffer)) 0.1)))
2829 ;; `ls' could produce colorized output.
2830 (goto-char (point-min))
2832 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
2833 (replace-match "" nil nil
))
2834 ;; There might be a nasty "Process *Async Shell* finished" message.
2835 (goto-char (point-min))
2837 (narrow-to-region (point-min) (point))
2840 (format "%s\n" (file-name-nondirectory tmp-name
))
2844 (ignore-errors (delete-file tmp-name
))))))
2846 (defun tramp--test-shell-command-to-string-asynchronously (command)
2847 "Like `shell-command-to-string', but for asynchronous processes."
2849 (async-shell-command command
(current-buffer))
2850 ;; Suppress nasty messages.
2851 (set-process-sentinel (get-buffer-process (current-buffer)) nil
)
2853 (while (get-buffer-process (current-buffer))
2854 (accept-process-output (get-buffer-process (current-buffer)) 0.1)))
2855 (accept-process-output nil
0.1)
2856 (buffer-substring-no-properties (point-min) (point-max))))
2858 ;; This test is inspired by Bug#23952.
2859 (ert-deftest tramp-test29-environment-variables
()
2860 "Check that remote processes set / unset environment variables properly."
2861 :tags
'(:expensive-test
)
2862 (skip-unless (tramp--test-enabled))
2863 (skip-unless (tramp--test-sh-p))
2865 (dolist (this-shell-command-to-string
2867 shell-command-to-string
2869 tramp--test-shell-command-to-string-asynchronously
))
2871 (let ((default-directory tramp-test-temporary-file-directory
)
2872 (shell-file-name "/bin/sh")
2873 (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
2874 kill-buffer-query-functions
)
2878 (let ((process-environment
2879 (cons (concat envvar
"=foo") process-environment
)))
2885 this-shell-command-to-string
2886 (format "echo -n ${%s:?bla}" envvar
))))))
2889 ;; Set the empty value.
2890 (let ((process-environment
2891 (cons (concat envvar
"=") process-environment
)))
2897 this-shell-command-to-string
2898 (format "echo -n ${%s:?bla}" envvar
))))
2902 (regexp-quote envvar
)
2903 (funcall this-shell-command-to-string
"set")))))
2905 ;; We force a reconnect, in order to have a clean environment.
2906 (tramp-cleanup-connection
2907 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
2908 'keep-debug
'keep-password
)
2910 ;; Unset the variable.
2911 (let ((tramp-remote-process-environment
2912 (cons (concat envvar
"=foo")
2913 tramp-remote-process-environment
)))
2914 ;; Set the initial value, we want to unset below.
2919 this-shell-command-to-string
2920 (format "echo -n ${%s:?bla}" envvar
))))
2921 (let ((process-environment
2922 (cons envvar process-environment
)))
2923 ;; Variable is unset.
2928 this-shell-command-to-string
2929 (format "echo -n ${%s:?bla}" envvar
))))
2930 ;; Variable is unset.
2933 (regexp-quote envvar
)
2934 (funcall this-shell-command-to-string
"set")))))))))
2936 ;; This test is inspired by Bug#27009.
2937 (ert-deftest tramp-test29-environment-variables-and-port-numbers
()
2938 "Check that two connections with separate ports are different."
2939 (skip-unless (tramp--test-enabled))
2940 ;; We test it only for the mock-up connection; otherwise there might
2941 ;; be problems with the used ports.
2944 (eq tramp-syntax
'default
)
2946 "mock" (file-remote-p tramp-test-temporary-file-directory
'method
))))
2948 ;; We force a reconnect, in order to have a clean environment.
2949 (dolist (dir `(,tramp-test-temporary-file-directory
2950 "/mock:localhost#11111:" "/mock:localhost#22222:"))
2951 (tramp-cleanup-connection
2952 (tramp-dissect-file-name dir
) 'keep-debug
'keep-password
))
2955 (dolist (port '(11111 22222))
2956 (let* ((default-directory
2957 (format "/mock:localhost#%d:%s" port temporary-file-directory
))
2958 (shell-file-name "/bin/sh")
2959 (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
2960 ;; We cannot use `process-environment', because this
2961 ;; would be applied in `process-file'.
2962 (tramp-remote-process-environment
2964 (format "%s=%d" envvar port
)
2965 tramp-remote-process-environment
)))
2968 (number-to-string port
)
2969 (shell-command-to-string (format "echo -n $%s" envvar
))))))
2972 (dolist (dir '("/mock:localhost#11111:" "/mock:localhost#22222:"))
2973 (tramp-cleanup-connection (tramp-dissect-file-name dir
)))))
2975 ;; The functions were introduced in Emacs 26.1.
2976 (ert-deftest tramp-test30-explicit-shell-file-name
()
2977 "Check that connection-local `explicit-shell-file-name' is set."
2978 :tags
'(:expensive-test
)
2979 (skip-unless (tramp--test-enabled))
2980 (skip-unless (tramp--test-sh-p))
2981 (skip-unless (and (fboundp 'connection-local-set-profile-variables
)
2982 (fboundp 'connection-local-set-profiles
)))
2984 ;; `connection-local-set-profile-variables' and
2985 ;; `connection-local-set-profiles' exists since Emacs 26. We don't
2986 ;; want to see compiler warnings for older Emacsen.
2987 (let ((default-directory tramp-test-temporary-file-directory
)
2988 explicit-shell-file-name kill-buffer-query-functions
)
2991 ;; `shell-mode' would ruin our test, because it deletes all
2992 ;; buffer local variables.
2993 (put 'explicit-shell-file-name
'permanent-local t
)
2994 ;; Declare connection-local variable `explicit-shell-file-name'.
2996 (connection-local-set-profile-variables
2998 '((explicit-shell-file-name .
"/bin/sh")
2999 (explicit-sh-args .
("-i"))))
3000 (connection-local-set-profiles
3001 `(:application tramp
3002 :protocol
,(file-remote-p default-directory
'method
)
3003 :user
,(file-remote-p default-directory
'user
)
3004 :machine
,(file-remote-p default-directory
'host
))
3007 ;; Run interactive shell. Since the default directory is
3008 ;; remote, `explicit-shell-file-name' shall be set in order
3009 ;; to avoid a question.
3010 (with-current-buffer (get-buffer-create "*shell*")
3011 (ignore-errors (kill-process (current-buffer)))
3012 (should-not explicit-shell-file-name
)
3013 (call-interactively 'shell
)
3014 (should explicit-shell-file-name
)))
3016 (put 'explicit-shell-file-name
'permanent-local nil
)
3017 (kill-buffer "*shell*"))))
3019 (ert-deftest tramp-test31-vc-registered
()
3020 "Check `vc-registered'."
3021 :tags
'(:expensive-test
)
3022 (skip-unless (tramp--test-enabled))
3023 (skip-unless (tramp--test-sh-p))
3025 ;; TODO: This test fails.
3026 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3027 (let* ((default-directory tramp-test-temporary-file-directory
)
3028 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
3029 (tmp-name2 (expand-file-name "foo" tmp-name1
))
3030 (tramp-remote-process-environment tramp-remote-process-environment
)
3031 (vc-handled-backends
3032 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3034 ((tramp-find-executable
3035 v vc-git-program
(tramp-get-remote-path v
))
3037 ((tramp-find-executable
3038 v vc-hg-program
(tramp-get-remote-path v
))
3040 ((tramp-find-executable
3041 v vc-bzr-program
(tramp-get-remote-path v
))
3042 (setq tramp-remote-process-environment
3043 (cons (format "BZR_HOME=%s"
3044 (file-remote-p tmp-name1
'localname
))
3045 tramp-remote-process-environment
))
3046 ;; We must force a reconnect, in order to activate $BZR_HOME.
3047 (tramp-cleanup-connection
3048 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
3052 (skip-unless vc-handled-backends
)
3053 (message "%s" vc-handled-backends
)
3057 (make-directory tmp-name1
)
3058 (write-region "foo" nil tmp-name2
)
3059 (should (file-directory-p tmp-name1
))
3060 (should (file-exists-p tmp-name2
))
3061 (should-not (vc-registered tmp-name1
))
3062 (should-not (vc-registered tmp-name2
))
3064 (let ((default-directory tmp-name1
))
3065 ;; Create empty repository, and register the file.
3066 ;; Sometimes, creation of repository fails (bzr!); we
3067 ;; skip the test then.
3069 (vc-create-repo (car vc-handled-backends
))
3070 (error (skip-unless nil
)))
3071 ;; The structure of VC-FILESET is not documented. Let's
3072 ;; hope it won't change.
3075 (list (car vc-handled-backends
)
3076 (list (file-name-nondirectory tmp-name2
))))
3077 ;; `vc-register' has changed its arguments in Emacs 25.1.
3080 nil
(list (car vc-handled-backends
)
3081 (list (file-name-nondirectory tmp-name2
))))))
3082 ;; vc-git uses an own process sentinel, Tramp's sentinel
3083 ;; for flushing the cache isn't used.
3084 (dired-uncache (concat (file-remote-p default-directory
) "/"))
3085 (should (vc-registered (file-name-nondirectory tmp-name2
)))))
3088 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
3090 (ert-deftest tramp-test32-make-auto-save-file-name
()
3091 "Check `make-auto-save-file-name'."
3092 (skip-unless (tramp--test-enabled))
3094 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3095 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3096 (tmp-name2 (tramp--test-make-temp-name nil quoted
)))
3100 ;; Use default `auto-save-file-name-transforms' mechanism.
3101 (let (tramp-auto-save-directory)
3103 (setq buffer-file-name tmp-name1
)
3106 (make-auto-save-file-name)
3107 ;; This is taken from original `make-auto-save-file-name'.
3108 ;; We call `convert-standard-filename', because on
3109 ;; MS Windows the (local) colons must be replaced by
3110 ;; exclamation marks.
3111 (convert-standard-filename
3115 (subst-char-in-string
3116 ?
/ ?
! (replace-regexp-in-string "!" "!!" tmp-name1
)))
3117 temporary-file-directory
))))))
3120 (let (tramp-auto-save-directory auto-save-file-name-transforms
)
3122 (setq buffer-file-name tmp-name1
)
3125 (make-auto-save-file-name)
3127 (if quoted
'tramp-compat-file-name-quote
'identity
)
3129 (format "#%s#" (file-name-nondirectory tmp-name1
))
3130 tramp-test-temporary-file-directory
))))))
3132 ;; TODO: The following two cases don't work yet.
3134 ;; Use default `tramp-auto-save-directory' mechanism.
3135 (let ((tramp-auto-save-directory tmp-name2
))
3137 (setq buffer-file-name tmp-name1
)
3140 (make-auto-save-file-name)
3141 ;; This is taken from Tramp.
3145 (tramp-subst-strs-in-string
3152 (tramp-compat-file-name-unquote tmp-name1
)))
3154 (should (file-directory-p tmp-name2
))))
3156 ;; Relative file names shall work, too.
3157 (let ((tramp-auto-save-directory "."))
3159 (setq buffer-file-name tmp-name1
3160 default-directory tmp-name2
)
3163 (make-auto-save-file-name)
3164 ;; This is taken from Tramp.
3168 (tramp-subst-strs-in-string
3175 (tramp-compat-file-name-unquote tmp-name1
)))
3177 (should (file-directory-p tmp-name2
)))))
3181 (ignore-errors (delete-file tmp-name1
))
3182 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
3184 ;; The functions were introduced in Emacs 26.1.
3185 (ert-deftest tramp-test33-make-nearby-temp-file
()
3186 "Check `make-nearby-temp-file' and `temporary-file-directory'."
3187 (skip-unless (tramp--test-enabled))
3189 (and (fboundp 'make-nearby-temp-file
) (fboundp 'temporary-file-directory
)))
3191 ;; `make-nearby-temp-file' and `temporary-file-directory' exists
3192 ;; since Emacs 26. We don't want to see compiler warnings for older
3194 (let ((default-directory tramp-test-temporary-file-directory
)
3196 ;; The remote host shall know a temporary file directory.
3197 (should (stringp (with-no-warnings (temporary-file-directory))))
3200 (file-remote-p default-directory
)
3201 (file-remote-p (with-no-warnings (temporary-file-directory)))))
3203 ;; The temporary file shall be located on the remote host.
3204 (setq tmp-file
(with-no-warnings (make-nearby-temp-file "tramp-test")))
3205 (should (file-exists-p tmp-file
))
3206 (should (file-regular-p tmp-file
))
3209 (file-remote-p default-directory
)
3210 (file-remote-p tmp-file
)))
3211 (delete-file tmp-file
)
3212 (should-not (file-exists-p tmp-file
))
3214 (setq tmp-file
(with-no-warnings (make-nearby-temp-file "tramp-test" 'dir
)))
3215 (should (file-exists-p tmp-file
))
3216 (should (file-directory-p tmp-file
))
3217 (delete-directory tmp-file
)
3218 (should-not (file-exists-p tmp-file
))))
3220 (defun tramp--test-adb-p ()
3221 "Check, whether the remote host runs Android.
3222 This requires restrictions of file name syntax."
3223 (tramp-adb-file-name-p tramp-test-temporary-file-directory
))
3225 (defun tramp--test-docker-p ()
3226 "Check, whether the docker method is used.
3227 This does not support some special file names."
3229 "docker" (file-remote-p tramp-test-temporary-file-directory
'method
)))
3231 (defun tramp--test-ftp-p ()
3232 "Check, whether an FTP-like method is used.
3233 This does not support globbing characters in file names (yet)."
3234 ;; Globbing characters are ??, ?* and ?\[.
3236 "ftp$" (file-remote-p tramp-test-temporary-file-directory
'method
)))
3238 (defun tramp--test-gvfs-p (&optional method
)
3239 "Check, whether the remote host runs a GVFS based method.
3240 This requires restrictions of file name syntax."
3241 (or (member method tramp-gvfs-methods
)
3242 (tramp-gvfs-file-name-p tramp-test-temporary-file-directory
)))
3244 (defun tramp--test-hpux-p ()
3245 "Check, whether the remote host runs HP-UX.
3246 Several special characters do not work properly there."
3247 ;; We must refill the cache. `file-truename' does it.
3248 (with-parsed-tramp-file-name
3249 (file-truename tramp-test-temporary-file-directory
) nil
3250 (string-match "^HP-UX" (tramp-get-connection-property v
"uname" ""))))
3252 (defun tramp--test-rsync-p ()
3253 "Check, whether the rsync method is used.
3254 This does not support special file names."
3256 "rsync" (file-remote-p tramp-test-temporary-file-directory
'method
)))
3258 (defun tramp--test-sh-p ()
3259 "Check, whether the remote host runs a based method from tramp-sh.el."
3261 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
3262 'tramp-sh-file-name-handler
))
3264 (defun tramp--test-windows-nt-and-batch ()
3265 "Check, whether the locale host runs MS Windows in batch mode.
3266 This does not support special characters."
3267 (and (eq system-type
'windows-nt
) noninteractive
))
3269 (defun tramp--test-windows-nt-and-pscp-psftp-p ()
3270 "Check, whether the locale host runs MS Windows, and ps{cp,ftp} is used.
3271 This does not support utf8 based file transfer."
3272 (and (eq system-type
'windows-nt
)
3274 (regexp-opt '("pscp" "psftp"))
3275 (file-remote-p tramp-test-temporary-file-directory
'method
))))
3277 (defun tramp--test-windows-nt-or-smb-p ()
3278 "Check, whether the locale or remote host runs MS Windows.
3279 This requires restrictions of file name syntax."
3280 (or (eq system-type
'windows-nt
)
3281 (tramp-smb-file-name-p tramp-test-temporary-file-directory
)))
3283 (defun tramp--test-check-files (&rest files
)
3284 "Run a simple but comprehensive test over every file in FILES."
3285 ;; TODO: The quoted case does not work.
3286 ;;(dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
3288 ;; We must use `file-truename' for the temporary directory,
3289 ;; because it could be located on a symlinked directory. This
3290 ;; would let the test fail.
3291 (let* ((tramp-test-temporary-file-directory
3292 (file-truename tramp-test-temporary-file-directory
))
3293 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
3294 (tmp-name2 (tramp--test-make-temp-name 'local quoted
))
3295 (files (delq nil files
))
3296 (process-environment process-environment
))
3299 (make-directory tmp-name1
)
3300 (make-directory tmp-name2
)
3303 (let* ((file1 (expand-file-name elt tmp-name1
))
3304 (file2 (expand-file-name elt tmp-name2
))
3305 (file3 (expand-file-name (concat elt
"foo") tmp-name1
)))
3306 (write-region elt nil file1
)
3307 (should (file-exists-p file1
))
3309 ;; Check file contents.
3311 (insert-file-contents file1
)
3312 (should (string-equal (buffer-string) elt
)))
3314 ;; Copy file both directions.
3315 (copy-file file1 tmp-name2
)
3316 (should (file-exists-p file2
))
3318 (should-not (file-exists-p file1
))
3319 (copy-file file2 tmp-name1
)
3320 (should (file-exists-p file1
))
3322 ;; Method "smb" supports `make-symbolic-link' only if the
3323 ;; remote host has CIFS capabilities. tramp-adb.el and
3324 ;; tramp-gvfs.el do not support symbolic links at all.
3327 (make-symbolic-link file1 file3
)
3328 (should (file-symlink-p file3
))
3331 (expand-file-name file1
) (file-truename file3
)))
3335 (if quoted
'tramp-compat-file-name-quote
'identity
)
3336 (car (file-attributes file3
)))
3337 (file-remote-p (file-truename file1
) 'localname
)))
3338 ;; Check file contents.
3340 (insert-file-contents file3
)
3341 (should (string-equal (buffer-string) elt
)))
3342 (delete-file file3
))
3345 (string-equal (error-message-string err
)
3346 "make-symbolic-link not supported"))))))
3348 ;; Check file names.
3349 (should (equal (directory-files
3350 tmp-name1 nil directory-files-no-dot-files-regexp
)
3351 (sort (copy-sequence files
) 'string-lessp
)))
3352 (should (equal (directory-files
3353 tmp-name2 nil directory-files-no-dot-files-regexp
)
3354 (sort (copy-sequence files
) 'string-lessp
)))
3356 ;; `substitute-in-file-name' could return different
3357 ;; values. For `adb', there could be strange file
3358 ;; permissions preventing overwriting a file. We don't
3359 ;; care in this testcase.
3362 (substitute-in-file-name (expand-file-name elt tmp-name1
)))
3364 (substitute-in-file-name
3365 (expand-file-name elt tmp-name2
))))
3366 (ignore-errors (write-region elt nil file1
))
3367 (should (file-exists-p file1
))
3368 (ignore-errors (write-region elt nil file2 nil
'nomessage
))
3369 (should (file-exists-p file2
))))
3371 (should (equal (directory-files
3372 tmp-name1 nil directory-files-no-dot-files-regexp
)
3374 tmp-name2 nil directory-files-no-dot-files-regexp
)))
3376 ;; Check directory creation. We use a subdirectory "foo"
3377 ;; in order to avoid conflicts with previous file name tests.
3379 (let* ((elt1 (concat elt
"foo"))
3380 (file1 (expand-file-name (concat "foo/" elt
) tmp-name1
))
3381 (file2 (expand-file-name elt file1
))
3382 (file3 (expand-file-name elt1 file1
)))
3383 (make-directory file1
'parents
)
3384 (should (file-directory-p file1
))
3385 (write-region elt nil file2
)
3386 (should (file-exists-p file2
))
3390 file1 nil directory-files-no-dot-files-regexp
)
3394 (caar (directory-files-and-attributes
3395 file1 nil directory-files-no-dot-files-regexp
))
3398 ;; Check symlink in `directory-files-and-attributes'.
3401 (make-symbolic-link file2 file3
)
3402 (should (file-symlink-p file3
))
3405 (caar (directory-files-and-attributes
3406 file1 nil
(regexp-quote elt1
)))
3411 (if quoted
'tramp-compat-file-name-quote
'identity
)
3412 (cadr (car (directory-files-and-attributes
3413 file1 nil
(regexp-quote elt1
)))))
3414 (file-remote-p (file-truename file2
) 'localname
)))
3416 (should-not (file-exists-p file3
)))
3418 (should (string-equal (error-message-string err
)
3419 "make-symbolic-link not supported"))))
3422 (should-not (file-exists-p file2
))
3423 (delete-directory file1
)
3424 (should-not (file-exists-p file1
))))
3426 ;; Check, that environment variables are set correctly.
3427 (when (and tramp--test-expensive-test
(tramp--test-sh-p))
3429 (let ((envvar (concat "VAR_" (upcase (md5 elt
))))
3430 (default-directory tramp-test-temporary-file-directory
)
3431 (process-environment process-environment
))
3433 ;; The value of PS1 could confuse Tramp's detection
3434 ;; of process output. So we unset it temporarily.
3437 (should (zerop (process-file "env" nil t nil
)))
3438 (goto-char (point-min))
3443 (regexp-quote envvar
)
3444 (regexp-quote (getenv envvar
))))))))))
3447 (ignore-errors (delete-directory tmp-name1
'recursive
))
3448 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
3450 (defun tramp--test-special-characters ()
3451 "Perform the test in `tramp-test34-special-characters*'."
3452 ;; Newlines, slashes and backslashes in file names are not
3453 ;; supported. So we don't test. And we don't test the tab
3454 ;; character on Windows or Cygwin, because the backslash is
3455 ;; interpreted as a path separator, preventing "\t" from being
3456 ;; expanded to <TAB>.
3457 (tramp--test-check-files
3458 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3460 (if (or (tramp--test-adb-p)
3461 (tramp--test-docker-p)
3462 (eq system-type
'cygwin
))
3469 (unless (or (tramp--test-ftp-p)
3470 (tramp--test-gvfs-p)
3471 (tramp--test-windows-nt-or-smb-p))
3473 (unless (or (tramp--test-ftp-p)
3474 (tramp--test-gvfs-p)
3475 (tramp--test-windows-nt-or-smb-p))
3477 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3481 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3484 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3487 (unless (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
3490 (unless (or (tramp--test-ftp-p) (tramp--test-gvfs-p)) "[foo]bar[baz]")
3493 ;; These tests are inspired by Bug#17238.
3494 (ert-deftest tramp-test34-special-characters
()
3495 "Check special characters in file names."
3496 (skip-unless (tramp--test-enabled))
3497 (skip-unless (not (tramp--test-rsync-p)))
3498 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3500 (tramp--test-special-characters))
3502 (ert-deftest tramp-test34-special-characters-with-stat
()
3503 "Check special characters in file names.
3504 Use the `stat' command."
3505 :tags
'(:expensive-test
)
3506 (skip-unless (tramp--test-enabled))
3507 (skip-unless (tramp--test-sh-p))
3508 (skip-unless (not (tramp--test-rsync-p)))
3509 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3510 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3511 (skip-unless (tramp-get-remote-stat v
)))
3513 (let ((tramp-connection-properties
3515 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3517 tramp-connection-properties
)))
3518 (tramp--test-special-characters)))
3520 (ert-deftest tramp-test34-special-characters-with-perl
()
3521 "Check special characters in file names.
3522 Use the `perl' command."
3523 :tags
'(:expensive-test
)
3524 (skip-unless (tramp--test-enabled))
3525 (skip-unless (tramp--test-sh-p))
3526 (skip-unless (not (tramp--test-rsync-p)))
3527 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3528 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3529 (skip-unless (tramp-get-remote-perl v
)))
3531 (let ((tramp-connection-properties
3533 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3535 ;; See `tramp-sh-handle-file-truename'.
3536 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3538 tramp-connection-properties
)))
3539 (tramp--test-special-characters)))
3541 (ert-deftest tramp-test34-special-characters-with-ls
()
3542 "Check special characters in file names.
3543 Use the `ls' command."
3544 :tags
'(:expensive-test
)
3545 (skip-unless (tramp--test-enabled))
3546 (skip-unless (tramp--test-sh-p))
3547 (skip-unless (not (tramp--test-rsync-p)))
3548 (skip-unless (not (tramp--test-windows-nt-and-batch)))
3549 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3551 (let ((tramp-connection-properties
3553 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3555 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3557 ;; See `tramp-sh-handle-file-truename'.
3558 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3560 tramp-connection-properties
)))
3561 (tramp--test-special-characters)))
3563 (defun tramp--test-utf8 ()
3564 "Perform the test in `tramp-test35-utf8*'."
3565 (let* ((utf8 (if (and (eq system-type
'darwin
)
3566 (memq 'utf-8-hfs
(coding-system-list)))
3568 (coding-system-for-read utf8
)
3569 (coding-system-for-write utf8
)
3570 (file-name-coding-system utf8
))
3571 (tramp--test-check-files
3572 (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ")
3573 (unless (tramp--test-hpux-p)
3574 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
3576 "Автостопом по гала́ктике")))
3578 (ert-deftest tramp-test35-utf8
()
3579 "Check UTF8 encoding in file names and file contents."
3580 (skip-unless (tramp--test-enabled))
3581 (skip-unless (not (tramp--test-docker-p)))
3582 (skip-unless (not (tramp--test-rsync-p)))
3583 (skip-unless (not (tramp--test-windows-nt-and-batch)))
3584 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3588 (ert-deftest tramp-test35-utf8-with-stat
()
3589 "Check UTF8 encoding in file names and file contents.
3590 Use the `stat' command."
3591 :tags
'(:expensive-test
)
3592 (skip-unless (tramp--test-enabled))
3593 (skip-unless (tramp--test-sh-p))
3594 (skip-unless (not (tramp--test-docker-p)))
3595 (skip-unless (not (tramp--test-rsync-p)))
3596 (skip-unless (not (tramp--test-windows-nt-and-batch)))
3597 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3598 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3599 (skip-unless (tramp-get-remote-stat v
)))
3601 (let ((tramp-connection-properties
3603 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3605 tramp-connection-properties
)))
3606 (tramp--test-utf8)))
3608 (ert-deftest tramp-test35-utf8-with-perl
()
3609 "Check UTF8 encoding in file names and file contents.
3610 Use the `perl' command."
3611 :tags
'(:expensive-test
)
3612 (skip-unless (tramp--test-enabled))
3613 (skip-unless (tramp--test-sh-p))
3614 (skip-unless (not (tramp--test-docker-p)))
3615 (skip-unless (not (tramp--test-rsync-p)))
3616 (skip-unless (not (tramp--test-windows-nt-and-batch)))
3617 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3618 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3619 (skip-unless (tramp-get-remote-perl v
)))
3621 (let ((tramp-connection-properties
3623 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3625 ;; See `tramp-sh-handle-file-truename'.
3626 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3628 tramp-connection-properties
)))
3629 (tramp--test-utf8)))
3631 (ert-deftest tramp-test35-utf8-with-ls
()
3632 "Check UTF8 encoding in file names and file contents.
3633 Use the `ls' command."
3634 :tags
'(:expensive-test
)
3635 (skip-unless (tramp--test-enabled))
3636 (skip-unless (tramp--test-sh-p))
3637 (skip-unless (not (tramp--test-docker-p)))
3638 (skip-unless (not (tramp--test-rsync-p)))
3639 (skip-unless (not (tramp--test-windows-nt-and-batch)))
3640 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
3642 (let ((tramp-connection-properties
3644 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3646 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3648 ;; See `tramp-sh-handle-file-truename'.
3649 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
3651 tramp-connection-properties
)))
3652 (tramp--test-utf8)))
3654 ;; This test is inspired by Bug#16928.
3655 (ert-deftest tramp-test36-asynchronous-requests
()
3656 "Check parallel asynchronous requests.
3657 Such requests could arrive from timers, process filters and
3658 process sentinels. They shall not disturb each other."
3659 ;; Mark as failed until bug has been fixed.
3660 :expected-result
:failed
3661 :tags
'(:expensive-test
)
3662 (skip-unless (tramp--test-enabled))
3663 (skip-unless (tramp--test-sh-p))
3665 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3666 ;; Keep instrumentation verbosity 0 until Tramp bug is fixed.
3667 ;; This has the side effect, that this test fails instead to
3668 ;; abort. Good for hydra.
3669 (tramp--instrument-test-case 0
3670 (let* ((tmp-name (tramp--test-make-temp-name nil quoted
))
3671 (default-directory tmp-name
)
3672 (remote-file-name-inhibit-cache t
)
3673 timer buffers kill-buffer-query-functions
)
3677 (make-directory tmp-name
)
3679 ;; Setup a timer in order to raise an ordinary command
3680 ;; again and again. `vc-registered' is well suited,
3681 ;; because there are many checks.
3689 (buffer-name (nth (random (length buffers
)) buffers
)))))))
3691 ;; Create temporary buffers. The number of buffers
3692 ;; corresponds to the number of processes; it could be
3693 ;; increased in order to make pressure on Tramp.
3695 (add-to-list 'buffers
(generate-new-buffer "*temp*")))
3697 ;; Open asynchronous processes. Set process sentinel.
3698 (dolist (buf buffers
)
3699 (async-shell-command "read line; touch $line; echo $line" buf
)
3700 (set-process-sentinel
3701 (get-buffer-process buf
)
3702 (lambda (proc _state
)
3703 (delete-file (buffer-name (process-buffer proc
))))))
3705 ;; Send a string. Use a random order of the buffers. Mix
3706 ;; with regular operation.
3707 (let ((buffers (copy-sequence buffers
))
3710 (setq buf
(nth (random (length buffers
)) buffers
))
3711 (process-send-string
3712 (get-buffer-process buf
) (format "'%s'\n" buf
))
3713 (file-attributes (buffer-name buf
))
3714 (setq buffers
(delq buf buffers
))))
3716 ;; Wait until the whole output has been read.
3717 (with-timeout ((* 10 (length buffers
))
3718 (ert-fail "`async-shell-command' timed out"))
3719 (let ((buffers (copy-sequence buffers
))
3722 (setq buf
(nth (random (length buffers
)) buffers
))
3724 (memq (process-status (get-buffer-process buf
))
3726 (accept-process-output (get-buffer-process buf
) 0.1)
3727 (setq buffers
(delq buf buffers
))))))
3730 (dolist (buf buffers
)
3731 (with-current-buffer buf
3733 (string-equal (format "'%s'\n" buf
) (buffer-string)))))
3736 tmp-name nil directory-files-no-dot-files-regexp
)))
3739 (ignore-errors (cancel-timer timer
))
3740 (ignore-errors (delete-directory tmp-name
'recursive
))
3741 (dolist (buf buffers
)
3742 (ignore-errors (kill-buffer buf
))))))))
3744 (ert-deftest tramp-test37-recursive-load
()
3745 "Check that Tramp does not fail due to recursive load."
3746 (skip-unless (tramp--test-enabled))
3750 (format "(expand-file-name %S)" tramp-test-temporary-file-directory
)
3752 "(let ((default-directory %S)) (expand-file-name %S))"
3753 tramp-test-temporary-file-directory
3754 temporary-file-directory
)))
3758 (shell-command-to-string
3760 "%s -batch -Q -L %s --eval %s"
3761 (expand-file-name invocation-name invocation-directory
)
3762 (mapconcat 'shell-quote-argument load-path
" -L ")
3763 (shell-quote-argument code
)))))))
3765 (ert-deftest tramp-test38-unload
()
3766 "Check that Tramp and its subpackages unload completely.
3767 Since it unloads Tramp, it shall be the last test to run."
3768 ;; Mark as failed until all symbols are unbound.
3769 :expected-result
(if (featurep 'tramp
) :failed
:passed
)
3770 :tags
'(:expensive-test
)
3771 (skip-unless noninteractive
)
3773 (when (featurep 'tramp
)
3774 (unload-feature 'tramp
'force
)
3775 ;; No Tramp feature must be left.
3776 (should-not (featurep 'tramp
))
3777 (should-not (all-completions "tramp" (delq 'tramp-tests features
)))
3778 ;; `file-name-handler-alist' must be clean.
3779 (should-not (all-completions "tramp" (mapcar 'cdr file-name-handler-alist
)))
3780 ;; There shouldn't be left a bound symbol. We do not regard our
3781 ;; test symbols, and the Tramp unload hooks.
3784 (and (or (boundp x
) (functionp x
))
3785 (string-match "^tramp" (symbol-name x
))
3786 (not (string-match "^tramp--?test" (symbol-name x
)))
3787 (not (string-match "unload-hook$" (symbol-name x
)))
3788 (ert-fail (format "`%s' still bound" x
)))))
3789 ;; There shouldn't be left a hook function containing a Tramp
3790 ;; function. We do not regard the Tramp unload hooks.
3794 (string-match "-hooks?$" (symbol-name x
))
3795 (not (string-match "unload-hook$" (symbol-name x
)))
3796 (consp (symbol-value x
))
3797 (ignore-errors (all-completions "tramp" (symbol-value x
)))
3798 (ert-fail (format "Hook `%s' still contains Tramp function" x
)))))))
3802 ;; * dired-compress-file
3805 ;; * file-name-case-insensitive-p
3806 ;; * file-selinux-context
3807 ;; * find-backup-file-name
3809 ;; * set-file-selinux-context
3811 ;; * Work on skipped tests. Make a comment, when it is impossible.
3812 ;; * Fix `tramp-test05-expand-file-name-relative' in `expand-file-name'.
3813 ;; * Fix `tramp-test06-directory-file-name' for `ftp'.
3814 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
3815 ;; * Fix Bug#27009. Set expected error of
3816 ;; `tramp-test29-environment-variables-and-port-numbers'.
3817 ;; * Fix Bug#16928. Set expected error of `tramp-test36-asynchronous-requests'.
3818 ;; * Fix `tramp-test38-unload' (Not all symbols are unbound). Set
3821 (defun tramp-test-all (&optional interactive
)
3822 "Run all tests for \\[tramp]."
3825 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
) "^tramp"))
3827 (provide 'tramp-tests
)
3828 ;;; tramp-tests.el ends here