1 ;;; tramp-tests.el --- Tests of remote file access -*- lexical-binding:t -*-
3 ;; Copyright (C) 2013-2018 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `https://www.gnu.org/licenses/'.
22 ;; The 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 ;; For slow remote connections, `tramp-test41-asynchronous-requests'
37 ;; might be too heavy. Setting $REMOTE_PARALLEL_PROCESSES to a proper
38 ;; value less than 10 could help.
40 ;; A whole test run can be performed calling the command `tramp-test-all'.
53 (declare-function tramp-find-executable
"tramp-sh")
54 (declare-function tramp-get-remote-path
"tramp-sh")
55 (declare-function tramp-get-remote-stat
"tramp-sh")
56 (declare-function tramp-get-remote-perl
"tramp-sh")
57 (defvar auto-save-file-name-transforms
)
58 (defvar tramp-copy-size-limit
)
59 (defvar tramp-persistency-file-name
)
60 (defvar tramp-remote-process-environment
)
62 ;; Beautify batch mode.
64 ;; Suppress nasty messages.
65 (fset 'shell-command-sentinel
'ignore
)
66 ;; We do not want to be interrupted.
67 (eval-after-load 'tramp-gvfs
68 '(fset 'tramp-gvfs-handler-askquestion
69 (lambda (_message _choices
) '(t nil
0)))))
71 ;; There is no default value on w32 systems, which could work out of the box.
72 (defconst tramp-test-temporary-file-directory
74 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
75 ((eq system-type
'windows-nt
) null-device
)
79 (tramp-login-program "sh")
80 (tramp-login-args (("-i")))
81 (tramp-remote-shell "/bin/sh")
82 (tramp-remote-shell-args ("-c"))
83 (tramp-connection-timeout 10)))
85 'tramp-default-host-alist
86 `("\\`mock\\'" nil
,(system-name)))
87 ;; Emacs' Makefile sets $HOME to a nonexistent value. Needed in
88 ;; batch mode only, therefore.
89 (unless (and (null noninteractive
) (file-directory-p "~/"))
90 (setenv "HOME" temporary-file-directory
))
91 (format "/mock::%s" temporary-file-directory
)))
92 "Temporary directory for Tramp tests.")
94 (setq password-cache-expiry nil
96 tramp-cache-read-persistent-data t
;; For auth-sources.
97 tramp-copy-size-limit nil
98 tramp-message-show-message nil
99 tramp-persistency-file-name nil
)
101 ;; This should happen on hydra only.
102 (when (getenv "EMACS_HYDRA_CI")
103 (add-to-list 'tramp-remote-path
'tramp-own-remote-path
))
105 (defvar tramp--test-expensive-test
107 (string-equal (getenv "SELECTOR") "(quote (not (tag :expensive-test)))"))
108 "Whether expensive tests are run.")
110 (defvar tramp--test-enabled-checked nil
111 "Cached result of `tramp--test-enabled'.
112 If the function did run, the value is a cons cell, the `cdr'
115 (defun tramp--test-enabled ()
116 "Whether remote file access is enabled."
117 (unless (consp tramp--test-enabled-checked
)
119 tramp--test-enabled-checked
123 (file-remote-p tramp-test-temporary-file-directory
)
124 (file-directory-p tramp-test-temporary-file-directory
)
125 (file-writable-p tramp-test-temporary-file-directory
))))))
127 (when (cdr tramp--test-enabled-checked
)
128 ;; Cleanup connection.
130 (tramp-cleanup-connection
131 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
132 nil
'keep-password
)))
135 (cdr tramp--test-enabled-checked
))
137 (defun tramp--test-make-temp-name (&optional local quoted
)
138 "Return a temporary file name for test.
139 If LOCAL is non-nil, a local file name is returned.
140 If QUOTED is non-nil, the local part of the file name is quoted.
141 The temporary file is not created."
143 (if quoted
'tramp-compat-file-name-quote
'identity
)
145 (make-temp-name "tramp-test")
146 (if local temporary-file-directory tramp-test-temporary-file-directory
))))
148 ;; Don't print messages in nested `tramp--test-instrument-test-case' calls.
149 (defvar tramp--test-instrument-test-case-p nil
150 "Whether `tramp--test-instrument-test-case' run.
151 This shall used dynamically bound only.")
153 (defmacro tramp--test-instrument-test-case
(verbose &rest body
)
154 "Run BODY with `tramp-verbose' equal VERBOSE.
155 Print the content of the Tramp debug buffer, if BODY does not
156 eval properly in `should' or `should-not'. `should-error' is not
157 handled properly. BODY shall not contain a timeout."
158 (declare (indent 1) (debug (natnump body
)))
159 `(let ((tramp-verbose (max (or ,verbose
0) (or tramp-verbose
0)))
160 (tramp-message-show-message t
)
161 (tramp-debug-on-error t
)
162 (debug-ignored-errors
163 (cons "^make-symbolic-link not supported$" debug-ignored-errors
))
166 (let ((tramp--test-instrument-test-case-p t
)) ,@body
)
168 (when (and (null tramp--test-instrument-test-case-p
) (> tramp-verbose
3))
169 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
170 (with-current-buffer (tramp-get-connection-buffer v
)
171 (message "%s" (buffer-string)))
172 (with-current-buffer (tramp-get-debug-buffer v
)
173 (message "%s" (buffer-string))))))))
175 (defsubst tramp--test-message
(fmt-string &rest arguments
)
176 "Emit a message into ERT *Messages*."
177 (tramp--test-instrument-test-case 0
180 (tramp-dissect-file-name tramp-test-temporary-file-directory
) 0
181 fmt-string arguments
)))
183 (defsubst tramp--test-backtrace
()
184 "Dump a backtrace into ERT *Messages*."
185 (tramp--test-instrument-test-case 10
187 (tramp-dissect-file-name tramp-test-temporary-file-directory
))))
189 (ert-deftest tramp-test00-availability
()
190 "Test availability of Tramp functions."
191 :expected-result
(if (tramp--test-enabled) :passed
:failed
)
193 "Remote directory: `%s'" tramp-test-temporary-file-directory
)
194 (should (ignore-errors
196 (file-remote-p tramp-test-temporary-file-directory
)
197 (file-directory-p tramp-test-temporary-file-directory
)
198 (file-writable-p tramp-test-temporary-file-directory
)))))
200 (ert-deftest tramp-test01-file-name-syntax
()
201 "Check remote file name syntax."
203 (should (tramp-tramp-file-p "/method::"))
204 (should (tramp-tramp-file-p "/method:host:"))
205 (should (tramp-tramp-file-p "/method:user@:"))
206 (should (tramp-tramp-file-p "/method:user@host:"))
207 (should (tramp-tramp-file-p "/method:user@email@host:"))
210 (should (tramp-tramp-file-p "/method:host#1234:"))
211 (should (tramp-tramp-file-p "/method:user@host#1234:"))
213 ;; Using an IPv4 address.
214 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
215 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
217 ;; Using an IPv6 address.
218 (should (tramp-tramp-file-p "/method:[::1]:"))
219 (should (tramp-tramp-file-p "/method:user@[::1]:"))
221 ;; Local file name part.
222 (should (tramp-tramp-file-p "/method:::"))
223 (should (tramp-tramp-file-p "/method::/:"))
224 (should (tramp-tramp-file-p "/method::/path/to/file"))
225 (should (tramp-tramp-file-p "/method::/:/path/to/file"))
226 (should (tramp-tramp-file-p "/method::file"))
227 (should (tramp-tramp-file-p "/method::/:file"))
230 (should (tramp-tramp-file-p "/method1:|method2::"))
231 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
232 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
233 (should (tramp-tramp-file-p
234 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
237 (should-not (tramp-tramp-file-p nil
))
238 (should-not (tramp-tramp-file-p 'symbol
))
240 (should-not (tramp-tramp-file-p "/host:"))
241 (should-not (tramp-tramp-file-p "/user@host:"))
242 (should-not (tramp-tramp-file-p "/1.2.3.4:"))
243 (should-not (tramp-tramp-file-p "/[]:"))
244 (should-not (tramp-tramp-file-p "/[::1]:"))
245 (should-not (tramp-tramp-file-p "/host:/:"))
246 (should-not (tramp-tramp-file-p "/host1|host2:"))
247 (should-not (tramp-tramp-file-p "/user1@host1|user2@host2:"))
248 ;; Quote with "/:" suppresses file name handlers.
249 (should-not (tramp-tramp-file-p "/::"))
250 (should-not (tramp-tramp-file-p "/:@:"))
251 (should-not (tramp-tramp-file-p "/:[]:"))
252 ;; Methods shall be at least two characters on MS Windows, except
253 ;; the default method.
254 (let ((system-type 'windows-nt
))
255 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
256 (should-not (tramp-tramp-file-p "/c::/path/to/file"))
257 (should (tramp-tramp-file-p "/-::/path/to/file")))
258 (let ((system-type 'gnu
/linux
))
259 (should (tramp-tramp-file-p "/-:h:/path/to/file"))
260 (should (tramp-tramp-file-p "/m::/path/to/file"))))
262 (ert-deftest tramp-test01-file-name-syntax-simplified
()
263 "Check simplified file name syntax."
264 :tags
'(:expensive-test
)
265 (let ((syntax tramp-syntax
))
268 (tramp-change-syntax 'simplified
)
270 (should (tramp-tramp-file-p "/host:"))
271 (should (tramp-tramp-file-p "/user@:"))
272 (should (tramp-tramp-file-p "/user@host:"))
273 (should (tramp-tramp-file-p "/user@email@host:"))
276 (should (tramp-tramp-file-p "/host#1234:"))
277 (should (tramp-tramp-file-p "/user@host#1234:"))
279 ;; Using an IPv4 address.
280 (should (tramp-tramp-file-p "/1.2.3.4:"))
281 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
283 ;; Using an IPv6 address.
284 (should (tramp-tramp-file-p "/[::1]:"))
285 (should (tramp-tramp-file-p "/user@[::1]:"))
287 ;; Local file name part.
288 (should (tramp-tramp-file-p "/host::"))
289 (should (tramp-tramp-file-p "/host:/:"))
290 (should (tramp-tramp-file-p "/host:/path/to/file"))
291 (should (tramp-tramp-file-p "/host:/:/path/to/file"))
292 (should (tramp-tramp-file-p "/host:file"))
293 (should (tramp-tramp-file-p "/host:/:file"))
296 (should (tramp-tramp-file-p "/host1|host2:"))
297 (should (tramp-tramp-file-p "/user1@host1|user2@host2:"))
298 (should (tramp-tramp-file-p "/user1@host1|user2@host2|user3@host3:"))
301 (should-not (tramp-tramp-file-p nil
))
302 (should-not (tramp-tramp-file-p 'symbol
))
303 ;; Quote with "/:" suppresses file name handlers.
304 (should-not (tramp-tramp-file-p "/::"))
305 (should-not (tramp-tramp-file-p "/:@:"))
306 (should-not (tramp-tramp-file-p "/:[]:")))
309 (tramp-change-syntax syntax
))))
311 (ert-deftest tramp-test01-file-name-syntax-separate
()
312 "Check separate file name syntax."
313 :tags
'(:expensive-test
)
314 (let ((syntax tramp-syntax
))
317 (tramp-change-syntax 'separate
)
319 (should (tramp-tramp-file-p "/[method/]"))
320 (should (tramp-tramp-file-p "/[method/host]"))
321 (should (tramp-tramp-file-p "/[method/user@]"))
322 (should (tramp-tramp-file-p "/[method/user@host]"))
323 (should (tramp-tramp-file-p "/[method/user@email@host]"))
326 (should (tramp-tramp-file-p "/[method/host#1234]"))
327 (should (tramp-tramp-file-p "/[method/user@host#1234]"))
329 ;; Using an IPv4 address.
330 (should (tramp-tramp-file-p "/[method/1.2.3.4]"))
331 (should (tramp-tramp-file-p "/[method/user@1.2.3.4]"))
333 ;; Using an IPv6 address.
334 (should (tramp-tramp-file-p "/[method/::1]"))
335 (should (tramp-tramp-file-p "/[method/user@::1]"))
337 ;; Local file name part.
338 (should (tramp-tramp-file-p "/[method/]"))
339 (should (tramp-tramp-file-p "/[method/]/:"))
340 (should (tramp-tramp-file-p "/[method/]/path/to/file"))
341 (should (tramp-tramp-file-p "/[method/]/:/path/to/file"))
342 (should (tramp-tramp-file-p "/[method/]file"))
343 (should (tramp-tramp-file-p "/[method/]/:file"))
346 (should (tramp-tramp-file-p "/[method1/|method2/]"))
347 (should (tramp-tramp-file-p "/[method1/host1|method2/host2]"))
350 "/[method1/user1@host1|method2/user2@host2]"))
353 "/[method1/user1@host1|method2/user2@host2|method3/user3@host3]"))
356 (should-not (tramp-tramp-file-p nil
))
357 (should-not (tramp-tramp-file-p 'symbol
))
359 (should-not (tramp-tramp-file-p "/host:"))
360 (should-not (tramp-tramp-file-p "/user@host:"))
361 (should-not (tramp-tramp-file-p "/1.2.3.4:"))
362 (should-not (tramp-tramp-file-p "/host:/:"))
363 (should-not (tramp-tramp-file-p "/host1|host2:"))
364 (should-not (tramp-tramp-file-p "/user1@host1|user2@host2:"))
365 ;; Quote with "/:" suppresses file name handlers.
366 (should-not (tramp-tramp-file-p "/:[]")))
369 (tramp-change-syntax syntax
))))
371 (ert-deftest tramp-test02-file-name-dissect
()
372 "Check remote file name components."
373 (let ((tramp-default-method "default-method")
374 (tramp-default-user "default-user")
375 (tramp-default-host "default-host")
376 tramp-default-method-alist
377 tramp-default-user-alist
378 tramp-default-host-alist
)
379 ;; Expand `tramp-default-user' and `tramp-default-host'.
380 (should (string-equal
381 (file-remote-p "/method::")
382 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
383 (should (string-equal (file-remote-p "/method::" 'method
) "method"))
384 (should (string-equal (file-remote-p "/method::" 'user
) "default-user"))
385 (should (string-equal (file-remote-p "/method::" 'host
) "default-host"))
386 (should (string-equal (file-remote-p "/method::" 'localname
) ""))
387 (should (string-equal (file-remote-p "/method::" 'hop
) nil
))
389 ;; Expand `tramp-default-method' and `tramp-default-user'.
390 (should (string-equal
391 (file-remote-p "/-:host:")
392 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
393 (should (string-equal (file-remote-p "/-:host:" 'method
) "default-method"))
394 (should (string-equal (file-remote-p "/-:host:" 'user
) "default-user"))
395 (should (string-equal (file-remote-p "/-:host:" 'host
) "host"))
396 (should (string-equal (file-remote-p "/-:host:" 'localname
) ""))
397 (should (string-equal (file-remote-p "/-:host:" 'hop
) nil
))
399 ;; Expand `tramp-default-method' and `tramp-default-host'.
400 (should (string-equal
401 (file-remote-p "/-:user@:")
402 (format "/%s:%s@%s:" "default-method" "user" "default-host")))
403 (should (string-equal (file-remote-p "/-:user@:" 'method
) "default-method"))
404 (should (string-equal (file-remote-p "/-:user@:" 'user
) "user"))
405 (should (string-equal (file-remote-p "/-:user@:" 'host
) "default-host"))
406 (should (string-equal (file-remote-p "/-:user@:" 'localname
) ""))
407 (should (string-equal (file-remote-p "/-:user@:" 'hop
) nil
))
409 ;; Expand `tramp-default-method'.
410 (should (string-equal
411 (file-remote-p "/-:user@host:")
412 (format "/%s:%s@%s:" "default-method" "user" "host")))
413 (should (string-equal
414 (file-remote-p "/-:user@host:" 'method
) "default-method"))
415 (should (string-equal (file-remote-p "/-:user@host:" 'user
) "user"))
416 (should (string-equal (file-remote-p "/-:user@host:" 'host
) "host"))
417 (should (string-equal (file-remote-p "/-:user@host:" 'localname
) ""))
418 (should (string-equal (file-remote-p "/-:user@host:" 'hop
) nil
))
420 ;; Expand `tramp-default-user'.
421 (should (string-equal
422 (file-remote-p "/method:host:")
423 (format "/%s:%s@%s:" "method" "default-user" "host")))
424 (should (string-equal (file-remote-p "/method:host:" 'method
) "method"))
425 (should (string-equal (file-remote-p "/method:host:" 'user
) "default-user"))
426 (should (string-equal (file-remote-p "/method:host:" 'host
) "host"))
427 (should (string-equal (file-remote-p "/method:host:" 'localname
) ""))
428 (should (string-equal (file-remote-p "/method:host:" 'hop
) nil
))
430 ;; Expand `tramp-default-host'.
431 (should (string-equal
432 (file-remote-p "/method:user@:")
433 (format "/%s:%s@%s:" "method" "user" "default-host")))
434 (should (string-equal (file-remote-p "/method:user@:" 'method
) "method"))
435 (should (string-equal (file-remote-p "/method:user@:" 'user
) "user"))
436 (should (string-equal (file-remote-p "/method:user@:" 'host
)
438 (should (string-equal (file-remote-p "/method:user@:" 'localname
) ""))
439 (should (string-equal (file-remote-p "/method:user@:" 'hop
) nil
))
442 (should (string-equal
443 (file-remote-p "/method:user@host:")
444 (format "/%s:%s@%s:" "method" "user" "host")))
445 (should (string-equal
446 (file-remote-p "/method:user@host:" 'method
) "method"))
447 (should (string-equal (file-remote-p "/method:user@host:" 'user
) "user"))
448 (should (string-equal (file-remote-p "/method:user@host:" 'host
) "host"))
449 (should (string-equal (file-remote-p "/method:user@host:" 'localname
) ""))
450 (should (string-equal (file-remote-p "/method:user@host:" 'hop
) nil
))
453 (should (string-equal
454 (file-remote-p "/method:user@email@host:")
455 (format "/%s:%s@%s:" "method" "user@email" "host")))
456 (should (string-equal
457 (file-remote-p "/method:user@email@host:" 'method
) "method"))
458 (should (string-equal
459 (file-remote-p "/method:user@email@host:" 'user
) "user@email"))
460 (should (string-equal
461 (file-remote-p "/method:user@email@host:" 'host
) "host"))
462 (should (string-equal
463 (file-remote-p "/method:user@email@host:" 'localname
) ""))
464 (should (string-equal
465 (file-remote-p "/method:user@email@host:" 'hop
) nil
))
467 ;; Expand `tramp-default-method' and `tramp-default-user'.
468 (should (string-equal
469 (file-remote-p "/-:host#1234:")
470 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
471 (should (string-equal
472 (file-remote-p "/-:host#1234:" 'method
) "default-method"))
473 (should (string-equal (file-remote-p "/-:host#1234:" 'user
) "default-user"))
474 (should (string-equal (file-remote-p "/-:host#1234:" 'host
) "host#1234"))
475 (should (string-equal (file-remote-p "/-:host#1234:" 'localname
) ""))
476 (should (string-equal (file-remote-p "/-:host#1234:" 'hop
) nil
))
478 ;; Expand `tramp-default-method'.
479 (should (string-equal
480 (file-remote-p "/-:user@host#1234:")
481 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
482 (should (string-equal
483 (file-remote-p "/-:user@host#1234:" 'method
) "default-method"))
484 (should (string-equal (file-remote-p "/-:user@host#1234:" 'user
) "user"))
485 (should (string-equal (file-remote-p "/-:user@host#1234:" 'host
) "host#1234"))
486 (should (string-equal (file-remote-p "/-:user@host#1234:" 'localname
) ""))
487 (should (string-equal (file-remote-p "/-:user@host#1234:" 'hop
) nil
))
489 ;; Expand `tramp-default-user'.
490 (should (string-equal
491 (file-remote-p "/method:host#1234:")
492 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
493 (should (string-equal
494 (file-remote-p "/method:host#1234:" 'method
) "method"))
495 (should (string-equal
496 (file-remote-p "/method:host#1234:" 'user
) "default-user"))
497 (should (string-equal
498 (file-remote-p "/method:host#1234:" 'host
) "host#1234"))
499 (should (string-equal (file-remote-p "/method:host#1234:" 'localname
) ""))
500 (should (string-equal (file-remote-p "/method:host#1234:" 'hop
) nil
))
503 (should (string-equal
504 (file-remote-p "/method:user@host#1234:")
505 (format "/%s:%s@%s:" "method" "user" "host#1234")))
506 (should (string-equal
507 (file-remote-p "/method:user@host#1234:" 'method
) "method"))
508 (should (string-equal
509 (file-remote-p "/method:user@host#1234:" 'user
) "user"))
510 (should (string-equal
511 (file-remote-p "/method:user@host#1234:" 'host
) "host#1234"))
512 (should (string-equal
513 (file-remote-p "/method:user@host#1234:" 'localname
) ""))
514 (should (string-equal
515 (file-remote-p "/method:user@host#1234:" 'hop
) nil
))
517 ;; Expand `tramp-default-method' and `tramp-default-user'.
518 (should (string-equal
519 (file-remote-p "/-:1.2.3.4:")
520 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
521 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'method
) "default-method"))
522 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'user
) "default-user"))
523 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'host
) "1.2.3.4"))
524 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'localname
) ""))
525 (should (string-equal (file-remote-p "/-:1.2.3.4:" 'hop
) nil
))
527 ;; Expand `tramp-default-method'.
528 (should (string-equal
529 (file-remote-p "/-:user@1.2.3.4:")
530 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
531 (should (string-equal
532 (file-remote-p "/-:user@1.2.3.4:" 'method
) "default-method"))
533 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'user
) "user"))
534 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'host
) "1.2.3.4"))
535 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'localname
) ""))
536 (should (string-equal (file-remote-p "/-:user@1.2.3.4:" 'hop
) nil
))
538 ;; Expand `tramp-default-user'.
539 (should (string-equal
540 (file-remote-p "/method:1.2.3.4:")
541 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
542 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method
) "method"))
543 (should (string-equal
544 (file-remote-p "/method:1.2.3.4:" 'user
) "default-user"))
545 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host
) "1.2.3.4"))
546 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname
) ""))
547 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'hop
) nil
))
550 (should (string-equal
551 (file-remote-p "/method:user@1.2.3.4:")
552 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
553 (should (string-equal
554 (file-remote-p "/method:user@1.2.3.4:" 'method
) "method"))
555 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user
) "user"))
556 (should (string-equal
557 (file-remote-p "/method:user@1.2.3.4:" 'host
) "1.2.3.4"))
558 (should (string-equal
559 (file-remote-p "/method:user@1.2.3.4:" 'localname
) ""))
560 (should (string-equal
561 (file-remote-p "/method:user@1.2.3.4:" 'hop
) nil
))
563 ;; Expand `tramp-default-method', `tramp-default-user' and
564 ;; `tramp-default-host'.
565 (should (string-equal
566 (file-remote-p "/-:[]:")
568 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
569 (should (string-equal (file-remote-p "/-:[]:" 'method
) "default-method"))
570 (should (string-equal (file-remote-p "/-:[]:" 'user
) "default-user"))
571 (should (string-equal (file-remote-p "/-:[]:" 'host
) "default-host"))
572 (should (string-equal (file-remote-p "/-:[]:" 'localname
) ""))
573 (should (string-equal (file-remote-p "/-:[]:" 'hop
) nil
))
575 ;; Expand `tramp-default-method' and `tramp-default-user'.
576 (let ((tramp-default-host "::1"))
577 (should (string-equal
578 (file-remote-p "/-:[]:")
579 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
580 (should (string-equal (file-remote-p "/-:[]:" 'method
) "default-method"))
581 (should (string-equal (file-remote-p "/-:[]:" 'user
) "default-user"))
582 (should (string-equal (file-remote-p "/-:[]:" 'host
) "::1"))
583 (should (string-equal (file-remote-p "/-:[]:" 'localname
) ""))
584 (should (string-equal (file-remote-p "/-:[]:" 'hop
) nil
)))
586 ;; Expand `tramp-default-method' and `tramp-default-user'.
587 (should (string-equal
588 (file-remote-p "/-:[::1]:")
589 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
590 (should (string-equal (file-remote-p "/-:[::1]:" 'method
) "default-method"))
591 (should (string-equal (file-remote-p "/-:[::1]:" 'user
) "default-user"))
592 (should (string-equal (file-remote-p "/-:[::1]:" 'host
) "::1"))
593 (should (string-equal (file-remote-p "/-:[::1]:" 'localname
) ""))
594 (should (string-equal (file-remote-p "/-:[::1]:" 'hop
) nil
))
596 ;; Expand `tramp-default-method'.
597 (should (string-equal
598 (file-remote-p "/-:user@[::1]:")
599 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
600 (should (string-equal
601 (file-remote-p "/-:user@[::1]:" 'method
) "default-method"))
602 (should (string-equal (file-remote-p "/-:user@[::1]:" 'user
) "user"))
603 (should (string-equal (file-remote-p "/-:user@[::1]:" 'host
) "::1"))
604 (should (string-equal (file-remote-p "/-:user@[::1]:" 'localname
) ""))
605 (should (string-equal (file-remote-p "/-:user@[::1]:" 'hop
) nil
))
607 ;; Expand `tramp-default-user'.
608 (should (string-equal
609 (file-remote-p "/method:[::1]:")
610 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
611 (should (string-equal (file-remote-p "/method:[::1]:" 'method
) "method"))
612 (should (string-equal
613 (file-remote-p "/method:[::1]:" 'user
) "default-user"))
614 (should (string-equal (file-remote-p "/method:[::1]:" 'host
) "::1"))
615 (should (string-equal (file-remote-p "/method:[::1]:" 'localname
) ""))
616 (should (string-equal (file-remote-p "/method:[::1]:" 'hop
) nil
))
619 (should (string-equal
620 (file-remote-p "/method:user@[::1]:")
621 (format "/%s:%s@%s:" "method" "user" "[::1]")))
622 (should (string-equal
623 (file-remote-p "/method:user@[::1]:" 'method
) "method"))
624 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user
) "user"))
625 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host
) "::1"))
626 (should (string-equal
627 (file-remote-p "/method:user@[::1]:" 'localname
) ""))
628 (should (string-equal (file-remote-p "/method:user@[::1]:" 'hop
) nil
))
630 ;; Local file name part.
631 (should (string-equal (file-remote-p "/-:host:/:" 'localname
) "/:"))
632 (should (string-equal (file-remote-p "/method:::" 'localname
) ":"))
633 (should (string-equal (file-remote-p "/method:: " 'localname
) " "))
634 (should (string-equal (file-remote-p "/method::file" 'localname
) "file"))
635 (should (string-equal
636 (file-remote-p "/method::/path/to/file" 'localname
)
642 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
643 (format "/%s:%s@%s|%s:%s@%s:"
644 "method1" "user1" "host1" "method2" "user2" "host2")))
648 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method
)
653 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user
)
658 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host
)
663 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname
)
668 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'hop
)
670 "method1" "user1" "host1")))
676 "/method1:user1@host1"
677 "|method2:user2@host2"
678 "|method3:user3@host3:/path/to/file"))
679 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
680 "method1" "user1" "host1"
681 "method2" "user2" "host2"
682 "method3" "user3" "host3")))
687 "/method1:user1@host1"
688 "|method2:user2@host2"
689 "|method3:user3@host3:/path/to/file")
696 "/method1:user1@host1"
697 "|method2:user2@host2"
698 "|method3:user3@host3:/path/to/file")
705 "/method1:user1@host1"
706 "|method2:user2@host2"
707 "|method3:user3@host3:/path/to/file")
714 "/method1:user1@host1"
715 "|method2:user2@host2"
716 "|method3:user3@host3:/path/to/file")
723 "/method1:user1@host1"
724 "|method2:user2@host2"
725 "|method3:user3@host3:/path/to/file")
727 (format "%s:%s@%s|%s:%s@%s|"
728 "method1" "user1" "host1" "method2" "user2" "host2")))
730 ;; Expand `tramp-default-method-alist'.
731 (add-to-list 'tramp-default-method-alist
'("host1" "user1" "method1"))
732 (add-to-list 'tramp-default-method-alist
'("host2" "user2" "method2"))
733 (add-to-list 'tramp-default-method-alist
'("host3" "user3" "method3"))
740 "|-:user3@host3:/path/to/file"))
741 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
744 "method3" "user3" "host3")))
746 ;; Expand `tramp-default-user-alist'.
747 (add-to-list 'tramp-default-user-alist
'("method1" "host1" "user1"))
748 (add-to-list 'tramp-default-user-alist
'("method2" "host2" "user2"))
749 (add-to-list 'tramp-default-user-alist
'("method3" "host3" "user3"))
756 "|method3:host3:/path/to/file"))
757 (format "/%s:%s|%s:%s|%s:%s@%s:"
760 "method3" "user3" "host3")))
762 ;; Expand `tramp-default-host-alist'.
763 (add-to-list 'tramp-default-host-alist
'("method1" "user1" "host1"))
764 (add-to-list 'tramp-default-host-alist
'("method2" "user2" "host2"))
765 (add-to-list 'tramp-default-host-alist
'("method3" "user3" "host3"))
772 "|method3:user3@:/path/to/file"))
773 (format "/%s:%s@|%s:%s@|%s:%s@%s:"
776 "method3" "user3" "host3")))))
778 (ert-deftest tramp-test02-file-name-dissect-simplified
()
779 "Check simplified file name components."
780 :tags
'(:expensive-test
)
781 (let ((tramp-default-method "default-method")
782 (tramp-default-user "default-user")
783 (tramp-default-host "default-host")
784 tramp-default-user-alist
785 tramp-default-host-alist
786 (syntax tramp-syntax
))
789 (tramp-change-syntax 'simplified
)
790 ;; Expand `tramp-default-method' and `tramp-default-user'.
791 (should (string-equal
792 (file-remote-p "/host:")
793 (format "/%s@%s:" "default-user" "host")))
794 (should (string-equal
795 (file-remote-p "/host:" 'method
) "default-method"))
796 (should (string-equal (file-remote-p "/host:" 'user
) "default-user"))
797 (should (string-equal (file-remote-p "/host:" 'host
) "host"))
798 (should (string-equal (file-remote-p "/host:" 'localname
) ""))
799 (should (string-equal (file-remote-p "/host:" 'hop
) nil
))
801 ;; Expand `tramp-default-method' and `tramp-default-host'.
802 (should (string-equal
803 (file-remote-p "/user@:")
804 (format "/%s@%s:" "user" "default-host")))
805 (should (string-equal
806 (file-remote-p "/user@:" 'method
) "default-method"))
807 (should (string-equal (file-remote-p "/user@:" 'user
) "user"))
808 (should (string-equal (file-remote-p "/user@:" 'host
) "default-host"))
809 (should (string-equal (file-remote-p "/user@:" 'localname
) ""))
810 (should (string-equal (file-remote-p "/user@:" 'hop
) nil
))
812 ;; Expand `tramp-default-method'.
813 (should (string-equal
814 (file-remote-p "/user@host:")
815 (format "/%s@%s:" "user" "host")))
816 (should (string-equal
817 (file-remote-p "/user@host:" 'method
) "default-method"))
818 (should (string-equal (file-remote-p "/user@host:" 'user
) "user"))
819 (should (string-equal (file-remote-p "/user@host:" 'host
) "host"))
820 (should (string-equal (file-remote-p "/user@host:" 'localname
) ""))
821 (should (string-equal (file-remote-p "/user@host:" 'hop
) nil
))
824 (should (string-equal
825 (file-remote-p "/user@email@host:")
826 (format "/%s@%s:" "user@email" "host")))
827 (should (string-equal
829 "/user@email@host:" 'method
) "default-method"))
830 (should (string-equal
831 (file-remote-p "/user@email@host:" 'user
) "user@email"))
832 (should (string-equal
833 (file-remote-p "/user@email@host:" 'host
) "host"))
834 (should (string-equal
835 (file-remote-p "/user@email@host:" 'localname
) ""))
836 (should (string-equal
837 (file-remote-p "/user@email@host:" 'hop
) nil
))
839 ;; Expand `tramp-default-method' and `tramp-default-user'.
840 (should (string-equal
841 (file-remote-p "/host#1234:")
842 (format "/%s@%s:" "default-user" "host#1234")))
843 (should (string-equal
844 (file-remote-p "/host#1234:" 'method
) "default-method"))
845 (should (string-equal
846 (file-remote-p "/host#1234:" 'user
) "default-user"))
847 (should (string-equal
848 (file-remote-p "/host#1234:" 'host
) "host#1234"))
849 (should (string-equal (file-remote-p "/host#1234:" 'localname
) ""))
850 (should (string-equal (file-remote-p "/host#1234:" 'hop
) nil
))
852 ;; Expand `tramp-default-method'.
853 (should (string-equal
854 (file-remote-p "/user@host#1234:")
855 (format "/%s@%s:" "user" "host#1234")))
856 (should (string-equal
857 (file-remote-p "/user@host#1234:" 'method
) "default-method"))
858 (should (string-equal
859 (file-remote-p "/user@host#1234:" 'user
) "user"))
860 (should (string-equal
861 (file-remote-p "/user@host#1234:" 'host
) "host#1234"))
862 (should (string-equal
863 (file-remote-p "/user@host#1234:" 'localname
) ""))
864 (should (string-equal (file-remote-p "/user@host#1234:" 'hop
) nil
))
866 ;; Expand `tramp-default-method' and `tramp-default-user'.
867 (should (string-equal
868 (file-remote-p "/1.2.3.4:")
869 (format "/%s@%s:" "default-user" "1.2.3.4")))
870 (should (string-equal
871 (file-remote-p "/1.2.3.4:" 'method
) "default-method"))
872 (should (string-equal
873 (file-remote-p "/1.2.3.4:" 'user
) "default-user"))
874 (should (string-equal (file-remote-p "/1.2.3.4:" 'host
) "1.2.3.4"))
875 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname
) ""))
876 (should (string-equal (file-remote-p "/1.2.3.4:" 'hop
) nil
))
878 ;; Expand `tramp-default-method'.
879 (should (string-equal
880 (file-remote-p "/user@1.2.3.4:")
881 (format "/%s@%s:" "user" "1.2.3.4")))
882 (should (string-equal
883 (file-remote-p "/user@1.2.3.4:" 'method
) "default-method"))
884 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user
) "user"))
885 (should (string-equal
886 (file-remote-p "/user@1.2.3.4:" 'host
) "1.2.3.4"))
887 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname
) ""))
888 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'hop
) nil
))
890 ;; Expand `tramp-default-method', `tramp-default-user' and
891 ;; `tramp-default-host'.
892 (should (string-equal
893 (file-remote-p "/[]:")
895 "/%s@%s:" "default-user" "default-host")))
896 (should (string-equal
897 (file-remote-p "/[]:" 'method
) "default-method"))
898 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
899 (should (string-equal (file-remote-p "/[]:" 'host
) "default-host"))
900 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
901 (should (string-equal (file-remote-p "/[]:" 'hop
) nil
))
903 ;; Expand `tramp-default-method' and `tramp-default-user'.
904 (let ((tramp-default-host "::1"))
905 (should (string-equal
906 (file-remote-p "/[]:")
907 (format "/%s@%s:" "default-user" "[::1]")))
908 (should (string-equal
909 (file-remote-p "/[]:" 'method
) "default-method"))
910 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
911 (should (string-equal (file-remote-p "/[]:" 'host
) "::1"))
912 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
913 (should (string-equal (file-remote-p "/[]:" 'hop
) nil
)))
915 ;; Expand `tramp-default-method' and `tramp-default-user'.
916 (should (string-equal
917 (file-remote-p "/[::1]:")
918 (format "/%s@%s:" "default-user" "[::1]")))
919 (should (string-equal
920 (file-remote-p "/[::1]:" 'method
) "default-method"))
921 (should (string-equal (file-remote-p "/[::1]:" 'user
) "default-user"))
922 (should (string-equal (file-remote-p "/[::1]:" 'host
) "::1"))
923 (should (string-equal (file-remote-p "/[::1]:" 'localname
) ""))
924 (should (string-equal (file-remote-p "/[::1]:" 'hop
) nil
))
926 ;; Expand `tramp-default-method'.
927 (should (string-equal
928 (file-remote-p "/user@[::1]:")
929 (format "/%s@%s:" "user" "[::1]")))
930 (should (string-equal
931 (file-remote-p "/user@[::1]:" 'method
) "default-method"))
932 (should (string-equal (file-remote-p "/user@[::1]:" 'user
) "user"))
933 (should (string-equal (file-remote-p "/user@[::1]:" 'host
) "::1"))
934 (should (string-equal (file-remote-p "/user@[::1]:" 'localname
) ""))
935 (should (string-equal (file-remote-p "/user@[::1]:" 'hop
) nil
))
937 ;; Local file name part.
938 (should (string-equal (file-remote-p "/host:/:" 'localname
) "/:"))
939 (should (string-equal (file-remote-p "/host::" 'localname
) ":"))
940 (should (string-equal (file-remote-p "/host: " 'localname
) " "))
941 (should (string-equal (file-remote-p "/host:file" 'localname
) "file"))
942 (should (string-equal
943 (file-remote-p "/host:/path/to/file" 'localname
)
949 (file-remote-p "/user1@host1|user2@host2:/path/to/file")
950 (format "/%s@%s|%s@%s:" "user1" "host1" "user2" "host2")))
954 "/user1@host1|user2@host2:/path/to/file" 'method
)
959 "/user1@host1|user2@host2:/path/to/file" 'user
)
964 "/user1@host1|user2@host2:/path/to/file" 'host
)
969 "/user1@host1|user2@host2:/path/to/file" 'localname
)
974 "/user1@host1|user2@host2:/path/to/file" 'hop
)
975 (format "%s@%s|" "user1" "host1")))
983 "|user3@host3:/path/to/file"))
984 (format "/%s@%s|%s@%s|%s@%s:"
994 "|user3@host3:/path/to/file")
1003 "|user3@host3:/path/to/file")
1012 "|user3@host3:/path/to/file")
1021 "|user3@host3:/path/to/file")
1030 "|user3@host3:/path/to/file")
1032 (format "%s@%s|%s@%s|"
1033 "user1" "host1" "user2" "host2")))
1035 ;; Expand `tramp-default-user-alist'.
1036 (add-to-list 'tramp-default-user-alist
'(nil "host1" "user1"))
1037 (add-to-list 'tramp-default-user-alist
'(nil "host2" "user2"))
1038 (add-to-list 'tramp-default-user-alist
'(nil "host3" "user3"))
1045 "|host3:/path/to/file"))
1046 (format "/%s|%s|%s@%s:"
1051 ;; Expand `tramp-default-host-alist'.
1052 (add-to-list 'tramp-default-host-alist
'(nil "user1" "host1"))
1053 (add-to-list 'tramp-default-host-alist
'(nil "user2" "host2"))
1054 (add-to-list 'tramp-default-host-alist
'(nil "user3" "host3"))
1061 "|user3@:/path/to/file"))
1062 (format "/%s@|%s@|%s@%s:"
1068 (tramp-change-syntax syntax
))))
1070 (ert-deftest tramp-test02-file-name-dissect-separate
()
1071 "Check separate file name components."
1072 :tags
'(:expensive-test
)
1073 (let ((tramp-default-method "default-method")
1074 (tramp-default-user "default-user")
1075 (tramp-default-host "default-host")
1076 tramp-default-method-alist
1077 tramp-default-user-alist
1078 tramp-default-host-alist
1079 (syntax tramp-syntax
))
1082 (tramp-change-syntax 'separate
)
1083 ;; Expand `tramp-default-user' and `tramp-default-host'.
1084 (should (string-equal
1085 (file-remote-p "/[method/]")
1087 "/[%s/%s@%s]" "method" "default-user" "default-host")))
1088 (should (string-equal (file-remote-p "/[method/]" 'method
) "method"))
1089 (should (string-equal
1090 (file-remote-p "/[method/]" 'user
) "default-user"))
1091 (should (string-equal
1092 (file-remote-p "/[method/]" 'host
) "default-host"))
1093 (should (string-equal (file-remote-p "/[method/]" 'localname
) ""))
1094 (should (string-equal (file-remote-p "/[method/]" 'hop
) nil
))
1096 ;; Expand `tramp-default-method' and `tramp-default-user'.
1097 (should (string-equal
1098 (file-remote-p "/[/host]")
1100 "/[%s/%s@%s]" "default-method" "default-user" "host")))
1101 (should (string-equal
1102 (file-remote-p "/[/host]" 'method
) "default-method"))
1103 (should (string-equal
1104 (file-remote-p "/[/host]" 'user
) "default-user"))
1105 (should (string-equal (file-remote-p "/[/host]" 'host
) "host"))
1106 (should (string-equal (file-remote-p "/[/host]" 'localname
) ""))
1107 (should (string-equal (file-remote-p "/[/host]" 'hop
) nil
))
1109 ;; Expand `tramp-default-method' and `tramp-default-host'.
1110 (should (string-equal
1111 (file-remote-p "/[/user@]")
1113 "/[%s/%s@%s]" "default-method" "user" "default-host")))
1114 (should (string-equal
1115 (file-remote-p "/[/user@]" 'method
) "default-method"))
1116 (should (string-equal (file-remote-p "/[/user@]" 'user
) "user"))
1117 (should (string-equal
1118 (file-remote-p "/[/user@]" 'host
) "default-host"))
1119 (should (string-equal (file-remote-p "/[/user@]" 'localname
) ""))
1120 (should (string-equal (file-remote-p "/[/user@]" 'hop
) nil
))
1122 ;; Expand `tramp-default-method'.
1123 (should (string-equal
1124 (file-remote-p "/[/user@host]")
1125 (format "/[%s/%s@%s]" "default-method" "user" "host")))
1126 (should (string-equal
1127 (file-remote-p "/[/user@host]" 'method
) "default-method"))
1128 (should (string-equal (file-remote-p "/[/user@host]" 'user
) "user"))
1129 (should (string-equal (file-remote-p "/[/user@host]" 'host
) "host"))
1130 (should (string-equal (file-remote-p "/[/user@host]" 'localname
) ""))
1131 (should (string-equal (file-remote-p "/[/user@host]" 'hop
) nil
))
1133 ;; Expand `tramp-default-method' and `tramp-default-user'.
1134 (should (string-equal
1135 (file-remote-p "/[-/host]")
1137 "/[%s/%s@%s]" "default-method" "default-user" "host")))
1138 (should (string-equal
1139 (file-remote-p "/[-/host]" 'method
) "default-method"))
1140 (should (string-equal
1141 (file-remote-p "/[-/host]" 'user
) "default-user"))
1142 (should (string-equal (file-remote-p "/[-/host]" 'host
) "host"))
1143 (should (string-equal (file-remote-p "/[-/host]" 'localname
) ""))
1144 (should (string-equal (file-remote-p "/[-/host]" 'hop
) nil
))
1146 ;; Expand `tramp-default-method' and `tramp-default-host'.
1147 (should (string-equal
1148 (file-remote-p "/[-/user@]")
1150 "/[%s/%s@%s]" "default-method" "user" "default-host")))
1151 (should (string-equal
1152 (file-remote-p "/[-/user@]" 'method
) "default-method"))
1153 (should (string-equal (file-remote-p "/[-/user@]" 'user
) "user"))
1154 (should (string-equal
1155 (file-remote-p "/[-/user@]" 'host
) "default-host"))
1156 (should (string-equal (file-remote-p "/[-/user@]" 'localname
) ""))
1157 (should (string-equal (file-remote-p "/[-/user@]" 'hop
) nil
))
1159 ;; Expand `tramp-default-method'.
1160 (should (string-equal
1161 (file-remote-p "/[-/user@host]")
1162 (format "/[%s/%s@%s]" "default-method" "user" "host")))
1163 (should (string-equal
1164 (file-remote-p "/[-/user@host]" 'method
) "default-method"))
1165 (should (string-equal (file-remote-p "/[-/user@host]" 'user
) "user"))
1166 (should (string-equal (file-remote-p "/[-/user@host]" 'host
) "host"))
1167 (should (string-equal (file-remote-p "/[-/user@host]" 'localname
) ""))
1168 (should (string-equal (file-remote-p "/[-/user@host]" 'hop
) nil
))
1170 ;; Expand `tramp-default-user'.
1171 (should (string-equal
1172 (file-remote-p "/[method/host]")
1173 (format "/[%s/%s@%s]" "method" "default-user" "host")))
1174 (should (string-equal
1175 (file-remote-p "/[method/host]" 'method
) "method"))
1176 (should (string-equal
1177 (file-remote-p "/[method/host]" 'user
) "default-user"))
1178 (should (string-equal (file-remote-p "/[method/host]" 'host
) "host"))
1179 (should (string-equal (file-remote-p "/[method/host]" 'localname
) ""))
1180 (should (string-equal (file-remote-p "/[method/host]" 'hop
) nil
))
1182 ;; Expand `tramp-default-host'.
1183 (should (string-equal
1184 (file-remote-p "/[method/user@]")
1185 (format "/[%s/%s@%s]" "method" "user" "default-host")))
1186 (should (string-equal
1187 (file-remote-p "/[method/user@]" 'method
) "method"))
1188 (should (string-equal (file-remote-p "/[method/user@]" 'user
) "user"))
1189 (should (string-equal
1190 (file-remote-p "/[method/user@]" 'host
) "default-host"))
1191 (should (string-equal
1192 (file-remote-p "/[method/user@]" 'localname
) ""))
1193 (should (string-equal (file-remote-p "/[method/user@]" 'hop
) nil
))
1196 (should (string-equal
1197 (file-remote-p "/[method/user@host]")
1198 (format "/[%s/%s@%s]" "method" "user" "host")))
1199 (should (string-equal
1200 (file-remote-p "/[method/user@host]" 'method
) "method"))
1201 (should (string-equal
1202 (file-remote-p "/[method/user@host]" 'user
) "user"))
1203 (should (string-equal
1204 (file-remote-p "/[method/user@host]" 'host
) "host"))
1205 (should (string-equal
1206 (file-remote-p "/[method/user@host]" 'localname
) ""))
1207 (should (string-equal
1208 (file-remote-p "/[method/user@host]" 'hop
) nil
))
1211 (should (string-equal
1212 (file-remote-p "/[method/user@email@host]")
1213 (format "/[%s/%s@%s]" "method" "user@email" "host")))
1214 (should (string-equal
1216 "/[method/user@email@host]" 'method
) "method"))
1217 (should (string-equal
1219 "/[method/user@email@host]" 'user
) "user@email"))
1220 (should (string-equal
1221 (file-remote-p "/[method/user@email@host]" 'host
) "host"))
1222 (should (string-equal
1223 (file-remote-p "/[method/user@email@host]" 'localname
) ""))
1224 (should (string-equal
1225 (file-remote-p "/[method/user@email@host]" 'hop
) nil
))
1227 ;; Expand `tramp-default-method' and `tramp-default-user'.
1228 (should (string-equal
1229 (file-remote-p "/[/host#1234]")
1231 "/[%s/%s@%s]" "default-method" "default-user" "host#1234")))
1232 (should (string-equal
1233 (file-remote-p "/[/host#1234]" 'method
) "default-method"))
1234 (should (string-equal
1235 (file-remote-p "/[/host#1234]" 'user
) "default-user"))
1236 (should (string-equal
1237 (file-remote-p "/[/host#1234]" 'host
) "host#1234"))
1238 (should (string-equal (file-remote-p "/[/host#1234]" 'localname
) ""))
1239 (should (string-equal (file-remote-p "/[/host#1234]" 'hop
) nil
))
1241 ;; Expand `tramp-default-method'.
1242 (should (string-equal
1243 (file-remote-p "/[/user@host#1234]")
1244 (format "/[%s/%s@%s]" "default-method" "user" "host#1234")))
1245 (should (string-equal
1247 "/[/user@host#1234]" 'method
) "default-method"))
1248 (should (string-equal
1250 "/[/user@host#1234]" 'user
) "user"))
1251 (should (string-equal
1252 (file-remote-p "/[/user@host#1234]" 'host
) "host#1234"))
1253 (should (string-equal
1254 (file-remote-p "/[/user@host#1234]" 'localname
) ""))
1255 (should (string-equal (file-remote-p "/[/user@host#1234]" 'hop
) nil
))
1257 ;; Expand `tramp-default-method' and `tramp-default-user'.
1258 (should (string-equal
1259 (file-remote-p "/[-/host#1234]")
1261 "/[%s/%s@%s]" "default-method" "default-user" "host#1234")))
1262 (should (string-equal
1263 (file-remote-p "/[-/host#1234]" 'method
) "default-method"))
1264 (should (string-equal
1265 (file-remote-p "/[-/host#1234]" 'user
) "default-user"))
1266 (should (string-equal
1267 (file-remote-p "/[-/host#1234]" 'host
) "host#1234"))
1268 (should (string-equal (file-remote-p "/[-/host#1234]" 'localname
) ""))
1269 (should (string-equal (file-remote-p "/[-/host#1234]" 'hop
) nil
))
1271 ;; Expand `tramp-default-method'.
1272 (should (string-equal
1273 (file-remote-p "/[-/user@host#1234]")
1274 (format "/[%s/%s@%s]" "default-method" "user" "host#1234")))
1275 (should (string-equal
1277 "/[-/user@host#1234]" 'method
) "default-method"))
1278 (should (string-equal
1280 "/[-/user@host#1234]" 'user
) "user"))
1281 (should (string-equal
1282 (file-remote-p "/[-/user@host#1234]" 'host
) "host#1234"))
1283 (should (string-equal
1284 (file-remote-p "/[-/user@host#1234]" 'localname
) ""))
1285 (should (string-equal (file-remote-p "/[-/user@host#1234]" 'hop
) nil
))
1287 ;; Expand `tramp-default-user'.
1288 (should (string-equal
1289 (file-remote-p "/[method/host#1234]")
1290 (format "/[%s/%s@%s]" "method" "default-user" "host#1234")))
1291 (should (string-equal
1292 (file-remote-p "/[method/host#1234]" 'method
) "method"))
1293 (should (string-equal
1294 (file-remote-p "/[method/host#1234]" 'user
) "default-user"))
1295 (should (string-equal
1296 (file-remote-p "/[method/host#1234]" 'host
) "host#1234"))
1297 (should (string-equal
1298 (file-remote-p "/[method/host#1234]" 'localname
) ""))
1299 (should (string-equal (file-remote-p "/[method/host#1234]" 'hop
) nil
))
1302 (should (string-equal
1303 (file-remote-p "/[method/user@host#1234]")
1304 (format "/[%s/%s@%s]" "method" "user" "host#1234")))
1305 (should (string-equal
1306 (file-remote-p "/[method/user@host#1234]" 'method
) "method"))
1307 (should (string-equal
1308 (file-remote-p "/[method/user@host#1234]" 'user
) "user"))
1309 (should (string-equal
1311 "/[method/user@host#1234]" 'host
) "host#1234"))
1312 (should (string-equal
1313 (file-remote-p "/[method/user@host#1234]" 'localname
) ""))
1314 (should (string-equal
1315 (file-remote-p "/[method/user@host#1234]" 'hop
) nil
))
1317 ;; Expand `tramp-default-method' and `tramp-default-user'.
1318 (should (string-equal
1319 (file-remote-p "/[/1.2.3.4]")
1321 "/[%s/%s@%s]" "default-method" "default-user" "1.2.3.4")))
1322 (should (string-equal
1323 (file-remote-p "/[/1.2.3.4]" 'method
) "default-method"))
1324 (should (string-equal
1325 (file-remote-p "/[/1.2.3.4]" 'user
) "default-user"))
1326 (should (string-equal
1327 (file-remote-p "/[/1.2.3.4]" 'host
) "1.2.3.4"))
1328 (should (string-equal (file-remote-p "/[/1.2.3.4]" 'localname
) ""))
1329 (should (string-equal (file-remote-p "/[/1.2.3.4]" 'hop
) nil
))
1331 ;; Expand `tramp-default-method'.
1332 (should (string-equal
1333 (file-remote-p "/[/user@1.2.3.4]")
1334 (format "/[%s/%s@%s]" "default-method" "user" "1.2.3.4")))
1335 (should (string-equal
1337 "/[/user@1.2.3.4]" 'method
) "default-method"))
1338 (should (string-equal
1339 (file-remote-p "/[/user@1.2.3.4]" 'user
) "user"))
1340 (should (string-equal
1341 (file-remote-p "/[/user@1.2.3.4]" 'host
) "1.2.3.4"))
1342 (should (string-equal
1343 (file-remote-p "/[/user@1.2.3.4]" 'localname
) ""))
1344 (should (string-equal (file-remote-p "/[/user@1.2.3.4]" 'hop
) nil
))
1346 ;; Expand `tramp-default-method' and `tramp-default-user'.
1347 (should (string-equal
1348 (file-remote-p "/[-/1.2.3.4]")
1350 "/[%s/%s@%s]" "default-method" "default-user" "1.2.3.4")))
1351 (should (string-equal
1352 (file-remote-p "/[-/1.2.3.4]" 'method
) "default-method"))
1353 (should (string-equal
1354 (file-remote-p "/[-/1.2.3.4]" 'user
) "default-user"))
1355 (should (string-equal
1356 (file-remote-p "/[-/1.2.3.4]" 'host
) "1.2.3.4"))
1357 (should (string-equal (file-remote-p "/[-/1.2.3.4]" 'localname
) ""))
1358 (should (string-equal (file-remote-p "/[-/1.2.3.4]" 'hop
) nil
))
1360 ;; Expand `tramp-default-method'.
1361 (should (string-equal
1362 (file-remote-p "/[-/user@1.2.3.4]")
1363 (format "/[%s/%s@%s]" "default-method" "user" "1.2.3.4")))
1364 (should (string-equal
1366 "/[-/user@1.2.3.4]" 'method
) "default-method"))
1367 (should (string-equal
1368 (file-remote-p "/[-/user@1.2.3.4]" 'user
) "user"))
1369 (should (string-equal
1370 (file-remote-p "/[-/user@1.2.3.4]" 'host
) "1.2.3.4"))
1371 (should (string-equal
1372 (file-remote-p "/[-/user@1.2.3.4]" 'localname
) ""))
1373 (should (string-equal (file-remote-p "/[-/user@1.2.3.4]" 'hop
) nil
))
1375 ;; Expand `tramp-default-user'.
1376 (should (string-equal
1377 (file-remote-p "/[method/1.2.3.4]")
1378 (format "/[%s/%s@%s]" "method" "default-user" "1.2.3.4")))
1379 (should (string-equal
1380 (file-remote-p "/[method/1.2.3.4]" 'method
) "method"))
1381 (should (string-equal
1382 (file-remote-p "/[method/1.2.3.4]" 'user
) "default-user"))
1383 (should (string-equal
1384 (file-remote-p "/[method/1.2.3.4]" 'host
) "1.2.3.4"))
1385 (should (string-equal
1386 (file-remote-p "/[method/1.2.3.4]" 'localname
) ""))
1387 (should (string-equal (file-remote-p "/[method/1.2.3.4]" 'hop
) nil
))
1390 (should (string-equal
1391 (file-remote-p "/[method/user@1.2.3.4]")
1392 (format "/[%s/%s@%s]" "method" "user" "1.2.3.4")))
1393 (should (string-equal
1394 (file-remote-p "/[method/user@1.2.3.4]" 'method
) "method"))
1395 (should (string-equal
1396 (file-remote-p "/[method/user@1.2.3.4]" 'user
) "user"))
1397 (should (string-equal
1398 (file-remote-p "/[method/user@1.2.3.4]" 'host
) "1.2.3.4"))
1399 (should (string-equal
1400 (file-remote-p "/[method/user@1.2.3.4]" 'localname
) ""))
1401 (should (string-equal
1402 (file-remote-p "/[method/user@1.2.3.4]" 'hop
) nil
))
1404 ;; Expand `tramp-default-method', `tramp-default-user' and
1405 ;; `tramp-default-host'.
1406 (should (string-equal
1407 (file-remote-p "/[/]")
1410 "default-method" "default-user" "default-host")))
1411 (should (string-equal
1412 (file-remote-p "/[/]" 'method
) "default-method"))
1413 (should (string-equal (file-remote-p "/[/]" 'user
) "default-user"))
1414 (should (string-equal (file-remote-p "/[/]" 'host
) "default-host"))
1415 (should (string-equal (file-remote-p "/[/]" 'localname
) ""))
1416 (should (string-equal (file-remote-p "/[/]" 'hop
) nil
))
1418 ;; Expand `tramp-default-method' and `tramp-default-user'.
1419 (let ((tramp-default-host "::1"))
1420 (should (string-equal
1421 (file-remote-p "/[/]")
1424 "default-method" "default-user" "::1")))
1425 (should (string-equal
1426 (file-remote-p "/[/]" 'method
) "default-method"))
1427 (should (string-equal (file-remote-p "/[/]" 'user
) "default-user"))
1428 (should (string-equal (file-remote-p "/[/]" 'host
) "::1"))
1429 (should (string-equal (file-remote-p "/[/]" 'localname
) ""))
1430 (should (string-equal (file-remote-p "/[/]" 'hop
) nil
)))
1432 ;; Expand `tramp-default-method' and `tramp-default-user'.
1433 (should (string-equal
1434 (file-remote-p "/[/::1]")
1436 "/[%s/%s@%s]" "default-method" "default-user" "::1")))
1437 (should (string-equal
1438 (file-remote-p "/[/::1]" 'method
) "default-method"))
1439 (should (string-equal
1440 (file-remote-p "/[/::1]" 'user
) "default-user"))
1441 (should (string-equal (file-remote-p "/[/::1]" 'host
) "::1"))
1442 (should (string-equal (file-remote-p "/[/::1]" 'localname
) ""))
1443 (should (string-equal (file-remote-p "/[/::1]" 'hop
) nil
))
1445 ;; Expand `tramp-default-method'.
1446 (should (string-equal
1447 (file-remote-p "/[/user@::1]")
1448 (format "/[%s/%s@%s]" "default-method" "user" "::1")))
1449 (should (string-equal
1450 (file-remote-p "/[/user@::1]" 'method
) "default-method"))
1451 (should (string-equal (file-remote-p "/[/user@::1]" 'user
) "user"))
1452 (should (string-equal (file-remote-p "/[/user@::1]" 'host
) "::1"))
1453 (should (string-equal (file-remote-p "/[/user@::1]" 'localname
) ""))
1454 (should (string-equal (file-remote-p "/[/user@::1]" 'hop
) nil
))
1456 ;; Expand `tramp-default-method', `tramp-default-user' and
1457 ;; `tramp-default-host'.
1458 (should (string-equal
1459 (file-remote-p "/[-/]")
1462 "default-method" "default-user" "default-host")))
1463 (should (string-equal
1464 (file-remote-p "/[-/]" 'method
) "default-method"))
1465 (should (string-equal (file-remote-p "/[-/]" 'user
) "default-user"))
1466 (should (string-equal (file-remote-p "/[-/]" 'host
) "default-host"))
1467 (should (string-equal (file-remote-p "/[-/]" 'localname
) ""))
1468 (should (string-equal (file-remote-p "/[-/]" 'hop
) nil
))
1470 ;; Expand `tramp-default-method' and `tramp-default-user'.
1471 (let ((tramp-default-host "::1"))
1472 (should (string-equal
1473 (file-remote-p "/[-/]")
1476 "default-method" "default-user" "::1")))
1477 (should (string-equal
1478 (file-remote-p "/[-/]" 'method
) "default-method"))
1479 (should (string-equal (file-remote-p "/[-/]" 'user
) "default-user"))
1480 (should (string-equal (file-remote-p "/[-/]" 'host
) "::1"))
1481 (should (string-equal (file-remote-p "/[-/]" 'localname
) ""))
1482 (should (string-equal (file-remote-p "/[-/]" 'hop
) nil
)))
1484 ;; Expand `tramp-default-method' and `tramp-default-user'.
1485 (should (string-equal
1486 (file-remote-p "/[-/::1]")
1488 "/[%s/%s@%s]" "default-method" "default-user" "::1")))
1489 (should (string-equal
1490 (file-remote-p "/[-/::1]" 'method
) "default-method"))
1491 (should (string-equal
1492 (file-remote-p "/[-/::1]" 'user
) "default-user"))
1493 (should (string-equal (file-remote-p "/[-/::1]" 'host
) "::1"))
1494 (should (string-equal (file-remote-p "/[-/::1]" 'localname
) ""))
1495 (should (string-equal (file-remote-p "/[-/::1]" 'hop
) nil
))
1497 ;; Expand `tramp-default-method'.
1498 (should (string-equal
1499 (file-remote-p "/[-/user@::1]")
1500 (format "/[%s/%s@%s]" "default-method" "user" "::1")))
1501 (should (string-equal
1502 (file-remote-p "/[-/user@::1]" 'method
) "default-method"))
1503 (should (string-equal (file-remote-p "/[-/user@::1]" 'user
) "user"))
1504 (should (string-equal (file-remote-p "/[-/user@::1]" 'host
) "::1"))
1505 (should (string-equal (file-remote-p "/[-/user@::1]" 'localname
) ""))
1506 (should (string-equal (file-remote-p "/[-/user@::1]" 'hop
) nil
))
1508 ;; Expand `tramp-default-user'.
1509 (should (string-equal
1510 (file-remote-p "/[method/::1]")
1511 (format "/[%s/%s@%s]" "method" "default-user" "::1")))
1512 (should (string-equal
1513 (file-remote-p "/[method/::1]" 'method
) "method"))
1514 (should (string-equal
1515 (file-remote-p "/[method/::1]" 'user
) "default-user"))
1516 (should (string-equal (file-remote-p "/[method/::1]" 'host
) "::1"))
1517 (should (string-equal (file-remote-p "/[method/::1]" 'localname
) ""))
1518 (should (string-equal (file-remote-p "/[method/::1]" 'hop
) nil
))
1521 (should (string-equal
1522 (file-remote-p "/[method/user@::1]")
1523 (format "/[%s/%s@%s]" "method" "user" "::1")))
1524 (should (string-equal
1525 (file-remote-p "/[method/user@::1]" 'method
) "method"))
1526 (should (string-equal
1527 (file-remote-p "/[method/user@::1]" 'user
) "user"))
1528 (should (string-equal
1529 (file-remote-p "/[method/user@::1]" 'host
) "::1"))
1530 (should (string-equal
1531 (file-remote-p "/[method/user@::1]" 'localname
) ""))
1532 (should (string-equal (file-remote-p "/[method/user@::1]" 'hop
) nil
))
1534 ;; Local file name part.
1535 (should (string-equal (file-remote-p "/[/host]/:" 'localname
) "/:"))
1536 (should (string-equal (file-remote-p "/[-/host]/:" 'localname
) "/:"))
1537 (should (string-equal (file-remote-p "/[method/]:" 'localname
) ":"))
1538 (should (string-equal (file-remote-p "/[method/] " 'localname
) " "))
1539 (should (string-equal
1540 (file-remote-p "/[method/]file" 'localname
) "file"))
1541 (should (string-equal
1542 (file-remote-p "/[method/]/path/to/file" 'localname
)
1549 "/[method1/user1@host1|method2/user2@host2]/path/to/file")
1550 (format "/[%s/%s@%s|%s/%s@%s]"
1551 "method1" "user1" "host1" "method2" "user2" "host2")))
1555 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'method
)
1560 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'user
)
1565 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'host
)
1570 "/[method1/user1@host1|method2/user2@host2]/path/to/file"
1576 "/[method1/user1@host1|method2/user2@host2]/path/to/file" 'hop
)
1578 "method1" "user1" "host1")))
1584 "/[method1/user1@host1"
1585 "|method2/user2@host2"
1586 "|method3/user3@host3]/path/to/file"))
1587 (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
1588 "method1" "user1" "host1"
1589 "method2" "user2" "host2"
1590 "method3" "user3" "host3")))
1595 "/[method1/user1@host1"
1596 "|method2/user2@host2"
1597 "|method3/user3@host3]/path/to/file")
1604 "/[method1/user1@host1"
1605 "|method2/user2@host2"
1606 "|method3/user3@host3]/path/to/file")
1613 "/[method1/user1@host1"
1614 "|method2/user2@host2"
1615 "|method3/user3@host3]/path/to/file")
1622 "/[method1/user1@host1"
1623 "|method2/user2@host2"
1624 "|method3/user3@host3]/path/to/file")
1631 "/[method1/user1@host1"
1632 "|method2/user2@host2"
1633 "|method3/user3@host3]/path/to/file")
1635 (format "%s/%s@%s|%s/%s@%s|"
1636 "method1" "user1" "host1" "method2" "user2" "host2")))
1638 ;; Expand `tramp-default-method-alist'.
1639 (add-to-list 'tramp-default-method-alist
'("host1" "user1" "method1"))
1640 (add-to-list 'tramp-default-method-alist
'("host2" "user2" "method2"))
1641 (add-to-list 'tramp-default-method-alist
'("host3" "user3" "method3"))
1648 "|/user3@host3]/path/to/file"))
1649 (format "/[/%s@%s|/%s@%s|%s/%s@%s]"
1652 "method3" "user3" "host3")))
1654 ;; Expand `tramp-default-user-alist'.
1655 (add-to-list 'tramp-default-user-alist
'("method1" "host1" "user1"))
1656 (add-to-list 'tramp-default-user-alist
'("method2" "host2" "user2"))
1657 (add-to-list 'tramp-default-user-alist
'("method3" "host3" "user3"))
1664 "|method3/host3]/path/to/file"))
1665 (format "/[%s/%s|%s/%s|%s/%s@%s]"
1668 "method3" "user3" "host3")))
1670 ;; Expand `tramp-default-host-alist'.
1671 (add-to-list 'tramp-default-host-alist
'("method1" "user1" "host1"))
1672 (add-to-list 'tramp-default-host-alist
'("method2" "user2" "host2"))
1673 (add-to-list 'tramp-default-host-alist
'("method3" "user3" "host3"))
1680 "|method3/user3@]/path/to/file"))
1681 (format "/[%s/%s@|%s/%s@|%s/%s@%s]"
1684 "method3" "user3" "host3"))))
1687 (tramp-change-syntax syntax
))))
1689 (ert-deftest tramp-test03-file-name-defaults
()
1690 "Check default values for some methods."
1691 ;; Default values in tramp-adb.el.
1692 (should (string-equal (file-remote-p "/adb::" 'host
) ""))
1693 ;; Default values in tramp-ftp.el.
1694 (should (string-equal (file-remote-p "/-:ftp.host:" 'method
) "ftp"))
1695 (dolist (u '("ftp" "anonymous"))
1696 (should (string-equal (file-remote-p (format "/-:%s@:" u
) 'method
) "ftp")))
1697 ;; Default values in tramp-gvfs.el.
1698 (when (and (load "tramp-gvfs" 'noerror
'nomessage
)
1699 (symbol-value 'tramp-gvfs-enabled
))
1700 (should (string-equal (file-remote-p "/synce::" 'user
) nil
)))
1701 ;; Default values in tramp-sh.el.
1702 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
1704 (string-equal (file-remote-p (format "/-:root@%s:" h
) 'method
) "su")))
1705 (dolist (m '("su" "sudo" "ksu"))
1706 (should (string-equal (file-remote-p (format "/%s::" m
) 'user
) "root")))
1707 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
1709 (string-equal (file-remote-p (format "/%s::" m
) 'user
) (user-login-name))))
1710 ;; Default values in tramp-smb.el.
1711 (should (string-equal (file-remote-p "/smb::" 'user
) nil
)))
1713 (ert-deftest tramp-test04-substitute-in-file-name
()
1714 "Check `substitute-in-file-name'."
1715 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
1718 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
1720 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
1721 ;; Quoting local part.
1724 (substitute-in-file-name "/method:host:/://foo") "/method:host:/://foo"))
1727 (substitute-in-file-name "/method:host:/:/path//foo")
1728 "/method:host:/:/path//foo"))
1731 (substitute-in-file-name "/method:host:/:/path///foo")
1732 "/method:host:/:/path///foo"))
1736 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
1738 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
1739 ;; Quoting local part.
1742 (substitute-in-file-name "/method:host:/:/path/~/foo")
1743 "/method:host:/:/path/~/foo"))
1746 (substitute-in-file-name "/method:host:/:/path//~/foo")
1747 "/method:host:/:/path//~/foo"))
1749 (let (process-environment)
1752 (substitute-in-file-name "/method:host:/path/$FOO")
1753 "/method:host:/path/$FOO"))
1754 (setenv "FOO" "bla")
1757 (substitute-in-file-name "/method:host:/path/$FOO")
1758 "/method:host:/path/bla"))
1761 (substitute-in-file-name "/method:host:/path/$$FOO")
1762 "/method:host:/path/$FOO"))
1763 ;; Quoting local part.
1766 (substitute-in-file-name "/method:host:/:/path/$FOO")
1767 "/method:host:/:/path/$FOO"))
1768 (setenv "FOO" "bla")
1771 (substitute-in-file-name "/method:host:/:/path/$FOO")
1772 "/method:host:/:/path/$FOO"))
1775 (substitute-in-file-name "/method:host:/:/path/$$FOO")
1776 "/method:host:/:/path/$$FOO"))))
1778 (ert-deftest tramp-test05-expand-file-name
()
1779 "Check `expand-file-name'."
1782 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
1785 (expand-file-name "/method:host:/path/../file") "/method:host:/file"))
1786 ;; Quoting local part.
1789 (expand-file-name "/method:host:/:/path/./file")
1790 "/method:host:/:/path/file"))
1793 (expand-file-name "/method:host:/:/path/../file") "/method:host:/:/file"))
1796 (expand-file-name "/method:host:/:/~/path/./file")
1797 "/method:host:/:/~/path/file")))
1799 ;; The following test is inspired by Bug#26911. It is rather a bug in
1800 ;; `expand-file-name', and it fails for all Emacs versions. Test
1801 ;; added for later, when it is fixed.
1802 (ert-deftest tramp-test05-expand-file-name-relative
()
1803 "Check `expand-file-name'."
1804 ;; Mark as failed until bug has been fixed.
1805 :expected-result
:failed
1806 (skip-unless (tramp--test-enabled))
1807 ;; These are the methods the test doesn't fail.
1808 (when (or (tramp--test-adb-p) (tramp--test-gvfs-p)
1809 (tramp-smb-file-name-p tramp-test-temporary-file-directory
))
1810 (setf (ert-test-expected-result-type
1811 (ert-get-test 'tramp-test05-expand-file-name-relative
))
1816 (let ((default-directory
1818 (file-remote-p tramp-test-temporary-file-directory
) "/path")))
1819 (expand-file-name ".." "./"))
1820 (concat (file-remote-p tramp-test-temporary-file-directory
) "/"))))
1822 (ert-deftest tramp-test06-directory-file-name
()
1823 "Check `directory-file-name'.
1824 This checks also `file-name-as-directory', `file-name-directory',
1825 `file-name-nondirectory' and `unhandled-file-name-directory'."
1828 (directory-file-name "/method:host:/path/to/file")
1829 "/method:host:/path/to/file"))
1832 (directory-file-name "/method:host:/path/to/file/")
1833 "/method:host:/path/to/file"))
1836 (directory-file-name "/method:host:/path/to/file//")
1837 "/method:host:/path/to/file"))
1840 (file-name-as-directory "/method:host:/path/to/file")
1841 "/method:host:/path/to/file/"))
1844 (file-name-as-directory "/method:host:/path/to/file/")
1845 "/method:host:/path/to/file/"))
1848 (file-name-directory "/method:host:/path/to/file")
1849 "/method:host:/path/to/"))
1852 (file-name-directory "/method:host:/path/to/file/")
1853 "/method:host:/path/to/file/"))
1855 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
1857 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
1859 (unhandled-file-name-directory "/method:host:/path/to/file"))
1862 (when (tramp--test-enabled) ;; Packages like tramp-gvfs.el might be disabled.
1863 (dolist (n-e '(nil t
))
1864 ;; We must clear `tramp-default-method'. On hydra, it is "ftp",
1865 ;; which ruins the tests.
1866 (let ((non-essential n-e
)
1867 tramp-default-method
)
1872 (file-remote-p tramp-test-temporary-file-directory
'method
))
1875 (file-remote-p tramp-test-temporary-file-directory
'host
))))
1876 (should (string-equal (directory-file-name file
) file
))
1879 (file-name-as-directory file
)
1880 (if (tramp-completion-mode-p)
1881 file
(concat file
"./"))))
1882 (should (string-equal (file-name-directory file
) file
))
1883 (should (string-equal (file-name-nondirectory file
) "")))))))
1885 (ert-deftest tramp-test07-file-exists-p
()
1886 "Check `file-exist-p', `write-region' and `delete-file'."
1887 (skip-unless (tramp--test-enabled))
1889 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1890 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1891 (should-not (file-exists-p tmp-name
))
1892 (write-region "foo" nil tmp-name
)
1893 (should (file-exists-p tmp-name
))
1894 (delete-file tmp-name
)
1895 (should-not (file-exists-p tmp-name
)))))
1897 (ert-deftest tramp-test08-file-local-copy
()
1898 "Check `file-local-copy'."
1899 (skip-unless (tramp--test-enabled))
1901 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1902 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
1906 (write-region "foo" nil tmp-name1
)
1907 (should (setq tmp-name2
(file-local-copy tmp-name1
)))
1909 (insert-file-contents tmp-name2
)
1910 (should (string-equal (buffer-string) "foo")))
1911 ;; Check also that a file transfer with compression works.
1912 (let ((default-directory tramp-test-temporary-file-directory
)
1913 (tramp-copy-size-limit 4)
1914 (tramp-inline-compress-start-size 2))
1915 (delete-file tmp-name2
)
1916 (should (setq tmp-name2
(file-local-copy tmp-name1
))))
1918 (delete-file tmp-name1
)
1919 (delete-file tmp-name2
)
1921 (setq tmp-name2
(file-local-copy tmp-name1
))
1922 :type tramp-file-missing
))
1926 (delete-file tmp-name1
)
1927 (delete-file tmp-name2
))))))
1929 (ert-deftest tramp-test09-insert-file-contents
()
1930 "Check `insert-file-contents'."
1931 (skip-unless (tramp--test-enabled))
1933 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1934 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1937 (write-region "foo" nil tmp-name
)
1938 (insert-file-contents tmp-name
)
1939 (should (string-equal (buffer-string) "foo"))
1940 (insert-file-contents tmp-name
)
1941 (should (string-equal (buffer-string) "foofoo"))
1943 (insert-file-contents tmp-name nil
1 3)
1944 (should (string-equal (buffer-string) "oofoofoo"))
1946 (insert-file-contents tmp-name nil nil nil
'replace
)
1947 (should (string-equal (buffer-string) "foo"))
1949 (delete-file tmp-name
)
1951 (insert-file-contents tmp-name
)
1952 :type tramp-file-missing
))
1955 (ignore-errors (delete-file tmp-name
))))))
1957 (ert-deftest tramp-test10-write-region
()
1958 "Check `write-region'."
1959 (skip-unless (tramp--test-enabled))
1961 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
1962 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
1965 ;; Write buffer. Use absolute and relative file name.
1968 (write-region nil nil tmp-name
))
1970 (insert-file-contents tmp-name
)
1971 (should (string-equal (buffer-string) "foo")))
1972 (delete-file tmp-name
)
1975 (should-not (file-exists-p tmp-name
))
1976 (let ((default-directory (file-name-directory tmp-name
)))
1977 (should-not (file-exists-p (file-name-nondirectory tmp-name
)))
1978 (write-region nil nil
(file-name-nondirectory tmp-name
))
1979 (should (file-exists-p (file-name-nondirectory tmp-name
))))
1980 (should (file-exists-p tmp-name
)))
1982 (insert-file-contents tmp-name
)
1983 (should (string-equal (buffer-string) "foo")))
1988 (write-region nil nil tmp-name
'append
))
1990 (insert-file-contents tmp-name
)
1991 (should (string-equal (buffer-string) "foobla")))
1994 (write-region nil nil tmp-name
3))
1996 (insert-file-contents tmp-name
)
1997 (should (string-equal (buffer-string) "foobaz")))
2000 (write-region "foo" nil tmp-name
)
2002 (insert-file-contents tmp-name
)
2003 (should (string-equal (buffer-string) "foo")))
2007 (insert "123456789")
2008 (write-region 3 5 tmp-name
))
2010 (insert-file-contents tmp-name
)
2011 (should (string-equal (buffer-string) "34")))
2014 ;; Macro `ert-with-message-capture' was introduced in Emacs 26.1.
2015 (with-no-warnings (when (symbol-plist 'ert-with-message-capture
)
2016 (let ((tramp-message-show-message t
))
2017 (dolist (noninteractive '(nil t
))
2018 (dolist (visit '(nil t
"string" no-message
))
2019 (ert-with-message-capture tramp--test-messages
2020 (write-region "foo" nil tmp-name nil visit
)
2021 ;; We must check the last line. There could be
2022 ;; other messages from the progress reporter.
2025 (if (and (null noninteractive
)
2026 (or (eq visit t
) (null visit
) (stringp visit
)))
2027 (format "^Wrote %s\n\\'" tmp-name
) "^\\'")
2028 tramp--test-messages
))))))))
2030 ;; Do not overwrite if excluded.
2031 (cl-letf (((symbol-function 'y-or-n-p
) (lambda (_prompt) t
)))
2032 (write-region "foo" nil tmp-name nil nil nil
'mustbenew
))
2033 ;; `mustbenew' is passed to Tramp since Emacs 26.1.
2034 (when (tramp--test-emacs26-p)
2036 (cl-letf (((symbol-function 'y-or-n-p
) 'ignore
))
2037 (write-region "foo" nil tmp-name nil nil nil
'mustbenew
))
2038 :type
'file-already-exists
)
2040 (write-region "foo" nil tmp-name nil nil nil
'excl
)
2041 :type
'file-already-exists
)))
2044 (ignore-errors (delete-file tmp-name
))))))
2046 (ert-deftest tramp-test11-copy-file
()
2047 "Check `copy-file'."
2048 (skip-unless (tramp--test-enabled))
2050 ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
2051 (dolist (quoted (if (and tramp--test-expensive-test
(tramp--test-emacs26-p))
2053 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2054 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2055 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
2056 (dolist (source-target
2057 `(;; Copy on remote side.
2058 (,tmp-name1 .
,tmp-name2
)
2059 ;; Copy from remote side to local side.
2060 (,tmp-name1 .
,tmp-name3
)
2061 ;; Copy from local side to remote side.
2062 (,tmp-name3 .
,tmp-name1
)))
2063 (let ((source (car source-target
))
2064 (target (cdr source-target
)))
2066 ;; Copy simple file.
2069 (write-region "foo" nil source
)
2070 (should (file-exists-p source
))
2071 (copy-file source target
)
2072 (should (file-exists-p target
))
2074 (insert-file-contents target
)
2075 (should (string-equal (buffer-string) "foo")))
2077 (copy-file source target
)
2078 :type
'file-already-exists
)
2079 (copy-file source target
'ok
))
2082 (ignore-errors (delete-file source
))
2083 (ignore-errors (delete-file target
)))
2085 ;; Copy file to directory.
2087 ;; FIXME: This fails on my QNAP server, see
2088 ;; /share/Web/owncloud/data/owncloud.log
2089 (unless (tramp--test-owncloud-p)
2090 (write-region "foo" nil source
)
2091 (should (file-exists-p source
))
2092 (make-directory target
)
2093 (should (file-directory-p target
))
2094 ;; This has been changed in Emacs 26.1.
2095 (when (tramp--test-emacs26-p)
2097 (copy-file source target
)
2098 :type
'file-already-exists
))
2099 (copy-file source
(file-name-as-directory target
))
2102 (expand-file-name (file-name-nondirectory source
) target
))))
2105 (ignore-errors (delete-file source
))
2106 (ignore-errors (delete-directory target
'recursive
)))
2108 ;; Copy directory to existing directory.
2110 ;; FIXME: This fails on my QNAP server, see
2111 ;; /share/Web/owncloud/data/owncloud.log
2112 (unless (and (tramp--test-owncloud-p)
2113 (or (not (file-remote-p source
))
2114 (not (file-remote-p target
))))
2115 (make-directory source
)
2116 (should (file-directory-p source
))
2117 (write-region "foo" nil
(expand-file-name "foo" source
))
2118 (should (file-exists-p (expand-file-name "foo" source
)))
2119 (make-directory target
)
2120 (should (file-directory-p target
))
2121 ;; Directory `target' exists already, so we must use
2122 ;; `file-name-as-directory'.
2123 (copy-file source
(file-name-as-directory target
))
2127 (concat (file-name-nondirectory source
) "/foo") target
))))
2130 (ignore-errors (delete-directory source
'recursive
))
2131 (ignore-errors (delete-directory target
'recursive
)))
2133 ;; Copy directory/file to non-existing directory.
2135 ;; FIXME: This fails on my QNAP server, see
2136 ;; /share/Web/owncloud/data/owncloud.log
2138 (and (tramp--test-owncloud-p) (not (file-remote-p source
)))
2139 (make-directory source
)
2140 (should (file-directory-p source
))
2141 (write-region "foo" nil
(expand-file-name "foo" source
))
2142 (should (file-exists-p (expand-file-name "foo" source
)))
2143 (make-directory target
)
2144 (should (file-directory-p target
))
2147 (expand-file-name (file-name-nondirectory source
) target
))
2151 (concat (file-name-nondirectory source
) "/foo") target
))))
2154 (ignore-errors (delete-directory source
'recursive
))
2155 (ignore-errors (delete-directory target
'recursive
))))))))
2157 (ert-deftest tramp-test12-rename-file
()
2158 "Check `rename-file'."
2159 (skip-unless (tramp--test-enabled))
2161 ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
2162 (dolist (quoted (if (and tramp--test-expensive-test
(tramp--test-emacs26-p))
2164 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2165 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2166 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
2167 (dolist (source-target
2168 `(;; Rename on remote side.
2169 (,tmp-name1 .
,tmp-name2
)
2170 ;; Rename from remote side to local side.
2171 (,tmp-name1 .
,tmp-name3
)
2172 ;; Rename from local side to remote side.
2173 (,tmp-name3 .
,tmp-name1
)))
2174 (let ((source (car source-target
))
2175 (target (cdr source-target
)))
2177 ;; Rename simple file.
2180 (write-region "foo" nil source
)
2181 (should (file-exists-p source
))
2182 (rename-file source target
)
2183 (should-not (file-exists-p source
))
2184 (should (file-exists-p target
))
2186 (insert-file-contents target
)
2187 (should (string-equal (buffer-string) "foo")))
2188 (write-region "foo" nil source
)
2189 (should (file-exists-p source
))
2191 (rename-file source target
)
2192 :type
'file-already-exists
)
2193 (rename-file source target
'ok
)
2194 (should-not (file-exists-p source
)))
2197 (ignore-errors (delete-file source
))
2198 (ignore-errors (delete-file target
)))
2200 ;; Rename file to directory.
2203 (write-region "foo" nil source
)
2204 (should (file-exists-p source
))
2205 (make-directory target
)
2206 (should (file-directory-p target
))
2207 ;; This has been changed in Emacs 26.1.
2208 (when (tramp--test-emacs26-p)
2210 (rename-file source target
)
2211 :type
'file-already-exists
))
2212 (rename-file source
(file-name-as-directory target
))
2213 (should-not (file-exists-p source
))
2216 (expand-file-name (file-name-nondirectory source
) target
))))
2219 (ignore-errors (delete-file source
))
2220 (ignore-errors (delete-directory target
'recursive
)))
2222 ;; Rename directory to existing directory.
2224 ;; FIXME: This fails on my QNAP server, see
2225 ;; /share/Web/owncloud/data/owncloud.log
2226 (unless (tramp--test-owncloud-p)
2227 (make-directory source
)
2228 (should (file-directory-p source
))
2229 (write-region "foo" nil
(expand-file-name "foo" source
))
2230 (should (file-exists-p (expand-file-name "foo" source
)))
2231 (make-directory target
)
2232 (should (file-directory-p target
))
2233 ;; Directory `target' exists already, so we must use
2234 ;; `file-name-as-directory'.
2235 (rename-file source
(file-name-as-directory target
))
2236 (should-not (file-exists-p source
))
2240 (concat (file-name-nondirectory source
) "/foo") target
))))
2243 (ignore-errors (delete-directory source
'recursive
))
2244 (ignore-errors (delete-directory target
'recursive
)))
2246 ;; Rename directory/file to non-existing directory.
2248 ;; FIXME: This fails on my QNAP server, see
2249 ;; /share/Web/owncloud/data/owncloud.log
2250 (unless (tramp--test-owncloud-p)
2251 (make-directory source
)
2252 (should (file-directory-p source
))
2253 (write-region "foo" nil
(expand-file-name "foo" source
))
2254 (should (file-exists-p (expand-file-name "foo" source
)))
2255 (make-directory target
)
2256 (should (file-directory-p target
))
2259 (expand-file-name (file-name-nondirectory source
) target
))
2260 (should-not (file-exists-p source
))
2264 (concat (file-name-nondirectory source
) "/foo") target
))))
2267 (ignore-errors (delete-directory source
'recursive
))
2268 (ignore-errors (delete-directory target
'recursive
))))))))
2270 (ert-deftest tramp-test13-make-directory
()
2271 "Check `make-directory'.
2272 This tests also `file-directory-p' and `file-accessible-directory-p'."
2273 (skip-unless (tramp--test-enabled))
2275 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2276 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2277 (tmp-name2 (expand-file-name "foo/bar" tmp-name1
)))
2280 (make-directory tmp-name1
)
2281 (should (file-directory-p tmp-name1
))
2282 (should (file-accessible-directory-p tmp-name1
))
2283 (should-error (make-directory tmp-name2
) :type
'file-error
)
2284 (make-directory tmp-name2
'parents
)
2285 (should (file-directory-p tmp-name2
))
2286 (should (file-accessible-directory-p tmp-name2
))
2287 ;; If PARENTS is non-nil, `make-directory' shall not
2288 ;; signal an error when DIR exists already.
2289 (make-directory tmp-name2
'parents
))
2292 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2294 (ert-deftest tramp-test14-delete-directory
()
2295 "Check `delete-directory'."
2296 (skip-unless (tramp--test-enabled))
2298 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2299 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2300 ;; Delete empty directory.
2301 (make-directory tmp-name
)
2302 (should (file-directory-p tmp-name
))
2303 (delete-directory tmp-name
)
2304 (should-not (file-directory-p tmp-name
))
2305 ;; Delete non-empty directory.
2306 (make-directory tmp-name
)
2307 (should (file-directory-p tmp-name
))
2308 (write-region "foo" nil
(expand-file-name "bla" tmp-name
))
2309 (should (file-exists-p (expand-file-name "bla" tmp-name
)))
2310 (should-error (delete-directory tmp-name
) :type
'file-error
)
2311 (delete-directory tmp-name
'recursive
)
2312 (should-not (file-directory-p tmp-name
)))))
2314 (ert-deftest tramp-test15-copy-directory
()
2315 "Check `copy-directory'."
2316 (skip-unless (tramp--test-enabled))
2318 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2319 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2320 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2321 (tmp-name3 (expand-file-name
2322 (file-name-nondirectory tmp-name1
) tmp-name2
))
2323 (tmp-name4 (expand-file-name "foo" tmp-name1
))
2324 (tmp-name5 (expand-file-name "foo" tmp-name2
))
2325 (tmp-name6 (expand-file-name "foo" tmp-name3
)))
2327 ;; Copy complete directory.
2330 ;; Copy empty directory.
2331 (make-directory tmp-name1
)
2332 (write-region "foo" nil tmp-name4
)
2333 (should (file-directory-p tmp-name1
))
2334 (should (file-exists-p tmp-name4
))
2335 (copy-directory tmp-name1 tmp-name2
)
2336 (should (file-directory-p tmp-name2
))
2337 (should (file-exists-p tmp-name5
))
2338 ;; Target directory does exist already.
2339 ;; This has been changed in Emacs 26.1.
2340 (when (tramp--test-emacs26-p)
2342 (copy-directory tmp-name1 tmp-name2
)
2344 (copy-directory tmp-name1
(file-name-as-directory tmp-name2
))
2345 (should (file-directory-p tmp-name3
))
2346 (should (file-exists-p tmp-name6
)))
2350 (delete-directory tmp-name1
'recursive
)
2351 (delete-directory tmp-name2
'recursive
)))
2353 ;; Copy directory contents.
2356 ;; Copy empty directory.
2357 (make-directory tmp-name1
)
2358 (write-region "foo" nil tmp-name4
)
2359 (should (file-directory-p tmp-name1
))
2360 (should (file-exists-p tmp-name4
))
2361 (copy-directory tmp-name1 tmp-name2 nil
'parents
'contents
)
2362 (should (file-directory-p tmp-name2
))
2363 (should (file-exists-p tmp-name5
))
2364 ;; Target directory does exist already.
2365 (delete-file tmp-name5
)
2366 (should-not (file-exists-p tmp-name5
))
2368 tmp-name1
(file-name-as-directory tmp-name2
)
2369 nil
'parents
'contents
)
2370 (should (file-directory-p tmp-name2
))
2371 (should (file-exists-p tmp-name5
))
2372 (should-not (file-directory-p tmp-name3
))
2373 (should-not (file-exists-p tmp-name6
)))
2377 (delete-directory tmp-name1
'recursive
)
2378 (delete-directory tmp-name2
'recursive
))))))
2380 (ert-deftest tramp-test16-directory-files
()
2381 "Check `directory-files'."
2382 (skip-unless (tramp--test-enabled))
2384 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2385 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2386 (tmp-name2 (expand-file-name "bla" tmp-name1
))
2387 (tmp-name3 (expand-file-name "foo" tmp-name1
)))
2390 (make-directory tmp-name1
)
2391 (write-region "foo" nil tmp-name2
)
2392 (write-region "bla" nil tmp-name3
)
2393 (should (file-directory-p tmp-name1
))
2394 (should (file-exists-p tmp-name2
))
2395 (should (file-exists-p tmp-name3
))
2396 (should (equal (directory-files tmp-name1
) '("." ".." "bla" "foo")))
2397 (should (equal (directory-files tmp-name1
'full
)
2398 `(,(concat tmp-name1
"/.")
2399 ,(concat tmp-name1
"/..")
2400 ,tmp-name2
,tmp-name3
)))
2401 (should (equal (directory-files
2402 tmp-name1 nil directory-files-no-dot-files-regexp
)
2404 (should (equal (directory-files
2405 tmp-name1
'full directory-files-no-dot-files-regexp
)
2406 `(,tmp-name2
,tmp-name3
))))
2409 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2411 ;; This is not a file name handler test. But Tramp needed to apply an
2412 ;; advice for older Emacs versions, so we check that this has been fixed.
2413 (ert-deftest tramp-test16-file-expand-wildcards
()
2414 "Check `file-expand-wildcards'."
2415 (skip-unless (tramp--test-enabled))
2417 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2418 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2419 (tmp-name2 (expand-file-name "foo" tmp-name1
))
2420 (tmp-name3 (expand-file-name "bar" tmp-name1
))
2421 (tmp-name4 (expand-file-name "baz" tmp-name1
))
2422 (default-directory tmp-name1
))
2425 (make-directory tmp-name1
)
2426 (write-region "foo" nil tmp-name2
)
2427 (write-region "bar" nil tmp-name3
)
2428 (write-region "baz" nil tmp-name4
)
2429 (should (file-directory-p tmp-name1
))
2430 (should (file-exists-p tmp-name2
))
2431 (should (file-exists-p tmp-name3
))
2432 (should (file-exists-p tmp-name4
))
2434 ;; `sort' works destructive.
2436 (equal (file-expand-wildcards "*")
2437 (sort (copy-sequence '("foo" "bar" "baz")) 'string
<)))
2439 (equal (file-expand-wildcards "ba?")
2440 (sort (copy-sequence '("bar" "baz")) 'string
<)))
2442 (equal (file-expand-wildcards "ba[rz]")
2443 (sort (copy-sequence '("bar" "baz")) 'string
<)))
2447 (file-expand-wildcards "*" 'full
)
2449 (copy-sequence `(,tmp-name2
,tmp-name3
,tmp-name4
)) 'string
<)))
2452 (file-expand-wildcards "ba?" 'full
)
2453 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2456 (file-expand-wildcards "ba[rz]" 'full
)
2457 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2461 (file-expand-wildcards (concat tmp-name1
"/" "*"))
2463 (copy-sequence `(,tmp-name2
,tmp-name3
,tmp-name4
)) 'string
<)))
2466 (file-expand-wildcards (concat tmp-name1
"/" "ba?"))
2467 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<)))
2470 (file-expand-wildcards (concat tmp-name1
"/" "ba[rz]"))
2471 (sort (copy-sequence `(,tmp-name3
,tmp-name4
)) 'string
<))))
2475 (delete-directory tmp-name1
'recursive
))))))
2477 (ert-deftest tramp-test17-insert-directory
()
2478 "Check `insert-directory'."
2479 (skip-unless (tramp--test-enabled))
2481 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2483 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2484 (tmp-name2 (expand-file-name "foo" tmp-name1
))
2485 ;; We test for the summary line. Keyword "total" could be localized.
2486 (process-environment
2487 (append '("LANG=C" "LANGUAGE=C" "LC_ALL=C") process-environment
)))
2490 (make-directory tmp-name1
)
2491 (write-region "foo" nil tmp-name2
)
2492 (should (file-directory-p tmp-name1
))
2493 (should (file-exists-p tmp-name2
))
2495 (insert-directory tmp-name1 nil
)
2496 (goto-char (point-min))
2497 (should (looking-at-p (regexp-quote tmp-name1
))))
2498 ;; This has been fixed in Emacs 26.1. See Bug#29423.
2499 (when (tramp--test-emacs26-p)
2501 (insert-directory (file-name-as-directory tmp-name1
) nil
)
2502 (goto-char (point-min))
2505 (regexp-quote (file-name-as-directory tmp-name1
))))))
2507 (insert-directory tmp-name1
"-al")
2508 (goto-char (point-min))
2510 (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1
)))))
2512 (insert-directory (file-name-as-directory tmp-name1
) "-al")
2513 (goto-char (point-min))
2515 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1
)))))
2518 (file-name-as-directory tmp-name1
) "-al" nil
'full-directory-p
)
2519 (goto-char (point-min))
2523 ;; There might be a summary line.
2524 "\\(total.+[[:digit:]]+\n\\)?"
2525 ;; We don't know in which order ".", ".." and "foo" appear.
2527 "\\(.+ %s\\( ->.+\\)?\n\\)\\{%d\\}"
2528 (regexp-opt (directory-files tmp-name1
))
2529 (length (directory-files tmp-name1
))))))))
2532 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2534 (ert-deftest tramp-test17-dired-with-wildcards
()
2535 "Check `dired' with wildcards."
2536 (skip-unless (tramp--test-enabled))
2537 (skip-unless (tramp--test-sh-p))
2538 (skip-unless (not (tramp--test-rsync-p)))
2539 ;; Since Emacs 26.1.
2540 (skip-unless (fboundp 'insert-directory-wildcard-in-dir-p
))
2542 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2544 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2546 (expand-file-name (tramp--test-make-temp-name nil quoted
)))
2547 (tmp-name3 (expand-file-name "foo" tmp-name1
))
2548 (tmp-name4 (expand-file-name "bar" tmp-name2
))
2549 (tramp-test-temporary-file-directory
2551 (if quoted
'tramp-compat-file-name-quote
'identity
)
2552 tramp-test-temporary-file-directory
))
2556 (make-directory tmp-name1
)
2557 (write-region "foo" nil tmp-name3
)
2558 (should (file-directory-p tmp-name1
))
2559 (should (file-exists-p tmp-name3
))
2560 (make-directory tmp-name2
)
2561 (write-region "foo" nil tmp-name4
)
2562 (should (file-directory-p tmp-name2
))
2563 (should (file-exists-p tmp-name4
))
2565 ;; Check for expanded directory names.
2566 (with-current-buffer
2570 "tramp-test*" tramp-test-temporary-file-directory
)))
2571 (goto-char (point-min))
2576 tmp-name1 tramp-test-temporary-file-directory
))))
2577 (goto-char (point-min))
2582 tmp-name2 tramp-test-temporary-file-directory
)))))
2583 (kill-buffer buffer
)
2585 ;; Check for expanded directory and file names.
2586 (with-current-buffer
2590 "tramp-test*/*" tramp-test-temporary-file-directory
)))
2591 (goto-char (point-min))
2596 tmp-name3 tramp-test-temporary-file-directory
))))
2597 (goto-char (point-min))
2603 tramp-test-temporary-file-directory
)))))
2604 (kill-buffer buffer
)
2606 ;; Check for special characters.
2607 (setq tmp-name3
(expand-file-name "*?" tmp-name1
))
2608 (setq tmp-name4
(expand-file-name "[a-z0-9]" tmp-name2
))
2609 (write-region "foo" nil tmp-name3
)
2610 (should (file-exists-p tmp-name3
))
2611 (write-region "foo" nil tmp-name4
)
2612 (should (file-exists-p tmp-name4
))
2614 (with-current-buffer
2618 "tramp-test*/*" tramp-test-temporary-file-directory
)))
2619 (goto-char (point-min))
2624 tmp-name3 tramp-test-temporary-file-directory
))))
2625 (goto-char (point-min))
2631 tramp-test-temporary-file-directory
)))))
2632 (kill-buffer buffer
))
2635 (ignore-errors (kill-buffer buffer
))
2636 (ignore-errors (delete-directory tmp-name1
'recursive
))
2637 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
2639 ;; Method "smb" supports `make-symbolic-link' only if the remote host
2640 ;; has CIFS capabilities. tramp-adb.el and tramp-gvfs.el do not
2641 ;; support symbolic links at all.
2642 (defmacro tramp--test-ignore-make-symbolic-link-error
(&rest body
)
2643 "Run BODY, ignoring \"make-symbolic-link not supported\" file error."
2644 (declare (indent defun
) (debug t
))
2645 `(condition-case err
2648 (unless (and (eq (car err
) 'file-error
)
2649 (string-equal (error-message-string err
)
2650 "make-symbolic-link not supported"))
2651 (signal (car err
) (cdr err
))))))
2653 (ert-deftest tramp-test18-file-attributes
()
2654 "Check `file-attributes'.
2655 This tests also `file-readable-p', `file-regular-p' and
2656 `file-ownership-preserved-p'."
2657 (skip-unless (tramp--test-enabled))
2659 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2660 ;; We must use `file-truename' for the temporary directory,
2661 ;; because it could be located on a symlinked directory. This
2662 ;; would let the test fail.
2663 (let* ((tramp-test-temporary-file-directory
2664 (file-truename tramp-test-temporary-file-directory
))
2665 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
2666 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2667 ;; File name with "//".
2671 (file-remote-p tmp-name1
)
2672 (replace-regexp-in-string
2673 "/" "//" (file-remote-p tmp-name1
'localname
))))
2677 ;; `file-ownership-preserved-p' should return t for
2678 ;; non-existing files. It is implemented only in tramp-sh.el.
2679 (when (tramp--test-sh-p)
2680 (should (file-ownership-preserved-p tmp-name1
'group
)))
2681 (write-region "foo" nil tmp-name1
)
2682 (should (file-exists-p tmp-name1
))
2683 (should (file-readable-p tmp-name1
))
2684 (should (file-regular-p tmp-name1
))
2685 (when (tramp--test-sh-p)
2686 (should (file-ownership-preserved-p tmp-name1
'group
)))
2688 ;; We do not test inodes and device numbers.
2689 (setq attr
(file-attributes tmp-name1
))
2690 (should (consp attr
))
2691 (should (null (car attr
)))
2692 (should (numberp (nth 1 attr
))) ;; Link.
2693 (should (numberp (nth 2 attr
))) ;; Uid.
2694 (should (numberp (nth 3 attr
))) ;; Gid.
2695 ;; Last access time.
2696 (should (stringp (current-time-string (nth 4 attr
))))
2697 ;; Last modification time.
2698 (should (stringp (current-time-string (nth 5 attr
))))
2699 ;; Last status change time.
2700 (should (stringp (current-time-string (nth 6 attr
))))
2701 (should (numberp (nth 7 attr
))) ;; Size.
2702 (should (stringp (nth 8 attr
))) ;; Modes.
2704 (setq attr
(file-attributes tmp-name1
'string
))
2705 (should (stringp (nth 2 attr
))) ;; Uid.
2706 (should (stringp (nth 3 attr
))) ;; Gid.
2708 (tramp--test-ignore-make-symbolic-link-error
2709 (when (tramp--test-sh-p)
2710 (should (file-ownership-preserved-p tmp-name2
'group
)))
2711 (make-symbolic-link tmp-name1 tmp-name2
)
2712 (should (file-exists-p tmp-name2
))
2713 (should (file-symlink-p tmp-name2
))
2714 (when (tramp--test-sh-p)
2715 (should (file-ownership-preserved-p tmp-name2
'group
)))
2716 (setq attr
(file-attributes tmp-name2
))
2720 (if quoted
'tramp-compat-file-name-quote
'identity
)
2722 (file-remote-p (file-truename tmp-name1
) 'localname
)))
2723 (delete-file tmp-name2
))
2725 ;; Check, that "//" in symlinks are handled properly.
2727 (let ((default-directory tramp-test-temporary-file-directory
))
2731 (tramp-file-name-localname
2732 (tramp-dissect-file-name tmp-name3
))
2733 (tramp-file-name-localname
2734 (tramp-dissect-file-name tmp-name2
)))
2736 (when (file-symlink-p tmp-name2
)
2737 (setq attr
(file-attributes tmp-name2
))
2741 (tramp-file-name-localname
2742 (tramp-dissect-file-name tmp-name3
))))
2743 (delete-file tmp-name2
))
2745 (when (tramp--test-sh-p)
2746 (should (file-ownership-preserved-p tmp-name1
'group
)))
2747 (delete-file tmp-name1
)
2748 (make-directory tmp-name1
)
2749 (should (file-exists-p tmp-name1
))
2750 (should (file-readable-p tmp-name1
))
2751 (should-not (file-regular-p tmp-name1
))
2752 (when (tramp--test-sh-p)
2753 (should (file-ownership-preserved-p tmp-name1
'group
)))
2754 (setq attr
(file-attributes tmp-name1
))
2755 (should (eq (car attr
) t
)))
2758 (ignore-errors (delete-directory tmp-name1
))
2759 (ignore-errors (delete-file tmp-name1
))
2760 (ignore-errors (delete-file tmp-name2
))))))
2762 (ert-deftest tramp-test19-directory-files-and-attributes
()
2763 "Check `directory-files-and-attributes'."
2764 (skip-unless (tramp--test-enabled))
2766 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2767 ;; `directory-files-and-attributes' contains also values for
2768 ;; "../". Ensure that this doesn't change during tests, for
2769 ;; example due to handling temporary files.
2770 (let* ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
2771 (tmp-name2 (expand-file-name "bla" tmp-name1
))
2775 (make-directory tmp-name1
)
2776 (should (file-directory-p tmp-name1
))
2777 (make-directory tmp-name2
)
2778 (should (file-directory-p tmp-name2
))
2779 (write-region "foo" nil
(expand-file-name "foo" tmp-name2
))
2780 (write-region "bar" nil
(expand-file-name "bar" tmp-name2
))
2781 (write-region "boz" nil
(expand-file-name "boz" tmp-name2
))
2782 (setq attr
(directory-files-and-attributes tmp-name2
))
2783 (should (consp attr
))
2784 ;; Dumb remote shells without perl(1) or stat(1) are not
2785 ;; able to return the date correctly. They say "don't know".
2790 5 (file-attributes (expand-file-name (car elt
) tmp-name2
)))
2793 (equal (file-attributes (expand-file-name (car elt
) tmp-name2
))
2795 (setq attr
(directory-files-and-attributes tmp-name2
'full
))
2797 (unless (equal (nth 5 (file-attributes (car elt
))) '(0 0))
2799 (equal (file-attributes (car elt
)) (cdr elt
)))))
2800 (setq attr
(directory-files-and-attributes tmp-name2 nil
"^b"))
2801 (should (equal (mapcar 'car attr
) '("bar" "boz"))))
2804 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
2806 (ert-deftest tramp-test20-file-modes
()
2807 "Check `file-modes'.
2808 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
2809 (skip-unless (tramp--test-enabled))
2810 (skip-unless (tramp--test-sh-p))
2812 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2813 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
2816 (write-region "foo" nil tmp-name
)
2817 (should (file-exists-p tmp-name
))
2818 (set-file-modes tmp-name
#o777
)
2819 (should (= (file-modes tmp-name
) #o777
))
2820 (should (file-executable-p tmp-name
))
2821 (should (file-writable-p tmp-name
))
2822 (set-file-modes tmp-name
#o444
)
2823 (should (= (file-modes tmp-name
) #o444
))
2824 (should-not (file-executable-p tmp-name
))
2825 ;; A file is always writable for user "root".
2826 (unless (zerop (nth 2 (file-attributes tmp-name
)))
2827 (should-not (file-writable-p tmp-name
))))
2830 (ignore-errors (delete-file tmp-name
))))))
2832 (ert-deftest tramp-test21-file-links
()
2833 "Check `file-symlink-p'.
2834 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2835 (skip-unless (tramp--test-enabled))
2836 ;; The semantics has changed heavily in Emacs 26.1. We cannot test
2837 ;; older Emacsen, therefore.
2838 (skip-unless (tramp--test-emacs26-p))
2840 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
2841 ;; We must use `file-truename' for the temporary directory,
2842 ;; because it could be located on a symlinked directory. This
2843 ;; would let the test fail.
2844 (let* ((tramp-test-temporary-file-directory
2845 (file-truename tramp-test-temporary-file-directory
))
2846 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
2847 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
2848 (tmp-name3 (tramp--test-make-temp-name 'local quoted
))
2849 (tmp-name4 (tramp--test-make-temp-name nil quoted
))
2851 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name4
)))
2852 ;; Check `make-symbolic-link'.
2854 (tramp--test-ignore-make-symbolic-link-error
2855 (write-region "foo" nil tmp-name1
)
2856 (should (file-exists-p tmp-name1
))
2857 (make-symbolic-link tmp-name1 tmp-name2
)
2861 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2862 (file-remote-p tmp-name1
'localname
))
2863 (file-symlink-p tmp-name2
)))
2865 (make-symbolic-link tmp-name1 tmp-name2
)
2866 :type
'file-already-exists
)
2867 ;; A number means interactive case.
2868 (cl-letf (((symbol-function 'yes-or-no-p
) 'ignore
))
2870 (make-symbolic-link tmp-name1 tmp-name2
0)
2871 :type
'file-already-exists
))
2872 (cl-letf (((symbol-function 'yes-or-no-p
) (lambda (_prompt) t
)))
2873 (make-symbolic-link tmp-name1 tmp-name2
0)
2877 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2878 (file-remote-p tmp-name1
'localname
))
2879 (file-symlink-p tmp-name2
))))
2880 (make-symbolic-link tmp-name1 tmp-name2
'ok-if-already-exists
)
2884 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2885 (file-remote-p tmp-name1
'localname
))
2886 (file-symlink-p tmp-name2
)))
2887 ;; If we use the local part of `tmp-name1', it shall still work.
2889 (file-remote-p tmp-name1
'localname
)
2890 tmp-name2
'ok-if-already-exists
)
2894 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2895 (file-remote-p tmp-name1
'localname
))
2896 (file-symlink-p tmp-name2
)))
2897 ;; `tmp-name3' is a local file name. Therefore, the link
2898 ;; target remains unchanged, even if quoted.
2899 ;; `make-symbolic-link' might not be permitted on w32 systems.
2900 (unless (tramp--test-windows-nt)
2901 (make-symbolic-link tmp-name1 tmp-name3
)
2903 (string-equal tmp-name1
(file-symlink-p tmp-name3
))))
2904 ;; Check directory as newname.
2905 (make-directory tmp-name4
)
2907 (make-symbolic-link tmp-name1 tmp-name4
)
2908 :type
'file-already-exists
)
2909 (make-symbolic-link tmp-name1
(file-name-as-directory tmp-name4
))
2913 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2914 (file-remote-p tmp-name1
'localname
))
2915 (file-symlink-p tmp-name5
)))
2916 ;; `smbclient' does not show symlinks in directories, so
2917 ;; we cannot delete a non-empty directory. We delete the
2919 (delete-file tmp-name5
))
2923 (delete-file tmp-name1
)
2924 (delete-file tmp-name2
)
2925 (delete-file tmp-name3
)
2926 (delete-directory tmp-name4
'recursive
)))
2928 ;; Check `add-name-to-file'.
2931 (write-region "foo" nil tmp-name1
)
2932 (should (file-exists-p tmp-name1
))
2933 (add-name-to-file tmp-name1 tmp-name2
)
2934 (should (file-regular-p tmp-name2
))
2936 (add-name-to-file tmp-name1 tmp-name2
)
2937 :type
'file-already-exists
)
2938 ;; A number means interactive case.
2939 (cl-letf (((symbol-function 'yes-or-no-p
) 'ignore
))
2941 (add-name-to-file tmp-name1 tmp-name2
0)
2942 :type
'file-already-exists
))
2943 (cl-letf (((symbol-function 'yes-or-no-p
) (lambda (_prompt) t
)))
2944 (add-name-to-file tmp-name1 tmp-name2
0)
2945 (should (file-regular-p tmp-name2
)))
2946 (add-name-to-file tmp-name1 tmp-name2
'ok-if-already-exists
)
2947 (should-not (file-symlink-p tmp-name2
))
2948 (should (file-regular-p tmp-name2
))
2949 ;; `tmp-name3' is a local file name.
2951 (add-name-to-file tmp-name1 tmp-name3
)
2953 ;; Check directory as newname.
2954 (make-directory tmp-name4
)
2956 (add-name-to-file tmp-name1 tmp-name4
)
2957 :type
'file-already-exists
)
2958 (add-name-to-file tmp-name1
(file-name-as-directory tmp-name4
))
2961 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name4
))))
2965 (delete-file tmp-name1
)
2966 (delete-file tmp-name2
)
2967 (delete-directory tmp-name4
'recursive
)))
2969 ;; Check `file-truename'.
2971 (tramp--test-ignore-make-symbolic-link-error
2972 (write-region "foo" nil tmp-name1
)
2973 (should (file-exists-p tmp-name1
))
2974 (should (string-equal tmp-name1
(file-truename tmp-name1
)))
2975 (make-symbolic-link tmp-name1 tmp-name2
)
2976 (should (file-symlink-p tmp-name2
))
2977 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
2979 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
)))
2980 (should (file-equal-p tmp-name1 tmp-name2
))
2981 ;; Check relative symlink file name.
2982 (delete-file tmp-name2
)
2983 (let ((default-directory tramp-test-temporary-file-directory
))
2984 (make-symbolic-link (file-name-nondirectory tmp-name1
) tmp-name2
))
2985 (should (file-symlink-p tmp-name2
))
2986 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
2988 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
)))
2989 (should (file-equal-p tmp-name1 tmp-name2
))
2990 ;; Symbolic links could look like a remote file name.
2991 ;; They must be quoted then.
2992 (delete-file tmp-name2
)
2995 (if quoted
'tramp-compat-file-name-unquote
'identity
)
2998 (should (file-symlink-p tmp-name2
))
3001 (file-truename tmp-name2
)
3002 (tramp-compat-file-name-quote
3003 (concat (file-remote-p tmp-name2
) "/penguin:motd:"))))
3004 ;; `tmp-name3' is a local file name.
3005 ;; `make-symbolic-link' might not be permitted on w32 systems.
3006 (unless (tramp--test-windows-nt)
3007 (make-symbolic-link tmp-name1 tmp-name3
)
3008 (should (file-symlink-p tmp-name3
))
3009 (should-not (string-equal tmp-name3
(file-truename tmp-name3
)))
3010 ;; `file-truename' returns a quoted file name for `tmp-name3'.
3011 ;; We must unquote it.
3014 (tramp-compat-file-name-unquote (file-truename tmp-name1
))
3015 (tramp-compat-file-name-unquote (file-truename tmp-name3
))))))
3019 (delete-file tmp-name1
)
3020 (delete-file tmp-name2
)
3021 (delete-file tmp-name3
)))
3023 ;; Symbolic links could be nested.
3025 (tramp--test-ignore-make-symbolic-link-error
3026 (make-directory tmp-name1
)
3027 (should (file-directory-p tmp-name1
))
3028 (let* ((tramp-test-temporary-file-directory
3029 (file-truename tmp-name1
))
3030 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
3031 (tmp-name3 tmp-name2
)
3032 (number-nesting 15))
3033 (dotimes (_ number-nesting
)
3036 (setq tmp-name3
(tramp--test-make-temp-name nil quoted
))))
3039 (file-truename tmp-name2
)
3040 (file-truename tmp-name3
)))
3042 (with-temp-buffer (insert-file-contents tmp-name2
))
3043 :type tramp-file-missing
)
3045 (with-temp-buffer (insert-file-contents tmp-name3
))
3046 :type tramp-file-missing
)
3047 ;; `directory-files' does not show symlinks to
3048 ;; non-existing targets in the "smb" case. So we remove
3049 ;; the symlinks manually.
3050 (while (stringp (setq tmp-name2
(file-symlink-p tmp-name3
)))
3051 (delete-file tmp-name3
)
3052 (setq tmp-name3
(concat (file-remote-p tmp-name3
) tmp-name2
)))))
3055 (ignore-errors (delete-directory tmp-name1
'recursive
)))
3057 ;; Detect cyclic symbolic links.
3059 (tramp--test-ignore-make-symbolic-link-error
3060 (make-symbolic-link tmp-name2 tmp-name1
)
3061 (should (file-symlink-p tmp-name1
))
3062 (if (tramp-smb-file-name-p tramp-test-temporary-file-directory
)
3063 ;; The symlink command of `smbclient' detects the
3066 (make-symbolic-link tmp-name1 tmp-name2
)
3068 (make-symbolic-link tmp-name1 tmp-name2
)
3069 (should (file-symlink-p tmp-name2
))
3070 (should-error (file-truename tmp-name1
) :type
'file-error
)))
3074 (delete-file tmp-name1
)
3075 (delete-file tmp-name2
)))
3077 ;; `file-truename' shall preserve trailing link of directories.
3078 (unless (file-symlink-p tramp-test-temporary-file-directory
)
3079 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory
))
3080 (dir2 (file-name-as-directory dir1
)))
3081 (should (string-equal (file-truename dir1
) (expand-file-name dir1
)))
3083 (string-equal (file-truename dir2
) (expand-file-name dir2
))))))))
3085 (ert-deftest tramp-test22-file-times
()
3086 "Check `set-file-times' and `file-newer-than-file-p'."
3087 (skip-unless (tramp--test-enabled))
3088 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
3090 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3091 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3092 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
3093 (tmp-name3 (tramp--test-make-temp-name nil quoted
)))
3096 (write-region "foo" nil tmp-name1
)
3097 (should (file-exists-p tmp-name1
))
3098 (should (consp (nth 5 (file-attributes tmp-name1
))))
3099 ;; '(0 0) means don't know, and will be replaced by
3100 ;; `current-time'. Therefore, we use '(0 1). We skip the
3101 ;; test, if the remote handler is not able to set the
3103 (skip-unless (set-file-times tmp-name1
'(0 1)))
3104 ;; Dumb remote shells without perl(1) or stat(1) are not
3105 ;; able to return the date correctly. They say "don't know".
3106 (unless (equal (nth 5 (file-attributes tmp-name1
)) '(0 0))
3107 (should (equal (nth 5 (file-attributes tmp-name1
)) '(0 1)))
3108 (write-region "bla" nil tmp-name2
)
3109 (should (file-exists-p tmp-name2
))
3110 (should (file-newer-than-file-p tmp-name2 tmp-name1
))
3111 ;; `tmp-name3' does not exist.
3112 (should (file-newer-than-file-p tmp-name2 tmp-name3
))
3113 (should-not (file-newer-than-file-p tmp-name3 tmp-name1
))))
3117 (delete-file tmp-name1
)
3118 (delete-file tmp-name2
))))))
3120 (ert-deftest tramp-test23-visited-file-modtime
()
3121 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
3122 (skip-unless (tramp--test-enabled))
3124 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3125 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
3128 (write-region "foo" nil tmp-name
)
3129 (should (file-exists-p tmp-name
))
3131 (insert-file-contents tmp-name
)
3132 (should (verify-visited-file-modtime))
3133 (set-visited-file-modtime '(0 1))
3134 (should (verify-visited-file-modtime))
3135 (should (equal (visited-file-modtime) '(0 1 0 0)))))
3138 (ignore-errors (delete-file tmp-name
))))))
3140 ;; This test is inspired by Bug#29149.
3141 (ert-deftest tramp-test24-file-acl
()
3142 "Check that `file-acl' and `set-file-acl' work proper."
3143 (skip-unless (tramp--test-enabled))
3144 (skip-unless (file-acl tramp-test-temporary-file-directory
))
3146 ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
3147 (dolist (quoted (if (and tramp--test-expensive-test
(tramp--test-emacs26-p))
3149 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3150 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
3151 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
3152 ;; Both files are remote.
3155 ;; Two files with same ACLs.
3156 (write-region "foo" nil tmp-name1
)
3157 (should (file-exists-p tmp-name1
))
3158 (should (file-acl tmp-name1
))
3159 (copy-file tmp-name1 tmp-name2 nil nil nil
'preserve-permissions
)
3160 (should (file-acl tmp-name2
))
3161 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name2
)))
3162 ;; Different permissions mean different ACLs.
3163 (when (not (tramp--test-windows-nt-or-smb-p))
3164 (set-file-modes tmp-name1
#o777
)
3165 (set-file-modes tmp-name2
#o444
)
3167 (string-equal (file-acl tmp-name1
) (file-acl tmp-name2
))))
3168 ;; Copy ACL. Not all remote handlers support it, so we test.
3169 (when (set-file-acl tmp-name2
(file-acl tmp-name1
))
3170 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name2
))))
3171 ;; An invalid ACL does not harm.
3172 (should-not (set-file-acl tmp-name2
"foo")))
3175 (ignore-errors (delete-file tmp-name1
))
3176 (ignore-errors (delete-file tmp-name2
)))
3178 ;; Remote and local file.
3180 (when (and (file-acl temporary-file-directory
)
3181 (not (tramp--test-windows-nt-or-smb-p)))
3182 ;; Two files with same ACLs.
3183 (write-region "foo" nil tmp-name1
)
3184 (should (file-exists-p tmp-name1
))
3185 (should (file-acl tmp-name1
))
3186 (copy-file tmp-name1 tmp-name3 nil nil nil
'preserve-permissions
)
3187 (should (file-acl tmp-name3
))
3188 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
3189 ;; Different permissions mean different ACLs.
3190 (set-file-modes tmp-name1
#o777
)
3191 (set-file-modes tmp-name3
#o444
)
3193 (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
3194 ;; Copy ACL. Since we don't know whether Emacs is built
3195 ;; with local ACL support, we must check it.
3196 (when (set-file-acl tmp-name3
(file-acl tmp-name1
))
3197 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
))))
3199 ;; Two files with same ACLs.
3200 (delete-file tmp-name1
)
3201 (copy-file tmp-name3 tmp-name1 nil nil nil
'preserve-permissions
)
3202 (should (file-acl tmp-name1
))
3203 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
3204 ;; Different permissions mean different ACLs.
3205 (set-file-modes tmp-name1
#o777
)
3206 (set-file-modes tmp-name3
#o444
)
3208 (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
)))
3210 (set-file-acl tmp-name1
(file-acl tmp-name3
))
3211 (should (string-equal (file-acl tmp-name1
) (file-acl tmp-name3
))))
3214 (ignore-errors (delete-file tmp-name1
))
3215 (ignore-errors (delete-file tmp-name3
))))))
3217 (ert-deftest tramp-test25-file-selinux
()
3218 "Check `file-selinux-context' and `set-file-selinux-context'."
3219 (skip-unless (tramp--test-enabled))
3221 (not (equal (file-selinux-context tramp-test-temporary-file-directory
)
3222 '(nil nil nil nil
))))
3224 ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
3225 (dolist (quoted (if (and tramp--test-expensive-test
(tramp--test-emacs26-p))
3227 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3228 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
3229 (tmp-name3 (tramp--test-make-temp-name 'local quoted
)))
3230 ;; Both files are remote.
3233 ;; Two files with same SELinux context.
3234 (write-region "foo" nil tmp-name1
)
3235 (should (file-exists-p tmp-name1
))
3236 (should (file-selinux-context tmp-name1
))
3237 (copy-file tmp-name1 tmp-name2
)
3238 (should (file-selinux-context tmp-name2
))
3241 (file-selinux-context tmp-name1
)
3242 (file-selinux-context tmp-name2
)))
3243 ;; Check different SELinux context. We cannot support
3244 ;; different ranges in this test; let's assume the most
3246 (let ((context (file-selinux-context tmp-name1
)))
3247 (when (and (string-equal (nth 3 context
) "s0")
3248 (setcar (nthcdr 3 context
) "s0:c0")
3249 (set-file-selinux-context tmp-name1 context
))
3252 (file-selinux-context tmp-name1
)
3253 (file-selinux-context tmp-name2
)))))
3254 ;; Copy SELinux context.
3256 (set-file-selinux-context
3257 tmp-name2
(file-selinux-context tmp-name1
)))
3260 (file-selinux-context tmp-name1
)
3261 (file-selinux-context tmp-name2
)))
3262 ;; An invalid SELinux context does not harm.
3263 (should-not (set-file-selinux-context tmp-name2
"foo")))
3266 (ignore-errors (delete-file tmp-name1
))
3267 (ignore-errors (delete-file tmp-name2
)))
3269 ;; Remote and local file.
3272 (or (equal (file-selinux-context temporary-file-directory
)
3274 (tramp--test-windows-nt-or-smb-p)))
3275 ;; Both users shall use the same SELinux context.
3277 (let ((default-directory temporary-file-directory
))
3278 (shell-command-to-string "id -Z"))
3279 (let ((default-directory
3280 tramp-test-temporary-file-directory
))
3281 (shell-command-to-string "id -Z"))))
3283 ;; Two files with same SELinux context.
3284 (write-region "foo" nil tmp-name1
)
3285 (should (file-exists-p tmp-name1
))
3286 (should (file-selinux-context tmp-name1
))
3287 (copy-file tmp-name1 tmp-name3
)
3288 (should (file-selinux-context tmp-name3
))
3289 ;; We cannot expect that copying over file system
3290 ;; boundaries keeps SELinux context. So we copy it
3293 (set-file-selinux-context
3294 tmp-name3
(file-selinux-context tmp-name1
)))
3297 (file-selinux-context tmp-name1
)
3298 (file-selinux-context tmp-name3
)))
3299 ;; Check different SELinux context. We cannot support
3300 ;; different ranges in this test; let's assume the most
3302 (let ((context (file-selinux-context tmp-name1
)))
3303 (when (and (string-equal (nth 3 context
) "s0")
3304 (setcar (nthcdr 3 context
) "s0:c0")
3305 (set-file-selinux-context tmp-name1 context
))
3308 (file-selinux-context tmp-name1
)
3309 (file-selinux-context tmp-name3
)))))
3310 ;; Copy SELinux context.
3312 (set-file-selinux-context
3313 tmp-name3
(file-selinux-context tmp-name1
)))
3316 (file-selinux-context tmp-name1
)
3317 (file-selinux-context tmp-name3
)))
3319 ;; Two files with same SELinux context.
3320 (delete-file tmp-name1
)
3321 (copy-file tmp-name3 tmp-name1
)
3322 (should (file-selinux-context tmp-name1
))
3323 ;; We cannot expect that copying over file system
3324 ;; boundaries keeps SELinux context. So we copy it
3327 (set-file-selinux-context
3328 tmp-name1
(file-selinux-context tmp-name3
)))
3331 (file-selinux-context tmp-name1
)
3332 (file-selinux-context tmp-name3
)))
3333 ;; Check different SELinux context. We cannot support
3334 ;; different ranges in this test; let's assume the most
3336 (let ((context (file-selinux-context tmp-name3
)))
3337 (when (and (string-equal (nth 3 context
) "s0")
3338 (setcar (nthcdr 3 context
) "s0:c0")
3339 (set-file-selinux-context tmp-name3 context
))
3342 (file-selinux-context tmp-name1
)
3343 (file-selinux-context tmp-name3
)))))
3344 ;; Copy SELinux context.
3346 (set-file-selinux-context
3347 tmp-name1
(file-selinux-context tmp-name3
)))
3350 (file-selinux-context tmp-name1
)
3351 (file-selinux-context tmp-name3
))))
3354 (ignore-errors (delete-file tmp-name1
))
3355 (ignore-errors (delete-file tmp-name3
))))))
3357 (ert-deftest tramp-test26-file-name-completion
()
3358 "Check `file-name-completion' and `file-name-all-completions'."
3359 (skip-unless (tramp--test-enabled))
3361 ;; Method and host name in completion mode. This kind of completion
3362 ;; does not work on MS Windows.
3363 (when (not (memq system-type
'(cygwin windows-nt
)))
3364 (let ((method (file-remote-p tramp-test-temporary-file-directory
'method
))
3365 (host (file-remote-p tramp-test-temporary-file-directory
'host
))
3366 (orig-syntax tramp-syntax
))
3367 (when (and (stringp host
) (string-match tramp-host-with-port-regexp host
))
3368 (setq host
(match-string 1 host
)))
3373 (if tramp--test-expensive-test
3374 (tramp-syntax-values) `(,orig-syntax
)))
3375 (tramp-change-syntax syntax
)
3376 (let ;; This is needed for the `simplified' syntax.
3378 (if (zerop (length tramp-method-regexp
))
3379 "" tramp-default-method-marker
))
3380 ;; This is needed for the `separate' syntax.
3381 (prefix-format (substring tramp-prefix-format
1)))
3382 ;; Complete method name.
3383 (unless (or (zerop (length method
))
3384 (zerop (length tramp-method-regexp
)))
3387 (concat prefix-format method tramp-postfix-method-format
)
3388 (file-name-all-completions
3389 (concat prefix-format
(substring method
0 1)) "/"))))
3390 ;; Complete host name for default method. With gvfs
3391 ;; based methods, host name will be determined as
3392 ;; host.local, so we omit the test.
3393 (let ((tramp-default-method (or method tramp-default-method
)))
3394 (unless (or (zerop (length host
))
3395 (tramp--test-gvfs-p tramp-default-method
))
3399 prefix-format method-marker tramp-postfix-method-format
3400 host tramp-postfix-host-format
)
3401 (file-name-all-completions
3403 prefix-format method-marker tramp-postfix-method-format
3404 (substring host
0 1))
3406 ;; Complete host name.
3407 (unless (or (zerop (length method
))
3408 (zerop (length tramp-method-regexp
))
3409 (zerop (length host
))
3410 (tramp--test-gvfs-p method
))
3414 prefix-format method tramp-postfix-method-format
3415 host tramp-postfix-host-format
)
3416 (file-name-all-completions
3417 (concat prefix-format method tramp-postfix-method-format
)
3421 (tramp-change-syntax orig-syntax
))))
3423 (dolist (n-e '(nil t
))
3424 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3425 (let ((non-essential n-e
)
3426 (tmp-name (tramp--test-make-temp-name nil quoted
)))
3431 (make-directory tmp-name
)
3432 (should (file-directory-p tmp-name
))
3433 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
3434 (should (file-exists-p (expand-file-name "foo" tmp-name
)))
3435 (write-region "bar" nil
(expand-file-name "bold" tmp-name
))
3436 (should (file-exists-p (expand-file-name "bold" tmp-name
)))
3437 (make-directory (expand-file-name "boz" tmp-name
))
3438 (should (file-directory-p (expand-file-name "boz" tmp-name
)))
3439 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
3440 (should (equal (file-name-completion "foo" tmp-name
) t
))
3441 (should (equal (file-name-completion "b" tmp-name
) "bo"))
3442 (should-not (file-name-completion "a" tmp-name
))
3445 (file-name-completion "b" tmp-name
'file-directory-p
) "boz/"))
3447 (equal (file-name-all-completions "fo" tmp-name
) '("foo")))
3450 (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
3452 (should-not (file-name-all-completions "a" tmp-name
))
3453 ;; `completion-regexp-list' restricts the completion to
3454 ;; files which match all expressions in this list.
3455 (let ((completion-regexp-list
3456 `(,directory-files-no-dot-files-regexp
"b")))
3458 (equal (file-name-completion "" tmp-name
) "bo"))
3461 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
3463 ;; `file-name-completion' ignores file names that end in
3464 ;; any string in `completion-ignored-extensions'.
3465 (let ((completion-ignored-extensions '(".ext")))
3466 (write-region "foo" nil
(expand-file-name "foo.ext" tmp-name
))
3467 (should (file-exists-p (expand-file-name "foo.ext" tmp-name
)))
3468 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
3469 (should (equal (file-name-completion "foo" tmp-name
) t
))
3471 (equal (file-name-completion "foo." tmp-name
) "foo.ext"))
3472 (should (equal (file-name-completion "foo.ext" tmp-name
) t
))
3473 ;; `file-name-all-completions' is not affected.
3476 (sort (file-name-all-completions "" tmp-name
) 'string-lessp
)
3477 '("../" "./" "bold" "boz/" "foo" "foo.ext")))))
3480 (ignore-errors (delete-directory tmp-name
'recursive
)))))))
3482 (ert-deftest tramp-test27-load
()
3484 (skip-unless (tramp--test-enabled))
3486 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3487 (let ((tmp-name (tramp--test-make-temp-name nil quoted
)))
3490 (load tmp-name
'noerror
'nomessage
)
3491 (should-not (featurep 'tramp-test-load
))
3492 (write-region "(provide 'tramp-test-load)" nil tmp-name
)
3493 ;; `load' in lread.c does not pass `must-suffix'. Why?
3495 ;; (load tmp-name nil 'nomessage 'nosuffix 'must-suffix)
3496 ;; :type 'file-error)
3497 (load tmp-name nil
'nomessage
'nosuffix
)
3498 (should (featurep 'tramp-test-load
)))
3502 (and (featurep 'tramp-test-load
) (unload-feature 'tramp-test-load
))
3503 (delete-file tmp-name
))))))
3505 (ert-deftest tramp-test28-process-file
()
3506 "Check `process-file'."
3507 :tags
'(:expensive-test
)
3508 (skip-unless (tramp--test-enabled))
3509 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
3511 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3512 (let* ((tmp-name (tramp--test-make-temp-name nil quoted
))
3513 (fnnd (file-name-nondirectory tmp-name
))
3514 (default-directory tramp-test-temporary-file-directory
)
3515 kill-buffer-query-functions
)
3518 ;; We cannot use "/bin/true" and "/bin/false"; those paths
3519 ;; do not exist on hydra.
3520 (should (zerop (process-file "true")))
3521 (should-not (zerop (process-file "false")))
3522 (should-not (zerop (process-file "binary-does-not-exist")))
3524 (write-region "foo" nil tmp-name
)
3525 (should (file-exists-p tmp-name
))
3526 (should (zerop (process-file "ls" nil t nil fnnd
)))
3527 ;; `ls' could produce colorized output.
3528 (goto-char (point-min))
3530 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3531 (replace-match "" nil nil
))
3532 (should (string-equal (format "%s\n" fnnd
) (buffer-string)))
3533 (should-not (get-buffer-window (current-buffer) t
))
3535 ;; Second run. The output must be appended.
3536 (goto-char (point-max))
3537 (should (zerop (process-file "ls" nil t t fnnd
)))
3538 ;; `ls' could produce colorized output.
3539 (goto-char (point-min))
3541 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3542 (replace-match "" nil nil
))
3544 (string-equal (format "%s\n%s\n" fnnd fnnd
) (buffer-string)))
3545 ;; A non-nil DISPLAY must not raise the buffer.
3546 (should-not (get-buffer-window (current-buffer) t
))))
3549 (ignore-errors (delete-file tmp-name
))))))
3551 (ert-deftest tramp-test29-start-file-process
()
3552 "Check `start-file-process'."
3553 :tags
'(:expensive-test
)
3554 (skip-unless (tramp--test-enabled))
3555 (skip-unless (tramp--test-sh-p))
3557 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3558 (let ((default-directory tramp-test-temporary-file-directory
)
3559 (tmp-name (tramp--test-make-temp-name nil quoted
))
3560 kill-buffer-query-functions proc
)
3563 (setq proc
(start-file-process "test1" (current-buffer) "cat"))
3564 (should (processp proc
))
3565 (should (equal (process-status proc
) 'run
))
3566 (process-send-string proc
"foo")
3567 (process-send-eof proc
)
3569 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3570 (while (< (- (point-max) (point-min)) (length "foo"))
3571 (accept-process-output proc
0.1)))
3572 (should (string-equal (buffer-string) "foo")))
3575 (ignore-errors (delete-process proc
)))
3579 (write-region "foo" nil tmp-name
)
3580 (should (file-exists-p tmp-name
))
3583 "test2" (current-buffer)
3584 "cat" (file-name-nondirectory tmp-name
)))
3585 (should (processp proc
))
3587 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3588 (while (< (- (point-max) (point-min)) (length "foo"))
3589 (accept-process-output proc
0.1)))
3590 (should (string-equal (buffer-string) "foo")))
3594 (delete-process proc
)
3595 (delete-file tmp-name
)))
3599 (setq proc
(start-file-process "test3" (current-buffer) "cat"))
3600 (should (processp proc
))
3601 (should (equal (process-status proc
) 'run
))
3604 (lambda (p s
) (with-current-buffer (process-buffer p
) (insert s
))))
3605 (process-send-string proc
"foo")
3606 (process-send-eof proc
)
3608 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
3609 (while (< (- (point-max) (point-min)) (length "foo"))
3610 (accept-process-output proc
0.1)))
3611 (should (string-equal (buffer-string) "foo")))
3614 (ignore-errors (delete-process proc
))))))
3616 (ert-deftest tramp-test30-interrupt-process
()
3617 "Check `interrupt-process'."
3618 :tags
'(:expensive-test
)
3619 (skip-unless (tramp--test-enabled))
3620 (skip-unless (tramp--test-sh-p))
3621 ;; Since Emacs 26.1.
3622 (skip-unless (boundp 'interrupt-process-functions
))
3624 (let ((default-directory tramp-test-temporary-file-directory
)
3625 kill-buffer-query-functions proc
)
3628 (setq proc
(start-file-process "test" (current-buffer) "sleep" "10"))
3629 (should (processp proc
))
3630 (should (process-live-p proc
))
3631 (should (equal (process-status proc
) 'run
))
3632 (should (numberp (process-get proc
'remote-pid
)))
3633 (should (interrupt-process proc
))
3634 ;; Let the process accept the interrupt.
3635 (accept-process-output proc
1 nil
0)
3636 (should-not (process-live-p proc
))
3637 ;; An interrupted process cannot be interrupted, again.
3638 (should-error (interrupt-process proc
) :type
'error
))
3641 (ignore-errors (delete-process proc
)))))
3643 (ert-deftest tramp-test31-shell-command
()
3644 "Check `shell-command'."
3645 :tags
'(:expensive-test
)
3646 (skip-unless (tramp--test-enabled))
3647 (skip-unless (tramp--test-sh-p))
3649 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3650 (let ((tmp-name (tramp--test-make-temp-name nil quoted
))
3651 (default-directory tramp-test-temporary-file-directory
)
3652 ;; Suppress nasty messages.
3654 kill-buffer-query-functions
)
3657 (write-region "foo" nil tmp-name
)
3658 (should (file-exists-p tmp-name
))
3660 (format "ls %s" (file-name-nondirectory tmp-name
))
3662 ;; `ls' could produce colorized output.
3663 (goto-char (point-min))
3665 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3666 (replace-match "" nil nil
))
3669 (format "%s\n" (file-name-nondirectory tmp-name
))
3673 (ignore-errors (delete-file tmp-name
)))
3677 (write-region "foo" nil tmp-name
)
3678 (should (file-exists-p tmp-name
))
3679 (async-shell-command
3680 (format "ls %s" (file-name-nondirectory tmp-name
))
3683 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
3684 (while (< (- (point-max) (point-min))
3685 (1+ (length (file-name-nondirectory tmp-name
))))
3686 (accept-process-output
3687 (get-buffer-process (current-buffer)) 0.1)))
3688 ;; `ls' could produce colorized output.
3689 (goto-char (point-min))
3691 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3692 (replace-match "" nil nil
))
3693 ;; There might be a nasty "Process *Async Shell* finished" message.
3694 (goto-char (point-min))
3696 (narrow-to-region (point-min) (point))
3699 (format "%s\n" (file-name-nondirectory tmp-name
))
3703 (ignore-errors (delete-file tmp-name
)))
3707 (write-region "foo" nil tmp-name
)
3708 (should (file-exists-p tmp-name
))
3709 (async-shell-command "read line; ls $line" (current-buffer))
3710 (process-send-string
3711 (get-buffer-process (current-buffer))
3712 (format "%s\n" (file-name-nondirectory tmp-name
)))
3714 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
3715 (while (< (- (point-max) (point-min))
3716 (1+ (length (file-name-nondirectory tmp-name
))))
3717 (accept-process-output
3718 (get-buffer-process (current-buffer)) 0.1)))
3719 ;; `ls' could produce colorized output.
3720 (goto-char (point-min))
3722 (re-search-forward tramp-display-escape-sequence-regexp nil t
)
3723 (replace-match "" nil nil
))
3724 ;; There might be a nasty "Process *Async Shell* finished" message.
3725 (goto-char (point-min))
3727 (narrow-to-region (point-min) (point))
3730 (format "%s\n" (file-name-nondirectory tmp-name
))
3734 (ignore-errors (delete-file tmp-name
))))))
3736 (defun tramp--test-shell-command-to-string-asynchronously (command)
3737 "Like `shell-command-to-string', but for asynchronous processes."
3739 (async-shell-command command
(current-buffer))
3741 (while (get-buffer-process (current-buffer))
3742 (accept-process-output (get-buffer-process (current-buffer)) 0.1)))
3743 (accept-process-output nil
0.1)
3744 (buffer-substring-no-properties (point-min) (point-max))))
3746 ;; This test is inspired by Bug#23952.
3747 (ert-deftest tramp-test32-environment-variables
()
3748 "Check that remote processes set / unset environment variables properly."
3749 :tags
'(:expensive-test
)
3750 (skip-unless (tramp--test-enabled))
3751 (skip-unless (tramp--test-sh-p))
3753 (dolist (this-shell-command-to-string
3755 shell-command-to-string
3757 tramp--test-shell-command-to-string-asynchronously
))
3759 (let ((default-directory tramp-test-temporary-file-directory
)
3760 (shell-file-name "/bin/sh")
3761 (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
3762 kill-buffer-query-functions
)
3766 (let ((process-environment
3767 (cons (concat envvar
"=foo") process-environment
)))
3773 this-shell-command-to-string
3774 (format "echo -n ${%s:?bla}" envvar
))))))
3777 ;; Set the empty value.
3778 (let ((process-environment
3779 (cons (concat envvar
"=") process-environment
)))
3785 this-shell-command-to-string
3786 (format "echo -n ${%s:?bla}" envvar
))))
3790 (regexp-quote envvar
)
3791 (funcall this-shell-command-to-string
"set")))))
3793 ;; We force a reconnect, in order to have a clean environment.
3794 (tramp-cleanup-connection
3795 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
3796 'keep-debug
'keep-password
)
3798 ;; Unset the variable.
3799 (let ((tramp-remote-process-environment
3800 (cons (concat envvar
"=foo")
3801 tramp-remote-process-environment
)))
3802 ;; Set the initial value, we want to unset below.
3807 this-shell-command-to-string
3808 (format "echo -n ${%s:?bla}" envvar
))))
3809 (let ((process-environment
3810 (cons envvar process-environment
)))
3811 ;; Variable is unset.
3816 this-shell-command-to-string
3817 (format "echo -n ${%s:?bla}" envvar
))))
3818 ;; Variable is unset.
3821 (regexp-quote envvar
)
3822 (funcall this-shell-command-to-string
"set")))))))))
3824 ;; This test is inspired by Bug#27009.
3825 (ert-deftest tramp-test32-environment-variables-and-port-numbers
()
3826 "Check that two connections with separate ports are different."
3827 (skip-unless (tramp--test-enabled))
3828 ;; We test it only for the mock-up connection; otherwise there might
3829 ;; be problems with the used ports.
3830 (skip-unless (and (eq tramp-syntax
'default
)
3831 (tramp--test-mock-p)))
3833 ;; We force a reconnect, in order to have a clean environment.
3834 (dolist (dir `(,tramp-test-temporary-file-directory
3835 "/mock:localhost#11111:" "/mock:localhost#22222:"))
3836 (tramp-cleanup-connection
3837 (tramp-dissect-file-name dir
) 'keep-debug
'keep-password
))
3840 (dolist (port '(11111 22222))
3841 (let* ((default-directory
3842 (format "/mock:localhost#%d:%s" port temporary-file-directory
))
3843 (shell-file-name "/bin/sh")
3844 (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
3845 ;; We cannot use `process-environment', because this
3846 ;; would be applied in `process-file'.
3847 (tramp-remote-process-environment
3849 (format "%s=%d" envvar port
)
3850 tramp-remote-process-environment
)))
3853 (number-to-string port
)
3854 (shell-command-to-string (format "echo -n $%s" envvar
))))))
3857 (dolist (dir '("/mock:localhost#11111:" "/mock:localhost#22222:"))
3858 (tramp-cleanup-connection (tramp-dissect-file-name dir
)))))
3860 ;; The functions were introduced in Emacs 26.1.
3861 (ert-deftest tramp-test33-explicit-shell-file-name
()
3862 "Check that connection-local `explicit-shell-file-name' is set."
3863 :tags
'(:expensive-test
)
3864 (skip-unless (tramp--test-enabled))
3865 (skip-unless (tramp--test-sh-p))
3866 ;; Since Emacs 26.1.
3867 (skip-unless (and (fboundp 'connection-local-set-profile-variables
)
3868 (fboundp 'connection-local-set-profiles
)))
3870 ;; `connection-local-set-profile-variables' and
3871 ;; `connection-local-set-profiles' exist since Emacs 26.1. We don't
3872 ;; want to see compiler warnings for older Emacsen.
3873 (let ((default-directory tramp-test-temporary-file-directory
)
3874 explicit-shell-file-name kill-buffer-query-functions
)
3877 ;; `shell-mode' would ruin our test, because it deletes all
3878 ;; buffer local variables.
3879 (put 'explicit-shell-file-name
'permanent-local t
)
3880 ;; Declare connection-local variable `explicit-shell-file-name'.
3882 (connection-local-set-profile-variables
3884 '((explicit-shell-file-name .
"/bin/sh")
3885 (explicit-sh-args .
("-i"))))
3886 (connection-local-set-profiles
3887 `(:application tramp
3888 :protocol
,(file-remote-p default-directory
'method
)
3889 :user
,(file-remote-p default-directory
'user
)
3890 :machine
,(file-remote-p default-directory
'host
))
3893 ;; Run interactive shell. Since the default directory is
3894 ;; remote, `explicit-shell-file-name' shall be set in order
3895 ;; to avoid a question.
3896 (with-current-buffer (get-buffer-create "*shell*")
3897 (ignore-errors (kill-process (current-buffer)))
3898 (should-not explicit-shell-file-name
)
3899 (call-interactively 'shell
)
3900 (should explicit-shell-file-name
)))
3902 (put 'explicit-shell-file-name
'permanent-local nil
)
3903 (kill-buffer "*shell*"))))
3905 (ert-deftest tramp-test34-vc-registered
()
3906 "Check `vc-registered'."
3907 :tags
'(:expensive-test
)
3908 (skip-unless (tramp--test-enabled))
3909 (skip-unless (tramp--test-sh-p))
3911 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3912 (let* ((default-directory tramp-test-temporary-file-directory
)
3913 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
3914 (tmp-name2 (expand-file-name "foo" tmp-name1
))
3915 (tramp-remote-process-environment tramp-remote-process-environment
)
3916 (vc-handled-backends
3917 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
3919 ((tramp-find-executable
3920 v vc-git-program
(tramp-get-remote-path v
))
3922 ((tramp-find-executable
3923 v vc-hg-program
(tramp-get-remote-path v
))
3925 ((tramp-find-executable
3926 v vc-bzr-program
(tramp-get-remote-path v
))
3927 (setq tramp-remote-process-environment
3928 (cons (format "BZR_HOME=%s"
3929 (file-remote-p tmp-name1
'localname
))
3930 tramp-remote-process-environment
))
3931 ;; We must force a reconnect, in order to activate $BZR_HOME.
3932 (tramp-cleanup-connection
3933 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
3934 'keep-debug
'keep-password
)
3937 ;; Suppress nasty messages.
3938 (inhibit-message t
))
3939 (skip-unless vc-handled-backends
)
3940 (unless quoted
(tramp--test-message "%s" vc-handled-backends
))
3944 (make-directory tmp-name1
)
3945 (write-region "foo" nil tmp-name2
)
3946 (should (file-directory-p tmp-name1
))
3947 (should (file-exists-p tmp-name2
))
3948 (should-not (vc-registered tmp-name1
))
3949 (should-not (vc-registered tmp-name2
))
3951 (let ((default-directory tmp-name1
))
3952 ;; Create empty repository, and register the file.
3953 ;; Sometimes, creation of repository fails (bzr!); we
3954 ;; skip the test then.
3956 (vc-create-repo (car vc-handled-backends
))
3957 (error (skip-unless nil
)))
3958 ;; The structure of VC-FILESET is not documented. Let's
3959 ;; hope it won't change.
3962 (list (car vc-handled-backends
)
3963 (list (file-name-nondirectory tmp-name2
))))
3964 ;; `vc-register' has changed its arguments in Emacs
3965 ;; 25.1. Let's skip it for older Emacsen.
3966 (error (skip-unless (>= emacs-major-version
25))))
3967 ;; vc-git uses an own process sentinel, Tramp's sentinel
3968 ;; for flushing the cache isn't used.
3969 (dired-uncache (concat (file-remote-p default-directory
) "/"))
3970 (should (vc-registered (file-name-nondirectory tmp-name2
)))))
3973 (ignore-errors (delete-directory tmp-name1
'recursive
))))))
3975 (ert-deftest tramp-test35-make-auto-save-file-name
()
3976 "Check `make-auto-save-file-name'."
3977 (skip-unless (tramp--test-enabled))
3979 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
3980 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
3981 (tmp-name2 (tramp--test-make-temp-name nil quoted
)))
3985 ;; Use default `auto-save-file-name-transforms' mechanism.
3986 (let (tramp-auto-save-directory)
3988 (setq buffer-file-name tmp-name1
)
3991 (make-auto-save-file-name)
3992 ;; This is taken from original `make-auto-save-file-name'.
3993 ;; We call `convert-standard-filename', because on
3994 ;; MS Windows the (local) colons must be replaced by
3995 ;; exclamation marks.
3996 (convert-standard-filename
4000 (subst-char-in-string
4001 ?
/ ?
! (replace-regexp-in-string "!" "!!" tmp-name1
)))
4002 temporary-file-directory
))))))
4005 (let (tramp-auto-save-directory auto-save-file-name-transforms
)
4007 (setq buffer-file-name tmp-name1
)
4010 (make-auto-save-file-name)
4012 (if quoted
'tramp-compat-file-name-quote
'identity
)
4014 (format "#%s#" (file-name-nondirectory tmp-name1
))
4015 tramp-test-temporary-file-directory
))))))
4017 ;; Use default `tramp-auto-save-directory' mechanism.
4018 (let ((tramp-auto-save-directory tmp-name2
))
4020 (setq buffer-file-name tmp-name1
)
4023 (make-auto-save-file-name)
4024 ;; This is taken from Tramp.
4028 (tramp-subst-strs-in-string
4035 (tramp-compat-file-name-unquote tmp-name1
)))
4037 (should (file-directory-p tmp-name2
))))
4039 ;; Relative file names shall work, too.
4040 (let ((tramp-auto-save-directory "."))
4042 (setq buffer-file-name tmp-name1
4043 default-directory tmp-name2
)
4046 (make-auto-save-file-name)
4047 ;; This is taken from Tramp.
4051 (tramp-subst-strs-in-string
4058 (tramp-compat-file-name-unquote tmp-name1
)))
4060 (should (file-directory-p tmp-name2
)))))
4063 (ignore-errors (delete-file tmp-name1
))
4064 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
4066 (ert-deftest tramp-test36-find-backup-file-name
()
4067 "Check `find-backup-file-name'."
4068 (skip-unless (tramp--test-enabled))
4070 (dolist (quoted (if tramp--test-expensive-test
'(nil t
) '(nil)))
4071 (let ((tmp-name1 (tramp--test-make-temp-name nil quoted
))
4072 (tmp-name2 (tramp--test-make-temp-name nil quoted
))
4073 ;; These settings are not used by Tramp, so we ignore them.
4074 version-control delete-old-versions
4075 (kept-old-versions (default-toplevel-value 'kept-old-versions
))
4076 (kept-new-versions (default-toplevel-value 'kept-new-versions
)))
4079 ;; Use default `backup-directory-alist' mechanism.
4080 (let (backup-directory-alist tramp-backup-directory-alist
)
4083 (find-backup-file-name tmp-name1
)
4086 (if quoted
'tramp-compat-file-name-quote
'identity
)
4088 (format "%s~" (file-name-nondirectory tmp-name1
))
4089 tramp-test-temporary-file-directory
)))))))
4092 ;; Map `backup-directory-alist'.
4093 (let ((backup-directory-alist `(("." .
,tmp-name2
)))
4094 tramp-backup-directory-alist
)
4097 (find-backup-file-name tmp-name1
)
4100 (if quoted
'tramp-compat-file-name-quote
'identity
)
4104 ;; This is taken from `make-backup-file-name-1'. We
4105 ;; call `convert-standard-filename', because on MS
4106 ;; Windows the (local) colons must be replaced by
4107 ;; exclamation marks.
4108 (subst-char-in-string
4110 (replace-regexp-in-string
4111 "!" "!!" (convert-standard-filename tmp-name1
))))
4113 ;; The backup directory is created.
4114 (should (file-directory-p tmp-name2
)))
4117 (ignore-errors (delete-directory tmp-name2
'recursive
)))
4120 ;; Map `tramp-backup-directory-alist'.
4121 (let ((tramp-backup-directory-alist `(("." .
,tmp-name2
)))
4122 backup-directory-alist
)
4125 (find-backup-file-name tmp-name1
)
4128 (if quoted
'tramp-compat-file-name-quote
'identity
)
4132 ;; This is taken from `make-backup-file-name-1'. We
4133 ;; call `convert-standard-filename', because on MS
4134 ;; Windows the (local) colons must be replaced by
4135 ;; exclamation marks.
4136 (subst-char-in-string
4138 (replace-regexp-in-string
4139 "!" "!!" (convert-standard-filename tmp-name1
))))
4141 ;; The backup directory is created.
4142 (should (file-directory-p tmp-name2
)))
4145 (ignore-errors (delete-directory tmp-name2
'recursive
)))
4148 ;; Map `tramp-backup-directory-alist' with local file name.
4149 (let ((tramp-backup-directory-alist
4150 `(("." .
,(file-remote-p tmp-name2
'localname
))))
4151 backup-directory-alist
)
4154 (find-backup-file-name tmp-name1
)
4157 (if quoted
'tramp-compat-file-name-quote
'identity
)
4161 ;; This is taken from `make-backup-file-name-1'. We
4162 ;; call `convert-standard-filename', because on MS
4163 ;; Windows the (local) colons must be replaced by
4164 ;; exclamation marks.
4165 (subst-char-in-string
4167 (replace-regexp-in-string
4168 "!" "!!" (convert-standard-filename tmp-name1
))))
4170 ;; The backup directory is created.
4171 (should (file-directory-p tmp-name2
)))
4174 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
4176 ;; The functions were introduced in Emacs 26.1.
4177 (ert-deftest tramp-test37-make-nearby-temp-file
()
4178 "Check `make-nearby-temp-file' and `temporary-file-directory'."
4179 (skip-unless (tramp--test-enabled))
4180 ;; Since Emacs 26.1.
4182 (and (fboundp 'make-nearby-temp-file
) (fboundp 'temporary-file-directory
)))
4184 ;; `make-nearby-temp-file' and `temporary-file-directory' exists
4185 ;; since Emacs 26.1. We don't want to see compiler warnings for
4187 (let ((default-directory tramp-test-temporary-file-directory
)
4189 ;; The remote host shall know a temporary file directory.
4190 (should (stringp (with-no-warnings (temporary-file-directory))))
4193 (file-remote-p default-directory
)
4194 (file-remote-p (with-no-warnings (temporary-file-directory)))))
4196 ;; The temporary file shall be located on the remote host.
4197 (setq tmp-file
(with-no-warnings (make-nearby-temp-file "tramp-test")))
4198 (should (file-exists-p tmp-file
))
4199 (should (file-regular-p tmp-file
))
4202 (file-remote-p default-directory
)
4203 (file-remote-p tmp-file
)))
4204 (delete-file tmp-file
)
4205 (should-not (file-exists-p tmp-file
))
4207 (setq tmp-file
(with-no-warnings (make-nearby-temp-file "tramp-test" 'dir
)))
4208 (should (file-exists-p tmp-file
))
4209 (should (file-directory-p tmp-file
))
4210 (delete-directory tmp-file
)
4211 (should-not (file-exists-p tmp-file
))))
4213 (defun tramp--test-emacs26-p ()
4214 "Check for Emacs version >= 26.1.
4215 Some semantics has been changed for there, w/o new functions or
4216 variables, so we check the Emacs version directly."
4217 (>= emacs-major-version
26))
4219 (defun tramp--test-adb-p ()
4220 "Check, whether the remote host runs Android.
4221 This requires restrictions of file name syntax."
4222 (tramp-adb-file-name-p tramp-test-temporary-file-directory
))
4224 (defun tramp--test-docker-p ()
4225 "Check, whether the docker method is used.
4226 This does not support some special file names."
4228 "docker" (file-remote-p tramp-test-temporary-file-directory
'method
)))
4230 (defun tramp--test-ftp-p ()
4231 "Check, whether an FTP-like method is used.
4232 This does not support globbing characters in file names (yet)."
4233 ;; Globbing characters are ??, ?* and ?\[.
4235 "ftp$" (file-remote-p tramp-test-temporary-file-directory
'method
)))
4237 (defun tramp--test-gvfs-p (&optional method
)
4238 "Check, whether the remote host runs a GVFS based method.
4239 This requires restrictions of file name syntax."
4240 (or (member method tramp-gvfs-methods
)
4241 (tramp-gvfs-file-name-p tramp-test-temporary-file-directory
)))
4243 (defun tramp--test-hpux-p ()
4244 "Check, whether the remote host runs HP-UX.
4245 Several special characters do not work properly there."
4246 ;; We must refill the cache. `file-truename' does it.
4247 (with-parsed-tramp-file-name
4248 (file-truename tramp-test-temporary-file-directory
) nil
4249 (string-match "^HP-UX" (tramp-get-connection-property v
"uname" ""))))
4251 (defun tramp--test-mock-p ()
4252 "Check, whether the mock method is used.
4253 This does not support external Emacs calls."
4255 "mock" (file-remote-p tramp-test-temporary-file-directory
'method
)))
4257 (defun tramp--test-owncloud-p ()
4258 "Check, whether the owncloud method is used."
4260 "owncloud" (file-remote-p tramp-test-temporary-file-directory
'method
)))
4262 (defun tramp--test-rsync-p ()
4263 "Check, whether the rsync method is used.
4264 This does not support special file names."
4266 "rsync" (file-remote-p tramp-test-temporary-file-directory
'method
)))
4268 (defun tramp--test-sh-p ()
4269 "Check, whether the remote host runs a based method from tramp-sh.el."
4271 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
4272 'tramp-sh-file-name-handler
))
4274 (defun tramp--test-windows-nt ()
4275 "Check, whether the locale host runs MS Windows."
4276 (eq system-type
'windows-nt
))
4278 (defun tramp--test-windows-nt-and-batch ()
4279 "Check, whether the locale host runs MS Windows in batch mode.
4280 This does not support special characters."
4281 (and (eq system-type
'windows-nt
) noninteractive
))
4283 (defun tramp--test-windows-nt-and-pscp-psftp-p ()
4284 "Check, whether the locale host runs MS Windows, and ps{cp,ftp} is used.
4285 This does not support utf8 based file transfer."
4286 (and (eq system-type
'windows-nt
)
4288 (regexp-opt '("pscp" "psftp"))
4289 (file-remote-p tramp-test-temporary-file-directory
'method
))))
4291 (defun tramp--test-windows-nt-or-smb-p ()
4292 "Check, whether the locale or remote host runs MS Windows.
4293 This requires restrictions of file name syntax."
4294 (or (eq system-type
'windows-nt
)
4295 (tramp-smb-file-name-p tramp-test-temporary-file-directory
)))
4297 (defun tramp--test-check-files (&rest files
)
4298 "Run a simple but comprehensive test over every file in FILES."
4299 ;; `filename-non-special' has been fixed in Emacs 26.1, see Bug#29579.
4300 (dolist (quoted (if (and tramp--test-expensive-test
(tramp--test-emacs26-p))
4302 ;; We must use `file-truename' for the temporary directory,
4303 ;; because it could be located on a symlinked directory. This
4304 ;; would let the test fail.
4305 (let* ((tramp-test-temporary-file-directory
4306 (file-truename tramp-test-temporary-file-directory
))
4307 (tmp-name1 (tramp--test-make-temp-name nil quoted
))
4308 (tmp-name2 (tramp--test-make-temp-name 'local quoted
))
4309 (files (delq nil files
))
4310 (process-environment process-environment
))
4313 (make-directory tmp-name1
)
4314 (make-directory tmp-name2
)
4317 (let* ((file1 (expand-file-name elt tmp-name1
))
4318 (file2 (expand-file-name elt tmp-name2
))
4319 (file3 (expand-file-name (concat elt
"foo") tmp-name1
)))
4320 (write-region elt nil file1
)
4321 (should (file-exists-p file1
))
4323 ;; Check file contents.
4325 (insert-file-contents file1
)
4326 (should (string-equal (buffer-string) elt
)))
4328 ;; Copy file both directions.
4329 (copy-file file1
(file-name-as-directory tmp-name2
))
4330 (should (file-exists-p file2
))
4332 (should-not (file-exists-p file1
))
4333 (copy-file file2
(file-name-as-directory tmp-name1
))
4334 (should (file-exists-p file1
))
4336 (tramp--test-ignore-make-symbolic-link-error
4337 (make-symbolic-link file1 file3
)
4338 (should (file-symlink-p file3
))
4341 (expand-file-name file1
) (file-truename file3
)))
4345 (if quoted
'tramp-compat-file-name-quote
'identity
)
4346 (car (file-attributes file3
)))
4347 (file-remote-p (file-truename file1
) 'localname
)))
4348 ;; Check file contents.
4350 (insert-file-contents file3
)
4351 (should (string-equal (buffer-string) elt
)))
4352 (delete-file file3
))))
4354 ;; Check file names.
4355 (should (equal (directory-files
4356 tmp-name1 nil directory-files-no-dot-files-regexp
)
4357 (sort (copy-sequence files
) 'string-lessp
)))
4358 (should (equal (directory-files
4359 tmp-name2 nil directory-files-no-dot-files-regexp
)
4360 (sort (copy-sequence files
) 'string-lessp
)))
4362 ;; `substitute-in-file-name' could return different
4363 ;; values. For `adb', there could be strange file
4364 ;; permissions preventing overwriting a file. We don't
4365 ;; care in this testcase.
4368 (substitute-in-file-name (expand-file-name elt tmp-name1
)))
4370 (substitute-in-file-name
4371 (expand-file-name elt tmp-name2
))))
4372 (ignore-errors (write-region elt nil file1
))
4373 (should (file-exists-p file1
))
4374 (ignore-errors (write-region elt nil file2 nil
'nomessage
))
4375 (should (file-exists-p file2
))))
4377 (should (equal (directory-files
4378 tmp-name1 nil directory-files-no-dot-files-regexp
)
4380 tmp-name2 nil directory-files-no-dot-files-regexp
)))
4382 ;; Check directory creation. We use a subdirectory "foo"
4383 ;; in order to avoid conflicts with previous file name tests.
4385 (let* ((elt1 (concat elt
"foo"))
4386 (file1 (expand-file-name (concat "foo/" elt
) tmp-name1
))
4387 (file2 (expand-file-name elt file1
))
4388 (file3 (expand-file-name elt1 file1
)))
4389 (make-directory file1
'parents
)
4390 (should (file-directory-p file1
))
4391 (write-region elt nil file2
)
4392 (should (file-exists-p file2
))
4396 file1 nil directory-files-no-dot-files-regexp
)
4400 (caar (directory-files-and-attributes
4401 file1 nil directory-files-no-dot-files-regexp
))
4404 ;; Check symlink in `directory-files-and-attributes'.
4405 ;; It does not work in the "smb" case, only relative
4406 ;; symlinks to existing files are shown there.
4407 (tramp--test-ignore-make-symbolic-link-error
4409 (tramp-smb-file-name-p tramp-test-temporary-file-directory
)
4410 (make-symbolic-link file2 file3
)
4411 (should (file-symlink-p file3
))
4414 (caar (directory-files-and-attributes
4415 file1 nil
(regexp-quote elt1
)))
4420 (if quoted
'tramp-compat-file-name-quote
'identity
)
4421 (cadr (car (directory-files-and-attributes
4422 file1 nil
(regexp-quote elt1
)))))
4423 (file-remote-p (file-truename file2
) 'localname
)))
4425 (should-not (file-exists-p file3
))))
4428 (should-not (file-exists-p file2
))
4429 (delete-directory file1
)
4430 (should-not (file-exists-p file1
))))
4432 ;; Check, that environment variables are set correctly.
4433 (when (and tramp--test-expensive-test
(tramp--test-sh-p))
4435 (let ((envvar (concat "VAR_" (upcase (md5 elt
))))
4436 (default-directory tramp-test-temporary-file-directory
)
4437 (process-environment process-environment
))
4439 ;; The value of PS1 could confuse Tramp's detection
4440 ;; of process output. So we unset it temporarily.
4443 (should (zerop (process-file "env" nil t nil
)))
4444 (goto-char (point-min))
4449 (regexp-quote envvar
)
4450 (regexp-quote (getenv envvar
))))))))))
4453 (ignore-errors (delete-directory tmp-name1
'recursive
))
4454 (ignore-errors (delete-directory tmp-name2
'recursive
))))))
4456 (defun tramp--test-special-characters ()
4457 "Perform the test in `tramp-test38-special-characters*'."
4458 ;; Newlines, slashes and backslashes in file names are not
4459 ;; supported. So we don't test. And we don't test the tab
4460 ;; character on Windows or Cygwin, because the backslash is
4461 ;; interpreted as a path separator, preventing "\t" from being
4462 ;; expanded to <TAB>.
4463 (tramp--test-check-files
4464 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4466 (if (or (tramp--test-adb-p)
4467 (tramp--test-docker-p)
4468 (eq system-type
'cygwin
))
4475 (unless (or (tramp--test-ftp-p)
4476 (tramp--test-gvfs-p)
4477 (tramp--test-windows-nt-or-smb-p))
4479 (unless (or (tramp--test-ftp-p)
4480 (tramp--test-gvfs-p)
4481 (tramp--test-windows-nt-or-smb-p))
4483 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4487 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4490 (if (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4493 (unless (or (tramp--test-gvfs-p) (tramp--test-windows-nt-or-smb-p))
4496 (unless (or (tramp--test-ftp-p) (tramp--test-gvfs-p)) "[foo]bar[baz]")
4499 ;; These tests are inspired by Bug#17238.
4500 (ert-deftest tramp-test38-special-characters
()
4501 "Check special characters in file names."
4502 (skip-unless (tramp--test-enabled))
4503 (skip-unless (not (tramp--test-rsync-p)))
4504 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4506 (tramp--test-special-characters))
4508 (ert-deftest tramp-test38-special-characters-with-stat
()
4509 "Check special characters in file names.
4510 Use the `stat' command."
4511 :tags
'(:expensive-test
)
4512 (skip-unless (tramp--test-enabled))
4513 (skip-unless (tramp--test-sh-p))
4514 (skip-unless (not (tramp--test-rsync-p)))
4515 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4516 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4517 (skip-unless (tramp-get-remote-stat v
)))
4519 (let ((tramp-connection-properties
4521 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4523 tramp-connection-properties
)))
4524 (tramp--test-special-characters)))
4526 (ert-deftest tramp-test38-special-characters-with-perl
()
4527 "Check special characters in file names.
4528 Use the `perl' command."
4529 :tags
'(:expensive-test
)
4530 (skip-unless (tramp--test-enabled))
4531 (skip-unless (tramp--test-sh-p))
4532 (skip-unless (not (tramp--test-rsync-p)))
4533 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4534 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4535 (skip-unless (tramp-get-remote-perl v
)))
4537 (let ((tramp-connection-properties
4539 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4541 ;; See `tramp-sh-handle-file-truename'.
4542 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4544 tramp-connection-properties
)))
4545 (tramp--test-special-characters)))
4547 (ert-deftest tramp-test38-special-characters-with-ls
()
4548 "Check special characters in file names.
4549 Use the `ls' command."
4550 :tags
'(:expensive-test
)
4551 (skip-unless (tramp--test-enabled))
4552 (skip-unless (tramp--test-sh-p))
4553 (skip-unless (not (tramp--test-rsync-p)))
4554 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4555 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4557 (let ((tramp-connection-properties
4559 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4561 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4563 ;; See `tramp-sh-handle-file-truename'.
4564 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4566 tramp-connection-properties
)))
4567 (tramp--test-special-characters)))
4569 (defun tramp--test-utf8 ()
4570 "Perform the test in `tramp-test39-utf8*'."
4571 (let* ((utf8 (if (and (eq system-type
'darwin
)
4572 (memq 'utf-8-hfs
(coding-system-list)))
4574 (coding-system-for-read utf8
)
4575 (coding-system-for-write utf8
)
4576 (file-name-coding-system
4577 (coding-system-change-eol-conversion utf8
'unix
)))
4578 (tramp--test-check-files
4579 (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ")
4580 (unless (tramp--test-hpux-p)
4581 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
4583 "Автостопом по гала́ктике")))
4585 (ert-deftest tramp-test39-utf8
()
4586 "Check UTF8 encoding in file names and file contents."
4587 (skip-unless (tramp--test-enabled))
4588 (skip-unless (not (tramp--test-docker-p)))
4589 (skip-unless (not (tramp--test-rsync-p)))
4590 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4591 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4595 (ert-deftest tramp-test39-utf8-with-stat
()
4596 "Check UTF8 encoding in file names and file contents.
4597 Use the `stat' command."
4598 :tags
'(:expensive-test
)
4599 (skip-unless (tramp--test-enabled))
4600 (skip-unless (tramp--test-sh-p))
4601 (skip-unless (not (tramp--test-docker-p)))
4602 (skip-unless (not (tramp--test-rsync-p)))
4603 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4604 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4605 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4606 (skip-unless (tramp-get-remote-stat v
)))
4608 (let ((tramp-connection-properties
4610 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4612 tramp-connection-properties
)))
4613 (tramp--test-utf8)))
4615 (ert-deftest tramp-test39-utf8-with-perl
()
4616 "Check UTF8 encoding in file names and file contents.
4617 Use the `perl' command."
4618 :tags
'(:expensive-test
)
4619 (skip-unless (tramp--test-enabled))
4620 (skip-unless (tramp--test-sh-p))
4621 (skip-unless (not (tramp--test-docker-p)))
4622 (skip-unless (not (tramp--test-rsync-p)))
4623 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4624 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4625 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
4626 (skip-unless (tramp-get-remote-perl v
)))
4628 (let ((tramp-connection-properties
4630 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4632 ;; See `tramp-sh-handle-file-truename'.
4633 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4635 tramp-connection-properties
)))
4636 (tramp--test-utf8)))
4638 (ert-deftest tramp-test39-utf8-with-ls
()
4639 "Check UTF8 encoding in file names and file contents.
4640 Use the `ls' command."
4641 :tags
'(:expensive-test
)
4642 (skip-unless (tramp--test-enabled))
4643 (skip-unless (tramp--test-sh-p))
4644 (skip-unless (not (tramp--test-docker-p)))
4645 (skip-unless (not (tramp--test-rsync-p)))
4646 (skip-unless (not (tramp--test-windows-nt-and-batch)))
4647 (skip-unless (not (tramp--test-windows-nt-and-pscp-psftp-p)))
4649 (let ((tramp-connection-properties
4651 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4653 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4655 ;; See `tramp-sh-handle-file-truename'.
4656 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
4658 tramp-connection-properties
)))
4659 (tramp--test-utf8)))
4661 (ert-deftest tramp-test40-file-system-info
()
4662 "Check that `file-system-info' returns proper values."
4663 (skip-unless (tramp--test-enabled))
4664 ;; Since Emacs 27.1.
4665 (skip-unless (fboundp 'file-system-info
))
4667 ;; `file-system-info' exists since Emacs 27. We don't want to see
4668 ;; compiler warnings for older Emacsen.
4669 (let ((fsi (with-no-warnings
4670 (file-system-info tramp-test-temporary-file-directory
))))
4672 (should (and (consp fsi
)
4674 (numberp (nth 0 fsi
))
4675 (numberp (nth 1 fsi
))
4676 (numberp (nth 2 fsi
))))))
4678 (defun tramp--test-timeout-handler ()
4680 (ert-fail (format "`%s' timed out" (ert-test-name (ert-running-test)))))
4682 ;; This test is inspired by Bug#16928.
4683 (ert-deftest tramp-test41-asynchronous-requests
()
4684 "Check parallel asynchronous requests.
4685 Such requests could arrive from timers, process filters and
4686 process sentinels. They shall not disturb each other."
4687 :tags
'(:expensive-test
)
4688 (skip-unless (tramp--test-enabled))
4689 (skip-unless (tramp--test-sh-p))
4691 ;; This test could be blocked on hydra. So we set a timeout of 300
4692 ;; seconds, and we send a SIGUSR1 signal after 300 seconds.
4693 (with-timeout (300 (tramp--test-timeout-handler))
4694 (define-key special-event-map
[sigusr1] 'tramp--test-timeout-handler)
4695 (tramp--test-instrument-test-case (if (getenv "EMACS_HYDRA_CI") 10 0)
4696 (let* (;; For the watchdog.
4697 (default-directory (expand-file-name temporary-file-directory))
4700 "*watchdog*" nil shell-file-name shell-command-switch
4701 (format "sleep 300; kill -USR1 %d" (emacs-pid))))
4702 (tmp-name (tramp--test-make-temp-name))
4703 (default-directory tmp-name)
4704 ;; Do not cache Tramp properties.
4705 (remote-file-name-inhibit-cache t)
4706 (process-file-side-effects t)
4707 ;; Suppress nasty messages.
4709 ;; Do not run delayed timers.
4710 (timer-max-repeats 0)
4711 ;; Number of asynchronous processes for test. Tests on
4712 ;; some machines handle less parallel processes.
4716 (string-to-number (getenv "REMOTE_PARALLEL_PROCESSES")))
4718 ;; On hydra, timings are bad.
4721 ((getenv "EMACS_HYDRA_CI") 10)
4723 ;; We must distinguish due to performance reasons.
4726 ((tramp--test-mock-p) 'vc-registered)
4727 (t 'file-attributes)))
4728 timer buffers kill-buffer-query-functions)
4732 (make-directory tmp-name)
4734 ;; Setup a timer in order to raise an ordinary command
4735 ;; again and again. `vc-registered' is well suited,
4736 ;; because there are many checks.
4743 (let ((time (float-time))
4744 (default-directory tmp-name)
4746 (buffer-name (nth (random (length buffers)) buffers))))
4747 (tramp--test-message
4748 "Start timer %s %s" file (current-time-string))
4749 (funcall timer-operation file)
4750 ;; Adjust timer if it takes too much time.
4751 (when (> (- (float-time) time) timer-repeat)
4752 (setq timer-repeat (* 1.5 timer-repeat))
4753 (setf (timer--repeat-delay timer) timer-repeat)
4754 (tramp--test-message "Increase timer %s" timer-repeat))
4755 (tramp--test-message
4756 "Stop timer %s %s" file (current-time-string)))))))
4758 ;; Create temporary buffers. The number of buffers
4759 ;; corresponds to the number of processes; it could be
4760 ;; increased in order to make pressure on Tramp.
4761 (dotimes (_ number-proc)
4762 (setq buffers (cons (generate-new-buffer "foo") buffers)))
4764 ;; Open asynchronous processes. Set process filter and sentinel.
4765 (dolist (buf buffers)
4767 (sit-for 0.01 'nodisp)
4769 (start-file-process-shell-command
4770 (buffer-name buf) buf
4772 "(read line && echo $line >$line);"
4773 "(read line && cat $line);"
4774 "(read line && rm $line)")))
4775 (file (expand-file-name (buffer-name buf))))
4776 ;; Remember the file name. Add counter.
4777 (process-put proc 'foo file)
4778 (process-put proc 'bar 0)
4779 ;; Add process filter.
4782 (lambda (proc string)
4783 (tramp--test-message
4784 "Process filter %s %s %s" proc string (current-time-string))
4785 (with-current-buffer (process-buffer proc)
4787 (unless (zerop (length string))
4788 (dired-uncache (process-get proc 'foo))
4789 (should (file-attributes (process-get proc 'foo))))))
4790 ;; Add process sentinel.
4791 (set-process-sentinel
4793 (lambda (proc _state)
4794 (tramp--test-message
4795 "Process sentinel %s %s" proc (current-time-string))
4796 (dired-uncache (process-get proc 'foo))
4797 (should-not (file-attributes (process-get proc 'foo)))))))
4799 ;; Send a string. Use a random order of the buffers. Mix
4800 ;; with regular operation.
4801 (let ((buffers (copy-sequence buffers)))
4804 (sit-for 0.01 'nodisp)
4805 (let* ((buf (nth (random (length buffers)) buffers))
4806 (proc (get-buffer-process buf))
4807 (file (process-get proc 'foo))
4808 (count (process-get proc 'bar)))
4809 (tramp--test-message
4810 "Start action %d %s %s" count buf (current-time-string))
4811 ;; Regular operation prior process action.
4812 (dired-uncache file)
4814 (should-not (file-attributes file))
4815 (should (file-attributes file)))
4816 ;; Send string to process.
4817 (process-send-string proc (format "%s\n" (buffer-name buf)))
4818 (accept-process-output proc 0.1 nil 0)
4819 ;; Give the watchdog a chance.
4820 (read-event nil nil 0.01)
4821 (tramp--test-message
4822 "Continue action %d %s %s" count buf (current-time-string))
4823 ;; Regular operation post process action.
4824 (dired-uncache file)
4826 (should-not (file-attributes file))
4827 (should (file-attributes file)))
4828 (tramp--test-message
4829 "Stop action %d %s %s" count buf (current-time-string))
4830 (process-put proc 'bar (1+ count))
4831 (unless (process-live-p proc)
4832 (setq buffers (delq buf buffers))))))
4834 ;; Checks. All process output shall exists in the
4835 ;; respective buffers. All created files shall be
4837 (tramp--test-message "Check %s" (current-time-string))
4838 (dolist (buf buffers)
4839 (with-current-buffer buf
4840 (should (string-equal (format "%s\n" buf) (buffer-string)))))
4843 tmp-name nil directory-files-no-dot-files-regexp)))
4846 (define-key special-event-map [sigusr1] 'ignore
)
4847 (ignore-errors (quit-process watchdog
))
4848 (dolist (buf buffers
)
4849 (ignore-errors (delete-process (get-buffer-process buf
)))
4850 (ignore-errors (kill-buffer buf
)))
4851 (ignore-errors (cancel-timer timer
))
4852 (ignore-errors (delete-directory tmp-name
'recursive
)))))))
4854 ;; This test is inspired by Bug#29163.
4855 (ert-deftest tramp-test42-auto-load
()
4856 "Check that Tramp autoloads properly."
4857 (let ((default-directory (expand-file-name temporary-file-directory
))
4860 "(message \"Tramp loaded: %%s\" (and (file-remote-p %S) t))"
4861 tramp-test-temporary-file-directory
)))
4864 "Tramp loaded: t[\n\r]+"
4865 (shell-command-to-string
4867 "%s -batch -Q -L %s --eval %s"
4868 (shell-quote-argument
4869 (expand-file-name invocation-name invocation-directory
))
4870 (mapconcat 'shell-quote-argument load-path
" -L ")
4871 (shell-quote-argument code
)))))))
4873 (ert-deftest tramp-test42-delay-load
()
4874 "Check that Tramp is loaded lazily, only when needed."
4875 ;; The autoloaded Tramp objects are different since Emacs 26.1. We
4876 ;; cannot test older Emacsen, therefore.
4877 (skip-unless (tramp--test-emacs26-p))
4879 ;; Tramp is neither loaded at Emacs startup, nor when completing a
4880 ;; non-Tramp file name like "/foo". Completing a Tramp-alike file
4881 ;; name like "/foo:" autoloads Tramp, when `tramp-mode' is t.
4882 (let ((default-directory (expand-file-name temporary-file-directory
))
4885 (setq tramp-mode %s) \
4886 (message \"Tramp loaded: %%s\" (featurep 'tramp)) \
4887 (file-name-all-completions \"/foo\" \"/\") \
4888 (message \"Tramp loaded: %%s\" (featurep 'tramp)) \
4889 (file-name-all-completions \"/foo:\" \"/\") \
4890 (message \"Tramp loaded: %%s\" (featurep 'tramp)))"))
4891 ;; Tramp doesn't load when `tramp-mode' is nil.
4892 (dolist (tm '(t nil
))
4896 "Tramp loaded: nil[\n\r]+Tramp loaded: nil[\n\r]+Tramp loaded: %s[\n\r]+"
4898 (shell-command-to-string
4900 "%s -batch -Q -L %s --eval %s"
4901 (shell-quote-argument
4902 (expand-file-name invocation-name invocation-directory
))
4903 (mapconcat 'shell-quote-argument load-path
" -L ")
4904 (shell-quote-argument (format code tm
)))))))))
4906 (ert-deftest tramp-test42-recursive-load
()
4907 "Check that Tramp does not fail due to recursive load."
4908 (skip-unless (tramp--test-enabled))
4910 (let ((default-directory (expand-file-name temporary-file-directory
)))
4914 "(expand-file-name %S)" tramp-test-temporary-file-directory
)
4916 "(let ((default-directory %S)) (expand-file-name %S))"
4917 tramp-test-temporary-file-directory
4918 temporary-file-directory
)))
4922 (shell-command-to-string
4924 "%s -batch -Q -L %s --eval %s"
4925 (shell-quote-argument
4926 (expand-file-name invocation-name invocation-directory
))
4927 (mapconcat 'shell-quote-argument load-path
" -L ")
4928 (shell-quote-argument code
))))))))
4930 (ert-deftest tramp-test42-remote-load-path
()
4931 "Check that Tramp autoloads its packages with remote `load-path'."
4932 ;; The autoloaded Tramp objects are different since Emacs 26.1. We
4933 ;; cannot test older Emacsen, therefore.
4934 (skip-unless (tramp--test-emacs26-p))
4936 ;; `tramp-cleanup-all-connections' is autoloaded from tramp-cmds.el.
4937 ;; It shall still work, when a remote file name is in the
4939 (let ((default-directory (expand-file-name temporary-file-directory
))
4941 "(let ((force-load-messages t) \
4942 (load-path (cons \"/foo:bar:\" load-path))) \
4943 (tramp-cleanup-all-connections))"))
4949 "tramp-cmds" (file-name-directory (locate-library "tramp"))))
4950 (shell-command-to-string
4952 "%s -batch -Q -L %s -l tramp-sh --eval %s"
4953 (shell-quote-argument
4954 (expand-file-name invocation-name invocation-directory
))
4955 (mapconcat 'shell-quote-argument load-path
" -L ")
4956 (shell-quote-argument code
)))))))
4958 (ert-deftest tramp-test43-unload
()
4959 "Check that Tramp and its subpackages unload completely.
4960 Since it unloads Tramp, it shall be the last test to run."
4961 :tags
'(:expensive-test
)
4962 (skip-unless noninteractive
)
4963 ;; The autoloaded Tramp objects are different since Emacs 26.1. We
4964 ;; cannot test older Emacsen, therefore.
4965 (skip-unless (tramp--test-emacs26-p))
4967 (when (featurep 'tramp
)
4968 (unload-feature 'tramp
'force
)
4969 ;; No Tramp feature must be left.
4970 (should-not (featurep 'tramp
))
4971 (should-not (all-completions "tramp" (delq 'tramp-tests features
)))
4972 ;; `file-name-handler-alist' must be clean.
4973 (should-not (all-completions "tramp" (mapcar 'cdr file-name-handler-alist
)))
4974 ;; There shouldn't be left a bound symbol, except buffer-local
4975 ;; variables, and autoload functions. We do not regard our test
4976 ;; symbols, and the Tramp unload hooks.
4979 (and (or (and (boundp x
) (null (local-variable-if-set-p x
)))
4980 (and (functionp x
) (null (autoloadp (symbol-function x
)))))
4981 (string-match "^tramp" (symbol-name x
))
4982 (not (string-match "^tramp--?test" (symbol-name x
)))
4983 (not (string-match "unload-hook$" (symbol-name x
)))
4984 (ert-fail (format "`%s' still bound" x
)))))
4985 ;; The defstruct `tramp-file-name' and all its internal functions
4987 (should-not (cl--find-class 'tramp-file-name
))
4991 (string-match "tramp-file-name" (symbol-name x
))
4992 (ert-fail (format "Structure function `%s' still exists" x
)))))
4993 ;; There shouldn't be left a hook function containing a Tramp
4994 ;; function. We do not regard the Tramp unload hooks.
4998 (string-match "-\\(hook\\|function\\)s?$" (symbol-name x
))
4999 (not (string-match "unload-hook$" (symbol-name x
)))
5000 (consp (symbol-value x
))
5001 (ignore-errors (all-completions "tramp" (symbol-value x
)))
5002 (ert-fail (format "Hook `%s' still contains Tramp function" x
)))))))
5004 (defun tramp-test-all (&optional interactive
)
5005 "Run all tests for \\[tramp]."
5008 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
) "^tramp"))
5012 ;; * dired-compress-file
5014 ;; * file-equal-p (partly done in `tramp-test21-file-links')
5015 ;; * file-in-directory-p
5016 ;; * file-name-case-insensitive-p
5018 ;; * Work on skipped tests. Make a comment, when it is impossible.
5019 ;; * Fix `tramp-test05-expand-file-name-relative' in `expand-file-name'.
5020 ;; * Fix `tramp-test06-directory-file-name' for `ftp'.
5021 ;; * Investigate, why `tramp-test11-copy-file' and `tramp-test12-rename-file'
5022 ;; do not work properly for `owncloud'.
5023 ;; * Fix `tramp-test29-start-file-process' on MS Windows (`process-send-eof'?).
5024 ;; * Fix `tramp-test30-interrupt-process', timeout doesn't work reliably.
5025 ;; * Fix Bug#16928 in `tramp-test41-asynchronous-requests'.
5027 (provide 'tramp-tests
)
5028 ;;; tramp-tests.el ends here