1 ;;; tramp-tests.el --- Tests of remote file access
3 ;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `http://www.gnu.org/licenses/'.
22 ;; The tests require a recent ert.el from Emacs 24.4.
24 ;; Some of the tests require access to a remote host files. Since
25 ;; this could be problematic, a mock-up connection method "mock" is
26 ;; used. Emulating a remote connection, it simply calls "sh -i".
27 ;; Tramp's file name handlers still run, so this test is sufficient
28 ;; except for connection establishing.
30 ;; If you want to test a real Tramp connection, set
31 ;; $REMOTE_TEMPORARY_FILE_DIRECTORY to a suitable value in order to
32 ;; overwrite the default value. If you want to skip tests accessing a
33 ;; remote host, set this environment variable to "/dev/null" or
34 ;; whatever is appropriate on your system.
36 ;; A whole test run can be performed calling the command `tramp-test-all'.
47 (declare-function tramp-find-executable
"tramp-sh")
48 (declare-function tramp-get-remote-path
"tramp-sh")
49 (declare-function tramp-get-remote-stat
"tramp-sh")
50 (declare-function tramp-get-remote-perl
"tramp-sh")
51 (defvar tramp-copy-size-limit
)
52 (defvar tramp-persistency-file-name
)
53 (defvar tramp-remote-process-environment
)
55 ;; There is no default value on w32 systems, which could work out of the box.
56 (defconst tramp-test-temporary-file-directory
58 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
59 ((eq system-type
'windows-nt
) null-device
)
63 (tramp-login-program "sh")
64 (tramp-login-args (("-i")))
65 (tramp-remote-shell "/bin/sh")
66 (tramp-remote-shell-args ("-c"))
67 (tramp-connection-timeout 10)))
68 (format "/mock::%s" temporary-file-directory
)))
69 "Temporary directory for Tramp tests.")
71 (setq password-cache-expiry nil
73 tramp-copy-size-limit nil
74 tramp-message-show-message nil
75 tramp-persistency-file-name nil
)
77 ;; This shall happen on hydra only.
78 (when (getenv "NIX_STORE")
79 (add-to-list 'tramp-remote-path
'tramp-own-remote-path
))
81 (defvar tramp--test-enabled-checked nil
82 "Cached result of `tramp--test-enabled'.
83 If the function did run, the value is a cons cell, the `cdr'
86 (defun tramp--test-enabled ()
87 "Whether remote file access is enabled."
88 (unless (consp tramp--test-enabled-checked
)
90 tramp--test-enabled-checked
94 (file-remote-p tramp-test-temporary-file-directory
)
95 (file-directory-p tramp-test-temporary-file-directory
)
96 (file-writable-p tramp-test-temporary-file-directory
))))))
98 (when (cdr tramp--test-enabled-checked
)
99 ;; Cleanup connection.
101 (tramp-cleanup-connection
102 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
103 nil
'keep-password
)))
106 (cdr tramp--test-enabled-checked
))
108 (defun tramp--test-make-temp-name (&optional local
)
109 "Create a temporary file name for test."
111 (make-temp-name "tramp-test")
112 (if local temporary-file-directory tramp-test-temporary-file-directory
)))
114 (defmacro tramp--instrument-test-case
(verbose &rest body
)
115 "Run BODY with `tramp-verbose' equal VERBOSE.
116 Print the the content of the Tramp debug buffer, if BODY does not
117 eval properly in `should', `should-not' or `should-error'. BODY
118 shall not contain a timeout."
119 (declare (indent 1) (debug (natnump body
)))
120 `(let ((tramp-verbose ,verbose
)
121 (tramp-message-show-message t
)
122 (tramp-debug-on-error t
)
123 (debug-ignored-errors
124 (cons "^make-symbolic-link not supported$" debug-ignored-errors
)))
127 (when (> tramp-verbose
3)
128 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
129 (with-current-buffer (tramp-get-connection-buffer v
)
130 (message "%s" (buffer-string)))
131 (with-current-buffer (tramp-get-debug-buffer v
)
132 (message "%s" (buffer-string))))))))
134 (ert-deftest tramp-test00-availability
()
135 "Test availability of Tramp functions."
136 :expected-result
(if (tramp--test-enabled) :passed
:failed
)
137 (message "Remote directory: `%s'" tramp-test-temporary-file-directory
)
138 (should (ignore-errors
140 (file-remote-p tramp-test-temporary-file-directory
)
141 (file-directory-p tramp-test-temporary-file-directory
)
142 (file-writable-p tramp-test-temporary-file-directory
)))))
144 (ert-deftest tramp-test01-file-name-syntax
()
145 "Check remote file name syntax."
147 (should (tramp-tramp-file-p "/method::"))
148 (should (tramp-tramp-file-p "/host:"))
149 (should (tramp-tramp-file-p "/user@:"))
150 (should (tramp-tramp-file-p "/user@host:"))
151 (should (tramp-tramp-file-p "/method:host:"))
152 (should (tramp-tramp-file-p "/method:user@:"))
153 (should (tramp-tramp-file-p "/method:user@host:"))
154 (should (tramp-tramp-file-p "/method:user@email@host:"))
157 (should (tramp-tramp-file-p "/host#1234:"))
158 (should (tramp-tramp-file-p "/user@host#1234:"))
159 (should (tramp-tramp-file-p "/method:host#1234:"))
160 (should (tramp-tramp-file-p "/method:user@host#1234:"))
162 ;; Using an IPv4 address.
163 (should (tramp-tramp-file-p "/1.2.3.4:"))
164 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
165 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
166 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
168 ;; Using an IPv6 address.
169 (should (tramp-tramp-file-p "/[]:"))
170 (should (tramp-tramp-file-p "/[::1]:"))
171 (should (tramp-tramp-file-p "/user@[::1]:"))
172 (should (tramp-tramp-file-p "/method:[::1]:"))
173 (should (tramp-tramp-file-p "/method:user@[::1]:"))
175 ;; Local file name part.
176 (should (tramp-tramp-file-p "/host:/:"))
177 (should (tramp-tramp-file-p "/method:::"))
178 (should (tramp-tramp-file-p "/method::/path/to/file"))
179 (should (tramp-tramp-file-p "/method::file"))
182 (should (tramp-tramp-file-p "/method1:|method2::"))
183 (should (tramp-tramp-file-p "/method1:host1|host2:"))
184 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
185 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
186 (should (tramp-tramp-file-p
187 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
190 (should-not (tramp-tramp-file-p nil
))
191 (should-not (tramp-tramp-file-p 'symbol
))
192 ;; "/:" suppresses file name handlers.
193 (should-not (tramp-tramp-file-p "/::"))
194 (should-not (tramp-tramp-file-p "/:@:"))
195 (should-not (tramp-tramp-file-p "/:[]:"))
196 ;; Multihops require a method.
197 (should-not (tramp-tramp-file-p "/host1|host2:"))
198 ;; Methods or hostnames shall be at least two characters on MS Windows.
199 (when (memq system-type
'(cygwin windows-nt
))
200 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
201 (should-not (tramp-tramp-file-p "/c::/path/to/file"))))
203 (ert-deftest tramp-test02-file-name-dissect
()
204 "Check remote file name components."
205 (let ((tramp-default-method "default-method")
206 (tramp-default-user "default-user")
207 (tramp-default-host "default-host"))
208 ;; Expand `tramp-default-user' and `tramp-default-host'.
209 (should (string-equal
210 (file-remote-p "/method::")
211 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
212 (should (string-equal (file-remote-p "/method::" 'method
) "method"))
213 (should (string-equal (file-remote-p "/method::" 'user
) "default-user"))
214 (should (string-equal (file-remote-p "/method::" 'host
) "default-host"))
215 (should (string-equal (file-remote-p "/method::" 'localname
) ""))
216 (should (string-equal (file-remote-p "/method::" 'hop
) nil
))
218 ;; Expand `tramp-default-method' and `tramp-default-user'.
219 (should (string-equal
220 (file-remote-p "/host:")
221 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
222 (should (string-equal (file-remote-p "/host:" 'method
) "default-method"))
223 (should (string-equal (file-remote-p "/host:" 'user
) "default-user"))
224 (should (string-equal (file-remote-p "/host:" 'host
) "host"))
225 (should (string-equal (file-remote-p "/host:" 'localname
) ""))
226 (should (string-equal (file-remote-p "/host:" 'hop
) nil
))
228 ;; Expand `tramp-default-method' and `tramp-default-host'.
229 (should (string-equal
230 (file-remote-p "/user@:")
231 (format "/%s:%s@%s:" "default-method""user" "default-host")))
232 (should (string-equal (file-remote-p "/user@:" 'method
) "default-method"))
233 (should (string-equal (file-remote-p "/user@:" 'user
) "user"))
234 (should (string-equal (file-remote-p "/user@:" 'host
) "default-host"))
235 (should (string-equal (file-remote-p "/user@:" 'localname
) ""))
236 (should (string-equal (file-remote-p "/user@:" 'hop
) nil
))
238 ;; Expand `tramp-default-method'.
239 (should (string-equal
240 (file-remote-p "/user@host:")
241 (format "/%s:%s@%s:" "default-method" "user" "host")))
242 (should (string-equal
243 (file-remote-p "/user@host:" 'method
) "default-method"))
244 (should (string-equal (file-remote-p "/user@host:" 'user
) "user"))
245 (should (string-equal (file-remote-p "/user@host:" 'host
) "host"))
246 (should (string-equal (file-remote-p "/user@host:" 'localname
) ""))
247 (should (string-equal (file-remote-p "/user@host:" 'hop
) nil
))
249 ;; Expand `tramp-default-user'.
250 (should (string-equal
251 (file-remote-p "/method:host:")
252 (format "/%s:%s@%s:" "method" "default-user" "host")))
253 (should (string-equal (file-remote-p "/method:host:" 'method
) "method"))
254 (should (string-equal (file-remote-p "/method:host:" 'user
) "default-user"))
255 (should (string-equal (file-remote-p "/method:host:" 'host
) "host"))
256 (should (string-equal (file-remote-p "/method:host:" 'localname
) ""))
257 (should (string-equal (file-remote-p "/method:host:" 'hop
) nil
))
259 ;; Expand `tramp-default-host'.
260 (should (string-equal
261 (file-remote-p "/method:user@:")
262 (format "/%s:%s@%s:" "method" "user" "default-host")))
263 (should (string-equal (file-remote-p "/method:user@:" 'method
) "method"))
264 (should (string-equal (file-remote-p "/method:user@:" 'user
) "user"))
265 (should (string-equal (file-remote-p "/method:user@:" 'host
)
267 (should (string-equal (file-remote-p "/method:user@:" 'localname
) ""))
268 (should (string-equal (file-remote-p "/method:user@:" 'hop
) nil
))
271 (should (string-equal
272 (file-remote-p "/method:user@host:")
273 (format "/%s:%s@%s:" "method" "user" "host")))
274 (should (string-equal
275 (file-remote-p "/method:user@host:" 'method
) "method"))
276 (should (string-equal (file-remote-p "/method:user@host:" 'user
) "user"))
277 (should (string-equal (file-remote-p "/method:user@host:" 'host
) "host"))
278 (should (string-equal (file-remote-p "/method:user@host:" 'localname
) ""))
279 (should (string-equal (file-remote-p "/method:user@host:" 'hop
) nil
))
282 (should (string-equal
283 (file-remote-p "/method:user@email@host:")
284 (format "/%s:%s@%s:" "method" "user@email" "host")))
285 (should (string-equal
286 (file-remote-p "/method:user@email@host:" 'method
) "method"))
287 (should (string-equal
288 (file-remote-p "/method:user@email@host:" 'user
) "user@email"))
289 (should (string-equal
290 (file-remote-p "/method:user@email@host:" 'host
) "host"))
291 (should (string-equal
292 (file-remote-p "/method:user@email@host:" 'localname
) ""))
293 (should (string-equal
294 (file-remote-p "/method:user@email@host:" 'hop
) nil
))
296 ;; Expand `tramp-default-method' and `tramp-default-user'.
297 (should (string-equal
298 (file-remote-p "/host#1234:")
299 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
300 (should (string-equal
301 (file-remote-p "/host#1234:" 'method
) "default-method"))
302 (should (string-equal (file-remote-p "/host#1234:" 'user
) "default-user"))
303 (should (string-equal (file-remote-p "/host#1234:" 'host
) "host#1234"))
304 (should (string-equal (file-remote-p "/host#1234:" 'localname
) ""))
305 (should (string-equal (file-remote-p "/host#1234:" 'hop
) nil
))
307 ;; Expand `tramp-default-method'.
308 (should (string-equal
309 (file-remote-p "/user@host#1234:")
310 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
311 (should (string-equal
312 (file-remote-p "/user@host#1234:" 'method
) "default-method"))
313 (should (string-equal (file-remote-p "/user@host#1234:" 'user
) "user"))
314 (should (string-equal (file-remote-p "/user@host#1234:" 'host
) "host#1234"))
315 (should (string-equal (file-remote-p "/user@host#1234:" 'localname
) ""))
316 (should (string-equal (file-remote-p "/user@host#1234:" 'hop
) nil
))
318 ;; Expand `tramp-default-user'.
319 (should (string-equal
320 (file-remote-p "/method:host#1234:")
321 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
322 (should (string-equal
323 (file-remote-p "/method:host#1234:" 'method
) "method"))
324 (should (string-equal
325 (file-remote-p "/method:host#1234:" 'user
) "default-user"))
326 (should (string-equal
327 (file-remote-p "/method:host#1234:" 'host
) "host#1234"))
328 (should (string-equal (file-remote-p "/method:host#1234:" 'localname
) ""))
329 (should (string-equal (file-remote-p "/method:host#1234:" 'hop
) nil
))
332 (should (string-equal
333 (file-remote-p "/method:user@host#1234:")
334 (format "/%s:%s@%s:" "method" "user" "host#1234")))
335 (should (string-equal
336 (file-remote-p "/method:user@host#1234:" 'method
) "method"))
337 (should (string-equal
338 (file-remote-p "/method:user@host#1234:" 'user
) "user"))
339 (should (string-equal
340 (file-remote-p "/method:user@host#1234:" 'host
) "host#1234"))
341 (should (string-equal
342 (file-remote-p "/method:user@host#1234:" 'localname
) ""))
343 (should (string-equal
344 (file-remote-p "/method:user@host#1234:" 'hop
) nil
))
346 ;; Expand `tramp-default-method' and `tramp-default-user'.
347 (should (string-equal
348 (file-remote-p "/1.2.3.4:")
349 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
350 (should (string-equal (file-remote-p "/1.2.3.4:" 'method
) "default-method"))
351 (should (string-equal (file-remote-p "/1.2.3.4:" 'user
) "default-user"))
352 (should (string-equal (file-remote-p "/1.2.3.4:" 'host
) "1.2.3.4"))
353 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname
) ""))
354 (should (string-equal (file-remote-p "/1.2.3.4:" 'hop
) nil
))
356 ;; Expand `tramp-default-method'.
357 (should (string-equal
358 (file-remote-p "/user@1.2.3.4:")
359 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
360 (should (string-equal
361 (file-remote-p "/user@1.2.3.4:" 'method
) "default-method"))
362 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user
) "user"))
363 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'host
) "1.2.3.4"))
364 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname
) ""))
365 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'hop
) nil
))
367 ;; Expand `tramp-default-user'.
368 (should (string-equal
369 (file-remote-p "/method:1.2.3.4:")
370 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
371 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method
) "method"))
372 (should (string-equal
373 (file-remote-p "/method:1.2.3.4:" 'user
) "default-user"))
374 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host
) "1.2.3.4"))
375 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname
) ""))
376 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'hop
) nil
))
379 (should (string-equal
380 (file-remote-p "/method:user@1.2.3.4:")
381 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
382 (should (string-equal
383 (file-remote-p "/method:user@1.2.3.4:" 'method
) "method"))
384 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user
) "user"))
385 (should (string-equal
386 (file-remote-p "/method:user@1.2.3.4:" 'host
) "1.2.3.4"))
387 (should (string-equal
388 (file-remote-p "/method:user@1.2.3.4:" 'localname
) ""))
389 (should (string-equal
390 (file-remote-p "/method:user@1.2.3.4:" 'hop
) nil
))
392 ;; Expand `tramp-default-method', `tramp-default-user' and
393 ;; `tramp-default-host'.
394 (should (string-equal
395 (file-remote-p "/[]:")
397 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
398 (should (string-equal (file-remote-p "/[]:" 'method
) "default-method"))
399 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
400 (should (string-equal (file-remote-p "/[]:" 'host
) "default-host"))
401 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
402 (should (string-equal (file-remote-p "/[]:" 'hop
) nil
))
404 ;; Expand `tramp-default-method' and `tramp-default-user'.
405 (let ((tramp-default-host "::1"))
406 (should (string-equal
407 (file-remote-p "/[]:")
408 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
409 (should (string-equal (file-remote-p "/[]:" 'method
) "default-method"))
410 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
411 (should (string-equal (file-remote-p "/[]:" 'host
) "::1"))
412 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
413 (should (string-equal (file-remote-p "/[]:" 'hop
) nil
)))
415 ;; Expand `tramp-default-method' and `tramp-default-user'.
416 (should (string-equal
417 (file-remote-p "/[::1]:")
418 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
419 (should (string-equal (file-remote-p "/[::1]:" 'method
) "default-method"))
420 (should (string-equal (file-remote-p "/[::1]:" 'user
) "default-user"))
421 (should (string-equal (file-remote-p "/[::1]:" 'host
) "::1"))
422 (should (string-equal (file-remote-p "/[::1]:" 'localname
) ""))
423 (should (string-equal (file-remote-p "/[::1]:" 'hop
) nil
))
425 ;; Expand `tramp-default-method'.
426 (should (string-equal
427 (file-remote-p "/user@[::1]:")
428 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
429 (should (string-equal
430 (file-remote-p "/user@[::1]:" 'method
) "default-method"))
431 (should (string-equal (file-remote-p "/user@[::1]:" 'user
) "user"))
432 (should (string-equal (file-remote-p "/user@[::1]:" 'host
) "::1"))
433 (should (string-equal (file-remote-p "/user@[::1]:" 'localname
) ""))
434 (should (string-equal (file-remote-p "/user@[::1]:" 'hop
) nil
))
436 ;; Expand `tramp-default-user'.
437 (should (string-equal
438 (file-remote-p "/method:[::1]:")
439 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
440 (should (string-equal (file-remote-p "/method:[::1]:" 'method
) "method"))
441 (should (string-equal
442 (file-remote-p "/method:[::1]:" 'user
) "default-user"))
443 (should (string-equal (file-remote-p "/method:[::1]:" 'host
) "::1"))
444 (should (string-equal (file-remote-p "/method:[::1]:" 'localname
) ""))
445 (should (string-equal (file-remote-p "/method:[::1]:" 'hop
) nil
))
448 (should (string-equal
449 (file-remote-p "/method:user@[::1]:")
450 (format "/%s:%s@%s:" "method" "user" "[::1]")))
451 (should (string-equal
452 (file-remote-p "/method:user@[::1]:" 'method
) "method"))
453 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user
) "user"))
454 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host
) "::1"))
455 (should (string-equal
456 (file-remote-p "/method:user@[::1]:" 'localname
) ""))
457 (should (string-equal (file-remote-p "/method:user@[::1]:" 'hop
) nil
))
459 ;; Local file name part.
460 (should (string-equal (file-remote-p "/host:/:" 'localname
) "/:"))
461 (should (string-equal (file-remote-p "/method:::" 'localname
) ":"))
462 (should (string-equal (file-remote-p "/method:: " 'localname
) " "))
463 (should (string-equal (file-remote-p "/method::file" 'localname
) "file"))
464 (should (string-equal
465 (file-remote-p "/method::/path/to/file" 'localname
)
471 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
472 (format "/%s:%s@%s|%s:%s@%s:"
473 "method1" "user1" "host1" "method2" "user2" "host2")))
477 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method
)
482 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user
)
487 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host
)
492 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname
)
497 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'hop
)
499 "method1" "user1" "host1")))
504 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
505 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
506 "method1" "user1" "host1"
507 "method2" "user2" "host2"
508 "method3" "user3" "host3")))
512 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
518 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
524 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
530 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
536 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
538 (format "%s:%s@%s|%s:%s@%s|"
539 "method1" "user1" "host1" "method2" "user2" "host2")))))
541 (ert-deftest tramp-test03-file-name-defaults
()
542 "Check default values for some methods."
543 ;; Default values in tramp-adb.el.
544 (should (string-equal (file-remote-p "/adb::" 'host
) ""))
545 ;; Default values in tramp-ftp.el.
546 (should (string-equal (file-remote-p "/ftp.host:" 'method
) "ftp"))
547 (dolist (u '("ftp" "anonymous"))
548 (should (string-equal (file-remote-p (format "/%s@:" u
) 'method
) "ftp")))
549 ;; Default values in tramp-gvfs.el.
550 (when (and (load "tramp-gvfs" 'noerror
'nomessage
)
551 (symbol-value 'tramp-gvfs-enabled
))
552 (should (string-equal (file-remote-p "/synce::" 'user
) nil
)))
553 ;; Default values in tramp-gw.el.
554 (dolist (m '("tunnel" "socks"))
556 (string-equal (file-remote-p (format "/%s::" m
) 'user
) (user-login-name))))
557 ;; Default values in tramp-sh.el.
558 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
559 (should (string-equal (file-remote-p (format "/root@%s:" h
) 'method
) "su")))
560 (dolist (m '("su" "sudo" "ksu"))
561 (should (string-equal (file-remote-p (format "/%s::" m
) 'user
) "root")))
562 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
564 (string-equal (file-remote-p (format "/%s::" m
) 'user
) (user-login-name))))
565 ;; Default values in tramp-smb.el.
566 (should (string-equal (file-remote-p "/user%domain@host:" 'method
) "smb"))
567 (should (string-equal (file-remote-p "/smb::" 'user
) nil
)))
569 (ert-deftest tramp-test04-substitute-in-file-name
()
570 "Check `substitute-in-file-name'."
571 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
574 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
576 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
579 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
581 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
582 (let (process-environment)
585 (substitute-in-file-name "/method:host:/path/$FOO")
586 "/method:host:/path/$FOO"))
590 (substitute-in-file-name "/method:host:/path/$FOO")
591 "/method:host:/path/bla"))
594 (substitute-in-file-name "/method:host:/path/$$FOO")
595 "/method:host:/path/$FOO"))))
597 (ert-deftest tramp-test05-expand-file-name
()
598 "Check `expand-file-name'."
601 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
604 (expand-file-name "/method:host:/path/../file") "/method:host:/file")))
606 (ert-deftest tramp-test06-directory-file-name
()
607 "Check `directory-file-name'.
608 This checks also `file-name-as-directory', `file-name-directory',
609 `file-name-nondirectory' and `unhandled-file-name-directory'."
612 (directory-file-name "/method:host:/path/to/file")
613 "/method:host:/path/to/file"))
616 (directory-file-name "/method:host:/path/to/file/")
617 "/method:host:/path/to/file"))
620 (file-name-as-directory "/method:host:/path/to/file")
621 "/method:host:/path/to/file/"))
624 (file-name-as-directory "/method:host:/path/to/file/")
625 "/method:host:/path/to/file/"))
628 (file-name-directory "/method:host:/path/to/file")
629 "/method:host:/path/to/"))
632 (file-name-directory "/method:host:/path/to/file/")
633 "/method:host:/path/to/file/"))
635 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
637 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
639 (unhandled-file-name-directory "/method:host:/path/to/file")))
641 (ert-deftest tramp-test07-file-exists-p
()
642 "Check `file-exist-p', `write-region' and `delete-file'."
643 (skip-unless (tramp--test-enabled))
645 (let ((tmp-name (tramp--test-make-temp-name)))
646 (should-not (file-exists-p tmp-name
))
647 (write-region "foo" nil tmp-name
)
648 (should (file-exists-p tmp-name
))
649 (delete-file tmp-name
)
650 (should-not (file-exists-p tmp-name
))))
652 (ert-deftest tramp-test08-file-local-copy
()
653 "Check `file-local-copy'."
654 (skip-unless (tramp--test-enabled))
656 (let ((tmp-name1 (tramp--test-make-temp-name))
660 (write-region "foo" nil tmp-name1
)
661 (should (setq tmp-name2
(file-local-copy tmp-name1
)))
663 (insert-file-contents tmp-name2
)
664 (should (string-equal (buffer-string) "foo")))
665 ;; Check also that a file transfer with compression works.
666 (let ((default-directory tramp-test-temporary-file-directory
)
667 (tramp-copy-size-limit 4)
668 (tramp-inline-compress-start-size 2))
669 (delete-file tmp-name2
)
670 (should (setq tmp-name2
(file-local-copy tmp-name1
)))))
674 (delete-file tmp-name1
)
675 (delete-file tmp-name2
)))))
677 (ert-deftest tramp-test09-insert-file-contents
()
678 "Check `insert-file-contents'."
679 (skip-unless (tramp--test-enabled))
681 (let ((tmp-name (tramp--test-make-temp-name)))
684 (write-region "foo" nil tmp-name
)
686 (insert-file-contents tmp-name
)
687 (should (string-equal (buffer-string) "foo"))
688 (insert-file-contents tmp-name
)
689 (should (string-equal (buffer-string) "foofoo"))
691 (insert-file-contents tmp-name nil
1 3)
692 (should (string-equal (buffer-string) "oofoofoo"))
694 (insert-file-contents tmp-name nil nil nil
'replace
)
695 (should (string-equal (buffer-string) "foo"))))
698 (ignore-errors (delete-file tmp-name
)))))
700 (ert-deftest tramp-test10-write-region
()
701 "Check `write-region'."
702 (skip-unless (tramp--test-enabled))
704 (let ((tmp-name (tramp--test-make-temp-name)))
709 (write-region nil nil tmp-name
))
711 (insert-file-contents tmp-name
)
712 (should (string-equal (buffer-string) "foo")))
716 (write-region nil nil tmp-name
'append
))
718 (insert-file-contents tmp-name
)
719 (should (string-equal (buffer-string) "foobla")))
721 (write-region "foo" nil tmp-name
)
723 (insert-file-contents tmp-name
)
724 (should (string-equal (buffer-string) "foo")))
728 (write-region 3 5 tmp-name
))
730 (insert-file-contents tmp-name
)
731 (should (string-equal (buffer-string) "34"))))
734 (ignore-errors (delete-file tmp-name
)))))
736 (ert-deftest tramp-test11-copy-file
()
738 (skip-unless (tramp--test-enabled))
740 (let ((tmp-name1 (tramp--test-make-temp-name))
741 (tmp-name2 (tramp--test-make-temp-name))
742 (tmp-name3 (tramp--test-make-temp-name))
743 (tmp-name4 (tramp--test-make-temp-name 'local
))
744 (tmp-name5 (tramp--test-make-temp-name 'local
)))
746 ;; Copy on remote side.
749 (write-region "foo" nil tmp-name1
)
750 (copy-file tmp-name1 tmp-name2
)
751 (should (file-exists-p tmp-name2
))
753 (insert-file-contents tmp-name2
)
754 (should (string-equal (buffer-string) "foo")))
755 (should-error (copy-file tmp-name1 tmp-name2
))
756 (copy-file tmp-name1 tmp-name2
'ok
)
757 (make-directory tmp-name3
)
758 (copy-file tmp-name1 tmp-name3
)
761 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name3
))))
764 (ignore-errors (delete-file tmp-name1
))
765 (ignore-errors (delete-file tmp-name2
))
766 (ignore-errors (delete-directory tmp-name3
'recursive
)))
768 ;; Copy from remote side to local side.
771 (write-region "foo" nil tmp-name1
)
772 (copy-file tmp-name1 tmp-name4
)
773 (should (file-exists-p tmp-name4
))
775 (insert-file-contents tmp-name4
)
776 (should (string-equal (buffer-string) "foo")))
777 (should-error (copy-file tmp-name1 tmp-name4
))
778 (copy-file tmp-name1 tmp-name4
'ok
)
779 (make-directory tmp-name5
)
780 (copy-file tmp-name1 tmp-name5
)
783 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name5
))))
786 (ignore-errors (delete-file tmp-name1
))
787 (ignore-errors (delete-file tmp-name4
))
788 (ignore-errors (delete-directory tmp-name5
'recursive
)))
790 ;; Copy from local side to remote side.
793 (write-region "foo" nil tmp-name4 nil
'nomessage
)
794 (copy-file tmp-name4 tmp-name1
)
795 (should (file-exists-p tmp-name1
))
797 (insert-file-contents tmp-name1
)
798 (should (string-equal (buffer-string) "foo")))
799 (should-error (copy-file tmp-name4 tmp-name1
))
800 (copy-file tmp-name4 tmp-name1
'ok
)
801 (make-directory tmp-name3
)
802 (copy-file tmp-name4 tmp-name3
)
805 (expand-file-name (file-name-nondirectory tmp-name4
) tmp-name3
))))
808 (ignore-errors (delete-file tmp-name1
))
809 (ignore-errors (delete-file tmp-name4
))
810 (ignore-errors (delete-directory tmp-name3
'recursive
)))))
812 (ert-deftest tramp-test12-rename-file
()
813 "Check `rename-file'."
814 (skip-unless (tramp--test-enabled))
816 (let ((tmp-name1 (tramp--test-make-temp-name))
817 (tmp-name2 (tramp--test-make-temp-name))
818 (tmp-name3 (tramp--test-make-temp-name))
819 (tmp-name4 (tramp--test-make-temp-name 'local
))
820 (tmp-name5 (tramp--test-make-temp-name 'local
)))
822 ;; Rename on remote side.
825 (write-region "foo" nil tmp-name1
)
826 (rename-file tmp-name1 tmp-name2
)
827 (should-not (file-exists-p tmp-name1
))
828 (should (file-exists-p tmp-name2
))
830 (insert-file-contents tmp-name2
)
831 (should (string-equal (buffer-string) "foo")))
832 (write-region "foo" nil tmp-name1
)
833 (should-error (rename-file tmp-name1 tmp-name2
))
834 (rename-file tmp-name1 tmp-name2
'ok
)
835 (should-not (file-exists-p tmp-name1
))
836 (write-region "foo" nil tmp-name1
)
837 (make-directory tmp-name3
)
838 (rename-file tmp-name1 tmp-name3
)
839 (should-not (file-exists-p tmp-name1
))
842 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name3
))))
845 (ignore-errors (delete-file tmp-name1
))
846 (ignore-errors (delete-file tmp-name2
))
847 (ignore-errors (delete-directory tmp-name3
'recursive
)))
849 ;; Rename from remote side to local side.
852 (write-region "foo" nil tmp-name1
)
853 (rename-file tmp-name1 tmp-name4
)
854 (should-not (file-exists-p tmp-name1
))
855 (should (file-exists-p tmp-name4
))
857 (insert-file-contents tmp-name4
)
858 (should (string-equal (buffer-string) "foo")))
859 (write-region "foo" nil tmp-name1
)
860 (should-error (rename-file tmp-name1 tmp-name4
))
861 (rename-file tmp-name1 tmp-name4
'ok
)
862 (should-not (file-exists-p tmp-name1
))
863 (write-region "foo" nil tmp-name1
)
864 (make-directory tmp-name5
)
865 (rename-file tmp-name1 tmp-name5
)
866 (should-not (file-exists-p tmp-name1
))
869 (expand-file-name (file-name-nondirectory tmp-name1
) tmp-name5
))))
872 (ignore-errors (delete-file tmp-name1
))
873 (ignore-errors (delete-file tmp-name4
))
874 (ignore-errors (delete-directory tmp-name5
'recursive
)))
876 ;; Rename from local side to remote side.
879 (write-region "foo" nil tmp-name4 nil
'nomessage
)
880 (rename-file tmp-name4 tmp-name1
)
881 (should-not (file-exists-p tmp-name4
))
882 (should (file-exists-p tmp-name1
))
884 (insert-file-contents tmp-name1
)
885 (should (string-equal (buffer-string) "foo")))
886 (write-region "foo" nil tmp-name4 nil
'nomessage
)
887 (should-error (rename-file tmp-name4 tmp-name1
))
888 (rename-file tmp-name4 tmp-name1
'ok
)
889 (should-not (file-exists-p tmp-name4
))
890 (write-region "foo" nil tmp-name4 nil
'nomessage
)
891 (make-directory tmp-name3
)
892 (rename-file tmp-name4 tmp-name3
)
893 (should-not (file-exists-p tmp-name4
))
896 (expand-file-name (file-name-nondirectory tmp-name4
) tmp-name3
))))
899 (ignore-errors (delete-file tmp-name1
))
900 (ignore-errors (delete-file tmp-name4
))
901 (ignore-errors (delete-directory tmp-name3
'recursive
)))))
903 (ert-deftest tramp-test13-make-directory
()
904 "Check `make-directory'.
905 This tests also `file-directory-p' and `file-accessible-directory-p'."
906 (skip-unless (tramp--test-enabled))
908 (let* ((tmp-name1 (tramp--test-make-temp-name))
909 (tmp-name2 (expand-file-name "foo/bar" tmp-name1
)))
912 (make-directory tmp-name1
)
913 (should (file-directory-p tmp-name1
))
914 (should (file-accessible-directory-p tmp-name1
))
915 (should-error (make-directory tmp-name2
) :type
'file-error
)
916 (make-directory tmp-name2
'parents
)
917 (should (file-directory-p tmp-name2
))
918 (should (file-accessible-directory-p tmp-name2
)))
921 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
923 (ert-deftest tramp-test14-delete-directory
()
924 "Check `delete-directory'."
925 (skip-unless (tramp--test-enabled))
927 (let ((tmp-name (tramp--test-make-temp-name)))
928 ;; Delete empty directory.
929 (make-directory tmp-name
)
930 (should (file-directory-p tmp-name
))
931 (delete-directory tmp-name
)
932 (should-not (file-directory-p tmp-name
))
933 ;; Delete non-empty directory.
934 (make-directory tmp-name
)
935 (write-region "foo" nil
(expand-file-name "bla" tmp-name
))
936 (should-error (delete-directory tmp-name
) :type
'file-error
)
937 (delete-directory tmp-name
'recursive
)
938 (should-not (file-directory-p tmp-name
))))
940 (ert-deftest tramp-test15-copy-directory
()
941 "Check `copy-directory'."
942 (skip-unless (tramp--test-enabled))
946 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
947 'tramp-smb-file-name-handler
)))
949 (let* ((tmp-name1 (tramp--test-make-temp-name))
950 (tmp-name2 (tramp--test-make-temp-name))
951 (tmp-name3 (expand-file-name
952 (file-name-nondirectory tmp-name1
) tmp-name2
))
953 (tmp-name4 (expand-file-name "foo" tmp-name1
))
954 (tmp-name5 (expand-file-name "foo" tmp-name2
))
955 (tmp-name6 (expand-file-name "foo" tmp-name3
)))
958 ;; Copy empty directory.
959 (make-directory tmp-name1
)
960 (write-region "foo" nil tmp-name4
)
961 (should (file-directory-p tmp-name1
))
962 (should (file-exists-p tmp-name4
))
963 (copy-directory tmp-name1 tmp-name2
)
964 (should (file-directory-p tmp-name2
))
965 (should (file-exists-p tmp-name5
))
966 ;; Target directory does exist already.
967 (copy-directory tmp-name1 tmp-name2
)
968 (should (file-directory-p tmp-name3
))
969 (should (file-exists-p tmp-name6
)))
973 (delete-directory tmp-name1
'recursive
)
974 (delete-directory tmp-name2
'recursive
)))))
976 (ert-deftest tramp-test16-directory-files
()
977 "Check `directory-files'."
978 (skip-unless (tramp--test-enabled))
980 (let* ((tmp-name1 (tramp--test-make-temp-name))
981 (tmp-name2 (expand-file-name "bla" tmp-name1
))
982 (tmp-name3 (expand-file-name "foo" tmp-name1
)))
985 (make-directory tmp-name1
)
986 (write-region "foo" nil tmp-name2
)
987 (write-region "bla" nil tmp-name3
)
988 (should (file-directory-p tmp-name1
))
989 (should (file-exists-p tmp-name2
))
990 (should (file-exists-p tmp-name3
))
991 (should (equal (directory-files tmp-name1
) '("." ".." "bla" "foo")))
992 (should (equal (directory-files tmp-name1
'full
)
993 `(,(concat tmp-name1
"/.")
994 ,(concat tmp-name1
"/..")
995 ,tmp-name2
,tmp-name3
)))
996 (should (equal (directory-files
997 tmp-name1 nil directory-files-no-dot-files-regexp
)
999 (should (equal (directory-files
1000 tmp-name1
'full directory-files-no-dot-files-regexp
)
1001 `(,tmp-name2
,tmp-name3
))))
1004 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
1006 (ert-deftest tramp-test17-insert-directory
()
1007 "Check `insert-directory'."
1008 (skip-unless (tramp--test-enabled))
1010 (let* ((tmp-name1 (tramp--test-make-temp-name))
1011 (tmp-name2 (expand-file-name "foo" tmp-name1
))
1012 ;; We test for the summary line. Keyword "total" could be localized.
1013 (process-environment
1014 (append '("LANG=C" "LANGUAGE=C" "LC_ALL=C") process-environment
)))
1017 (make-directory tmp-name1
)
1018 (write-region "foo" nil tmp-name2
)
1019 (should (file-directory-p tmp-name1
))
1020 (should (file-exists-p tmp-name2
))
1022 (insert-directory tmp-name1 nil
)
1023 (goto-char (point-min))
1024 (should (looking-at-p (regexp-quote tmp-name1
))))
1026 (insert-directory tmp-name1
"-al")
1027 (goto-char (point-min))
1028 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1
)))))
1030 (insert-directory (file-name-as-directory tmp-name1
) "-al")
1031 (goto-char (point-min))
1033 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1
)))))
1036 (file-name-as-directory tmp-name1
) "-al" nil
'full-directory-p
)
1037 (goto-char (point-min))
1041 ;; There might be a summary line.
1042 "\\(total.+[[:digit:]]+\n\\)?"
1043 ;; We don't know in which order ".", ".." and "foo" appear.
1044 "\\(.+ \\(\\.?\\.\\|foo\\)\n\\)\\{3\\}")))))
1047 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
1049 (ert-deftest tramp-test18-file-attributes
()
1050 "Check `file-attributes'.
1051 This tests also `file-readable-p' and `file-regular-p'."
1052 (skip-unless (tramp--test-enabled))
1054 ;; We must use `file-truename' for the temporary directory, because
1055 ;; it could be located on a symlinked directory. This would let the
1057 (let* ((tramp-test-temporary-file-directory
1058 (file-truename tramp-test-temporary-file-directory
))
1059 (tmp-name1 (tramp--test-make-temp-name))
1060 (tmp-name2 (tramp--test-make-temp-name))
1061 ;; File name with "//".
1065 (file-remote-p tmp-name1
)
1066 (replace-regexp-in-string
1067 "/" "//" (file-remote-p tmp-name1
'localname
))))
1071 (write-region "foo" nil tmp-name1
)
1072 (should (file-exists-p tmp-name1
))
1073 (setq attr
(file-attributes tmp-name1
))
1074 (should (consp attr
))
1075 (should (file-exists-p tmp-name1
))
1076 (should (file-readable-p tmp-name1
))
1077 (should (file-regular-p tmp-name1
))
1078 ;; We do not test inodes and device numbers.
1079 (should (null (car attr
)))
1080 (should (numberp (nth 1 attr
))) ;; Link.
1081 (should (numberp (nth 2 attr
))) ;; Uid.
1082 (should (numberp (nth 3 attr
))) ;; Gid.
1083 ;; Last access time.
1084 (should (stringp (current-time-string (nth 4 attr
))))
1085 ;; Last modification time.
1086 (should (stringp (current-time-string (nth 5 attr
))))
1087 ;; Last status change time.
1088 (should (stringp (current-time-string (nth 6 attr
))))
1089 (should (numberp (nth 7 attr
))) ;; Size.
1090 (should (stringp (nth 8 attr
))) ;; Modes.
1092 (setq attr
(file-attributes tmp-name1
'string
))
1093 (should (stringp (nth 2 attr
))) ;; Uid.
1094 (should (stringp (nth 3 attr
))) ;; Gid.
1098 (make-symbolic-link tmp-name1 tmp-name2
)
1099 (should (file-exists-p tmp-name2
))
1100 (should (file-symlink-p tmp-name2
))
1101 (setq attr
(file-attributes tmp-name2
))
1102 (should (string-equal
1104 (file-remote-p (file-truename tmp-name1
) 'localname
)))
1105 (delete-file tmp-name2
))
1107 (should (string-equal (error-message-string err
)
1108 "make-symbolic-link not supported"))))
1110 ;; Check, that "//" in symlinks are handled properly.
1112 (let ((default-directory tramp-test-temporary-file-directory
))
1116 (tramp-file-name-localname (tramp-dissect-file-name tmp-name3
))
1117 (tramp-file-name-localname (tramp-dissect-file-name tmp-name2
)))
1119 (when (file-symlink-p tmp-name2
)
1120 (setq attr
(file-attributes tmp-name2
))
1121 (should (string-equal
1123 (file-remote-p (file-truename tmp-name3
) 'localname
)))
1124 (delete-file tmp-name2
))
1126 (delete-file tmp-name1
)
1127 (make-directory tmp-name1
)
1128 (should (file-exists-p tmp-name1
))
1129 (should (file-readable-p tmp-name1
))
1130 (should-not (file-regular-p tmp-name1
))
1131 (setq attr
(file-attributes tmp-name1
))
1132 (should (eq (car attr
) t
)))
1135 (ignore-errors (delete-directory tmp-name1
))
1136 (ignore-errors (delete-file tmp-name1
))
1137 (ignore-errors (delete-file tmp-name2
)))))
1139 (ert-deftest tramp-test19-directory-files-and-attributes
()
1140 "Check `directory-files-and-attributes'."
1141 (skip-unless (tramp--test-enabled))
1143 ;; `directory-files-and-attributes' contains also values for "../".
1144 ;; Ensure that this doesn't change during tests, for
1145 ;; example due to handling temporary files.
1146 (let* ((tmp-name1 (tramp--test-make-temp-name))
1147 (tmp-name2 (expand-file-name "bla" tmp-name1
))
1151 (make-directory tmp-name1
)
1152 (should (file-directory-p tmp-name1
))
1153 (make-directory tmp-name2
)
1154 (should (file-directory-p tmp-name2
))
1155 (write-region "foo" nil
(expand-file-name "foo" tmp-name2
))
1156 (write-region "bar" nil
(expand-file-name "bar" tmp-name2
))
1157 (write-region "boz" nil
(expand-file-name "boz" tmp-name2
))
1158 (setq attr
(directory-files-and-attributes tmp-name2
))
1159 (should (consp attr
))
1160 ;; Dumb remote shells without perl(1) or stat(1) are not
1161 ;; able to return the date correctly. They say "don't know".
1166 (file-attributes (expand-file-name (car elt
) tmp-name2
)))
1169 (equal (file-attributes (expand-file-name (car elt
) tmp-name2
))
1171 (setq attr
(directory-files-and-attributes tmp-name2
'full
))
1173 (unless (equal (nth 5 (file-attributes (car elt
))) '(0 0))
1175 (equal (file-attributes (car elt
)) (cdr elt
)))))
1176 (setq attr
(directory-files-and-attributes tmp-name2 nil
"^b"))
1177 (should (equal (mapcar 'car attr
) '("bar" "boz"))))
1180 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
1182 (ert-deftest tramp-test20-file-modes
()
1183 "Check `file-modes'.
1184 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
1185 (skip-unless (tramp--test-enabled))
1189 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1190 '(tramp-adb-file-name-handler
1191 tramp-gvfs-file-name-handler
1192 tramp-smb-file-name-handler
))))
1194 (let ((tmp-name (tramp--test-make-temp-name)))
1197 (write-region "foo" nil tmp-name
)
1198 (should (file-exists-p tmp-name
))
1199 (set-file-modes tmp-name
#o777
)
1200 (should (= (file-modes tmp-name
) #o777
))
1201 (should (file-executable-p tmp-name
))
1202 (should (file-writable-p tmp-name
))
1203 (set-file-modes tmp-name
#o444
)
1204 (should (= (file-modes tmp-name
) #o444
))
1205 (should-not (file-executable-p tmp-name
))
1206 ;; A file is always writable for user "root".
1207 (unless (zerop (nth 2 (file-attributes tmp-name
)))
1208 (should-not (file-writable-p tmp-name
))))
1211 (ignore-errors (delete-file tmp-name
)))))
1213 (ert-deftest tramp-test21-file-links
()
1214 "Check `file-symlink-p'.
1215 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1216 (skip-unless (tramp--test-enabled))
1218 ;; We must use `file-truename' for the temporary directory, because
1219 ;; it could be located on a symlinked directory. This would let the
1221 (let* ((tramp-test-temporary-file-directory
1222 (file-truename tramp-test-temporary-file-directory
))
1223 (tmp-name1 (tramp--test-make-temp-name))
1224 (tmp-name2 (tramp--test-make-temp-name))
1225 (tmp-name3 (tramp--test-make-temp-name 'local
)))
1227 ;; Check `make-symbolic-link'.
1230 (write-region "foo" nil tmp-name1
)
1231 (should (file-exists-p tmp-name1
))
1232 ;; Method "smb" supports `make-symbolic-link' only if the
1233 ;; remote host has CIFS capabilities. tramp-adb.el and
1234 ;; tramp-gvfs.el do not support symbolic links at all.
1236 (make-symbolic-link tmp-name1 tmp-name2
)
1239 (not (string-equal (error-message-string err
)
1240 "make-symbolic-link not supported")))))
1241 (should (file-symlink-p tmp-name2
))
1242 (should-error (make-symbolic-link tmp-name1 tmp-name2
))
1243 (make-symbolic-link tmp-name1 tmp-name2
'ok-if-already-exists
)
1244 (should (file-symlink-p tmp-name2
))
1245 ;; `tmp-name3' is a local file name.
1246 (should-error (make-symbolic-link tmp-name1 tmp-name3
)))
1250 (delete-file tmp-name1
)
1251 (delete-file tmp-name2
)))
1253 ;; Check `add-name-to-file'.
1256 (write-region "foo" nil tmp-name1
)
1257 (should (file-exists-p tmp-name1
))
1258 (add-name-to-file tmp-name1 tmp-name2
)
1259 (should-not (file-symlink-p tmp-name2
))
1260 (should-error (add-name-to-file tmp-name1 tmp-name2
))
1261 (add-name-to-file tmp-name1 tmp-name2
'ok-if-already-exists
)
1262 (should-not (file-symlink-p tmp-name2
))
1263 ;; `tmp-name3' is a local file name.
1264 (should-error (add-name-to-file tmp-name1 tmp-name3
)))
1268 (delete-file tmp-name1
)
1269 (delete-file tmp-name2
)))
1271 ;; Check `file-truename'.
1274 (write-region "foo" nil tmp-name1
)
1275 (should (file-exists-p tmp-name1
))
1276 (make-symbolic-link tmp-name1 tmp-name2
)
1277 (should (file-symlink-p tmp-name2
))
1278 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
1280 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
)))
1281 (should (file-equal-p tmp-name1 tmp-name2
)))
1283 (delete-file tmp-name1
)
1284 (delete-file tmp-name2
)))
1286 ;; `file-truename' shall preserve trailing link of directories.
1287 (unless (file-symlink-p tramp-test-temporary-file-directory
)
1288 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory
))
1289 (dir2 (file-name-as-directory dir1
)))
1290 (should (string-equal (file-truename dir1
) (expand-file-name dir1
)))
1291 (should (string-equal (file-truename dir2
) (expand-file-name dir2
)))))))
1293 (ert-deftest tramp-test22-file-times
()
1294 "Check `set-file-times' and `file-newer-than-file-p'."
1295 (skip-unless (tramp--test-enabled))
1299 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1300 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1302 (let ((tmp-name1 (tramp--test-make-temp-name))
1303 (tmp-name2 (tramp--test-make-temp-name))
1304 (tmp-name3 (tramp--test-make-temp-name)))
1307 (write-region "foo" nil tmp-name1
)
1308 (should (file-exists-p tmp-name1
))
1309 (should (consp (nth 5 (file-attributes tmp-name1
))))
1310 ;; '(0 0) means don't know, and will be replaced by
1311 ;; `current-time'. Therefore, we use '(0 1).
1312 ;; We skip the test, if the remote handler is not able to
1313 ;; set the correct time.
1314 (skip-unless (set-file-times tmp-name1
'(0 1)))
1315 ;; Dumb remote shells without perl(1) or stat(1) are not
1316 ;; able to return the date correctly. They say "don't know".
1317 (unless (equal (nth 5 (file-attributes tmp-name1
)) '(0 0))
1318 (should (equal (nth 5 (file-attributes tmp-name1
)) '(0 1)))
1319 (write-region "bla" nil tmp-name2
)
1320 (should (file-exists-p tmp-name2
))
1321 (should (file-newer-than-file-p tmp-name2 tmp-name1
))
1322 ;; `tmp-name3' does not exist.
1323 (should (file-newer-than-file-p tmp-name2 tmp-name3
))
1324 (should-not (file-newer-than-file-p tmp-name3 tmp-name1
))))
1328 (delete-file tmp-name1
)
1329 (delete-file tmp-name2
)))))
1331 (ert-deftest tramp-test23-visited-file-modtime
()
1332 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1333 (skip-unless (tramp--test-enabled))
1335 (let ((tmp-name (tramp--test-make-temp-name)))
1338 (write-region "foo" nil tmp-name
)
1339 (should (file-exists-p tmp-name
))
1341 (insert-file-contents tmp-name
)
1342 (should (verify-visited-file-modtime))
1343 (set-visited-file-modtime '(0 1))
1344 (should (verify-visited-file-modtime))
1345 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1348 (ignore-errors (delete-file tmp-name
)))))
1350 (ert-deftest tramp-test24-file-name-completion
()
1351 "Check `file-name-completion' and `file-name-all-completions'."
1352 (skip-unless (tramp--test-enabled))
1354 (let ((tmp-name (tramp--test-make-temp-name)))
1357 (make-directory tmp-name
)
1358 (should (file-directory-p tmp-name
))
1359 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
1360 (write-region "bar" nil
(expand-file-name "bold" tmp-name
))
1361 (make-directory (expand-file-name "boz" tmp-name
))
1362 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
1363 (should (equal (file-name-completion "b" tmp-name
) "bo"))
1365 (equal (file-name-completion "b" tmp-name
'file-directory-p
) "boz/"))
1366 (should (equal (file-name-all-completions "fo" tmp-name
) '("foo")))
1368 (equal (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
1372 (ignore-errors (delete-directory tmp-name
'recursive
)))))
1374 (ert-deftest tramp-test25-load
()
1376 (skip-unless (tramp--test-enabled))
1378 (let ((tmp-name (tramp--test-make-temp-name)))
1381 (load tmp-name
'noerror
'nomessage
)
1382 (should-not (featurep 'tramp-test-load
))
1383 (write-region "(provide 'tramp-test-load)" nil tmp-name
)
1384 ;; `load' in lread.c does not pass `must-suffix'. Why?
1385 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1386 (load tmp-name nil
'nomessage
'nosuffix
)
1387 (should (featurep 'tramp-test-load
)))
1391 (and (featurep 'tramp-test-load
) (unload-feature 'tramp-test-load
))
1392 (delete-file tmp-name
)))))
1394 (ert-deftest tramp-test26-process-file
()
1395 "Check `process-file'."
1396 (skip-unless (tramp--test-enabled))
1400 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1401 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1403 (let* ((tmp-name (tramp--test-make-temp-name))
1404 (fnnd (file-name-nondirectory tmp-name
))
1405 (default-directory tramp-test-temporary-file-directory
)
1406 kill-buffer-query-functions
)
1409 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1410 ;; do not exist on hydra.
1411 (should (zerop (process-file "true")))
1412 (should-not (zerop (process-file "false")))
1413 (should-not (zerop (process-file "binary-does-not-exist")))
1415 (write-region "foo" nil tmp-name
)
1416 (should (file-exists-p tmp-name
))
1417 (should (zerop (process-file "ls" nil t nil fnnd
)))
1418 ;; `ls' could produce colorized output.
1419 (goto-char (point-min))
1420 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1421 (replace-match "" nil nil
))
1422 (should (string-equal (format "%s\n" fnnd
) (buffer-string)))
1423 (should-not (get-buffer-window (current-buffer) t
))
1425 ;; Second run. The output must be appended.
1426 (should (zerop (process-file "ls" nil t t fnnd
)))
1427 ;; `ls' could produce colorized output.
1428 (goto-char (point-min))
1429 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1430 (replace-match "" nil nil
))
1432 (string-equal (format "%s\n%s\n" fnnd fnnd
) (buffer-string)))
1433 ;; A non-nil DISPLAY must not raise the buffer.
1434 (should-not (get-buffer-window (current-buffer) t
))))
1437 (ignore-errors (delete-file tmp-name
)))))
1439 (ert-deftest tramp-test27-start-file-process
()
1440 "Check `start-file-process'."
1441 (skip-unless (tramp--test-enabled))
1445 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1446 '(tramp-adb-file-name-handler
1447 tramp-gvfs-file-name-handler
1448 tramp-smb-file-name-handler
))))
1450 (let ((default-directory tramp-test-temporary-file-directory
)
1451 (tmp-name (tramp--test-make-temp-name))
1452 kill-buffer-query-functions proc
)
1455 (setq proc
(start-file-process "test1" (current-buffer) "cat"))
1456 (should (processp proc
))
1457 (should (equal (process-status proc
) 'run
))
1458 (process-send-string proc
"foo")
1459 (process-send-eof proc
)
1461 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1462 (while (< (- (point-max) (point-min)) (length "foo"))
1463 (accept-process-output proc
1)))
1464 (should (string-equal (buffer-string) "foo")))
1467 (ignore-errors (delete-process proc
)))
1471 (write-region "foo" nil tmp-name
)
1472 (should (file-exists-p tmp-name
))
1475 "test2" (current-buffer)
1476 "cat" (file-name-nondirectory tmp-name
)))
1477 (should (processp proc
))
1479 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1480 (while (< (- (point-max) (point-min)) (length "foo"))
1481 (accept-process-output proc
1)))
1482 (should (string-equal (buffer-string) "foo")))
1486 (delete-process proc
)
1487 (delete-file tmp-name
)))
1491 (setq proc
(start-file-process "test3" (current-buffer) "cat"))
1492 (should (processp proc
))
1493 (should (equal (process-status proc
) 'run
))
1496 (lambda (p s
) (with-current-buffer (process-buffer p
) (insert s
))))
1497 (process-send-string proc
"foo")
1498 (process-send-eof proc
)
1500 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1501 (while (< (- (point-max) (point-min)) (length "foo"))
1502 (accept-process-output proc
1)))
1503 (should (string-equal (buffer-string) "foo")))
1506 (ignore-errors (delete-process proc
)))))
1508 (ert-deftest tramp-test28-shell-command
()
1509 "Check `shell-command'."
1510 (skip-unless (tramp--test-enabled))
1514 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1515 '(tramp-adb-file-name-handler
1516 tramp-gvfs-file-name-handler
1517 tramp-smb-file-name-handler
))))
1519 (let ((tmp-name (tramp--test-make-temp-name))
1520 (default-directory tramp-test-temporary-file-directory
)
1521 kill-buffer-query-functions
)
1524 (write-region "foo" nil tmp-name
)
1525 (should (file-exists-p tmp-name
))
1527 (format "ls %s" (file-name-nondirectory tmp-name
)) (current-buffer))
1528 ;; `ls' could produce colorized output.
1529 (goto-char (point-min))
1530 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1531 (replace-match "" nil nil
))
1534 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1537 (ignore-errors (delete-file tmp-name
)))
1541 (write-region "foo" nil tmp-name
)
1542 (should (file-exists-p tmp-name
))
1543 (async-shell-command
1544 (format "ls %s" (file-name-nondirectory tmp-name
)) (current-buffer))
1545 (set-process-sentinel (get-buffer-process (current-buffer)) nil
)
1547 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1548 (while (< (- (point-max) (point-min))
1549 (1+ (length (file-name-nondirectory tmp-name
))))
1550 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1551 ;; `ls' could produce colorized output.
1552 (goto-char (point-min))
1553 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1554 (replace-match "" nil nil
))
1555 ;; There might be a nasty "Process *Async Shell* finished" message.
1556 (goto-char (point-min))
1558 (narrow-to-region (point-min) (point))
1561 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1564 (ignore-errors (delete-file tmp-name
)))
1568 (write-region "foo" nil tmp-name
)
1569 (should (file-exists-p tmp-name
))
1570 (async-shell-command "read line; ls $line" (current-buffer))
1571 (set-process-sentinel (get-buffer-process (current-buffer)) nil
)
1572 (process-send-string
1573 (get-buffer-process (current-buffer))
1574 (format "%s\n" (file-name-nondirectory tmp-name
)))
1576 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1577 (while (< (- (point-max) (point-min))
1578 (1+ (length (file-name-nondirectory tmp-name
))))
1579 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1580 ;; `ls' could produce colorized output.
1581 (goto-char (point-min))
1582 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1583 (replace-match "" nil nil
))
1584 ;; There might be a nasty "Process *Async Shell* finished" message.
1585 (goto-char (point-min))
1587 (narrow-to-region (point-min) (point))
1590 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1593 (ignore-errors (delete-file tmp-name
)))))
1595 (ert-deftest tramp-test29-vc-registered
()
1596 "Check `vc-registered'."
1597 (skip-unless (tramp--test-enabled))
1600 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1601 'tramp-sh-file-name-handler
))
1603 (let* ((default-directory tramp-test-temporary-file-directory
)
1604 (tmp-name1 (tramp--test-make-temp-name))
1605 (tmp-name2 (expand-file-name "foo" tmp-name1
))
1606 (tramp-remote-process-environment tramp-remote-process-environment
)
1607 (vc-handled-backends
1608 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1610 ((tramp-find-executable v vc-bzr-program
(tramp-get-remote-path v
))
1611 (setq tramp-remote-process-environment
1612 (cons (format "BZR_HOME=%s"
1613 (file-remote-p tmp-name1
'localname
))
1614 tramp-remote-process-environment
))
1615 ;; We must force a reconnect, in order to activate $BZR_HOME.
1616 (tramp-cleanup-connection
1617 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1620 ((tramp-find-executable v vc-git-program
(tramp-get-remote-path v
))
1622 ((tramp-find-executable v vc-hg-program
(tramp-get-remote-path v
))
1625 (skip-unless vc-handled-backends
)
1626 (message "%s" vc-handled-backends
)
1630 (make-directory tmp-name1
)
1631 (write-region "foo" nil tmp-name2
)
1632 (should (file-directory-p tmp-name1
))
1633 (should (file-exists-p tmp-name2
))
1634 (should-not (vc-registered tmp-name1
))
1635 (should-not (vc-registered tmp-name2
))
1637 (let ((default-directory tmp-name1
))
1638 ;; Create empty repository, and register the file.
1639 (vc-create-repo (car vc-handled-backends
))
1640 ;; The structure of VC-FILESET is not documented. Let's
1641 ;; hope it won't change.
1644 (list (car vc-handled-backends
)
1645 (list (file-name-nondirectory tmp-name2
))))
1646 ;; `vc-register' has changed its arguments in Emacs 25.1.
1649 nil
(list (car vc-handled-backends
)
1650 (list (file-name-nondirectory tmp-name2
)))))))
1651 (should (vc-registered tmp-name2
)))
1654 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
1656 (ert-deftest tramp-test30-make-auto-save-file-name
()
1657 "Check `make-auto-save-file-name'."
1658 (skip-unless (tramp--test-enabled))
1660 (let ((tmp-name1 (tramp--test-make-temp-name))
1661 (tmp-name2 (tramp--test-make-temp-name)))
1665 ;; Use default `auto-save-file-name-transforms' mechanism.
1666 (let (tramp-auto-save-directory)
1668 (setq buffer-file-name tmp-name1
)
1671 (make-auto-save-file-name)
1672 ;; This is taken from original `make-auto-save-file-name'.
1676 (subst-char-in-string
1677 ?
/ ?
! (replace-regexp-in-string "!" "!!" tmp-name1
)))
1678 temporary-file-directory
)))))
1681 (let (tramp-auto-save-directory auto-save-file-name-transforms
)
1683 (setq buffer-file-name tmp-name1
)
1686 (make-auto-save-file-name)
1688 (format "#%s#" (file-name-nondirectory tmp-name1
))
1689 tramp-test-temporary-file-directory
)))))
1691 ;; Use default `tramp-auto-save-directory' mechanism.
1692 (let ((tramp-auto-save-directory tmp-name2
))
1694 (setq buffer-file-name tmp-name1
)
1697 (make-auto-save-file-name)
1698 ;; This is taken from Tramp.
1702 (tramp-subst-strs-in-string
1711 (should (file-directory-p tmp-name2
))))
1713 ;; Relative file names shall work, too.
1714 (let ((tramp-auto-save-directory "."))
1716 (setq buffer-file-name tmp-name1
1717 default-directory tmp-name2
)
1720 (make-auto-save-file-name)
1721 ;; This is taken from Tramp.
1725 (tramp-subst-strs-in-string
1734 (should (file-directory-p tmp-name2
)))))
1737 (ignore-errors (delete-file tmp-name1
))
1738 (ignore-errors (delete-directory tmp-name2
'recursive
)))))
1740 (defun tramp--test-adb-p ()
1741 "Check, whether the remote host runs Android.
1742 This requires restrictions of file name syntax."
1743 (tramp-adb-file-name-p tramp-test-temporary-file-directory
))
1745 (defun tramp--test-ftp-p ()
1746 "Check, whether an FTP-like method is used.
1747 This does not support globbing characters in file names (yet)."
1748 ;; Globbing characters are ??, ?* and ?\[.
1749 (and (eq (tramp-find-foreign-file-name-handler
1750 tramp-test-temporary-file-directory
)
1751 'tramp-sh-file-name-handler
)
1753 "ftp$" (file-remote-p tramp-test-temporary-file-directory
'method
))))
1755 (defun tramp--test-gvfs-p ()
1756 "Check, whether the remote host runs a GVFS based method.
1757 This requires restrictions of file name syntax."
1758 (tramp-gvfs-file-name-p tramp-test-temporary-file-directory
))
1760 (defun tramp--test-smb-or-windows-nt-p ()
1761 "Check, whether the locale or remote host runs MS Windows.
1762 This requires restrictions of file name syntax."
1763 (or (eq system-type
'windows-nt
)
1764 (tramp-smb-file-name-p tramp-test-temporary-file-directory
)))
1766 (defun tramp--test-hpux-p ()
1767 "Check, whether the remote host runs HP-UX.
1768 Several special characters do not work properly there."
1769 ;; We must refill the cache. `file-truename' does it.
1770 (with-parsed-tramp-file-name
1771 (file-truename tramp-test-temporary-file-directory
) nil
1772 (string-match "^HP-UX" (tramp-get-connection-property v
"uname" ""))))
1774 (defun tramp--test-check-files (&rest files
)
1775 "Run a simple but comprehensive test over every file in FILES."
1776 ;; We must use `file-truename' for the temporary directory, because
1777 ;; it could be located on a symlinked directory. This would let the
1779 (let* ((tramp-test-temporary-file-directory
1780 (file-truename tramp-test-temporary-file-directory
))
1781 (tmp-name1 (tramp--test-make-temp-name))
1782 (tmp-name2 (tramp--test-make-temp-name 'local
))
1783 (files (delq nil files
)))
1786 (make-directory tmp-name1
)
1787 (make-directory tmp-name2
)
1789 (let* ((file1 (expand-file-name elt tmp-name1
))
1790 (file2 (expand-file-name elt tmp-name2
))
1791 (file3 (expand-file-name (concat elt
"foo") tmp-name1
)))
1792 (write-region elt nil file1
)
1793 (should (file-exists-p file1
))
1795 ;; Check file contents.
1797 (insert-file-contents file1
)
1798 (should (string-equal (buffer-string) elt
)))
1800 ;; Copy file both directions.
1801 (copy-file file1 tmp-name2
)
1802 (should (file-exists-p file2
))
1804 (should-not (file-exists-p file1
))
1805 (copy-file file2 tmp-name1
)
1806 (should (file-exists-p file1
))
1808 ;; Method "smb" supports `make-symbolic-link' only if the
1809 ;; remote host has CIFS capabilities. tramp-adb.el and
1810 ;; tramp-gvfs.el do not support symbolic links at all.
1813 (make-symbolic-link file1 file3
)
1814 (should (file-symlink-p file3
))
1817 (expand-file-name file1
) (file-truename file3
)))
1820 (car (file-attributes file3
))
1821 (file-remote-p (file-truename file1
) 'localname
)))
1822 ;; Check file contents.
1824 (insert-file-contents file3
)
1825 (should (string-equal (buffer-string) elt
)))
1826 (delete-file file3
))
1828 (should (string-equal (error-message-string err
)
1829 "make-symbolic-link not supported"))))))
1831 ;; Check file names.
1832 (should (equal (directory-files
1833 tmp-name1 nil directory-files-no-dot-files-regexp
)
1834 (sort (copy-sequence files
) 'string-lessp
)))
1835 (should (equal (directory-files
1836 tmp-name2 nil directory-files-no-dot-files-regexp
)
1837 (sort (copy-sequence files
) 'string-lessp
)))
1839 ;; `substitute-in-file-name' could return different values.
1840 ;; For `adb', there could be strange file permissions
1841 ;; preventing overwriting a file. We don't care in this
1845 (substitute-in-file-name (expand-file-name elt tmp-name1
)))
1847 (substitute-in-file-name (expand-file-name elt tmp-name2
))))
1848 (ignore-errors (write-region elt nil file1
))
1849 (should (file-exists-p file1
))
1850 (ignore-errors (write-region elt nil file2 nil
'nomessage
))
1851 (should (file-exists-p file2
))))
1853 (should (equal (directory-files
1854 tmp-name1 nil directory-files-no-dot-files-regexp
)
1856 tmp-name2 nil directory-files-no-dot-files-regexp
)))
1858 ;; Check directory creation. We use a subdirectory "foo"
1859 ;; in order to avoid conflicts with previous file name tests.
1861 (let* ((elt1 (concat elt
"foo"))
1862 (file1 (expand-file-name (concat "foo/" elt
) tmp-name1
))
1863 (file2 (expand-file-name elt file1
))
1864 (file3 (expand-file-name elt1 file1
)))
1865 (make-directory file1
'parents
)
1866 (should (file-directory-p file1
))
1867 (write-region elt nil file2
)
1868 (should (file-exists-p file2
))
1871 (directory-files file1 nil directory-files-no-dot-files-regexp
)
1875 (caar (directory-files-and-attributes
1876 file1 nil directory-files-no-dot-files-regexp
))
1879 ;; Check symlink in `directory-files-and-attributes'.
1882 (make-symbolic-link file2 file3
)
1883 (should (file-symlink-p file3
))
1886 (caar (directory-files-and-attributes
1887 file1 nil
(regexp-quote elt1
)))
1891 (cadr (car (directory-files-and-attributes
1892 file1 nil
(regexp-quote elt1
))))
1893 (file-remote-p (file-truename file2
) 'localname
)))
1895 (should-not (file-exists-p file3
)))
1897 (should (string-equal (error-message-string err
)
1898 "make-symbolic-link not supported"))))
1901 (should-not (file-exists-p file2
))
1902 (delete-directory file1
)
1903 (should-not (file-exists-p file1
)))))
1906 (ignore-errors (delete-directory tmp-name1
'recursive
))
1907 (ignore-errors (delete-directory tmp-name2
'recursive
)))))
1909 (defun tramp--test-special-characters ()
1910 "Perform the test in `tramp-test31-special-characters*'."
1911 ;; Newlines, slashes and backslashes in file names are not
1912 ;; supported. So we don't test. And we don't test the tab
1913 ;; character on Windows or Cygwin, because the backslash is
1914 ;; interpreted as a path separator, preventing "\t" from being
1915 ;; expanded to <TAB>.
1916 (tramp--test-check-files
1917 (if (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1919 (if (or (tramp--test-adb-p) (eq system-type
'cygwin
))
1926 (unless (or (tramp--test-ftp-p)
1927 (tramp--test-gvfs-p)
1928 (tramp--test-smb-or-windows-nt-p))
1930 (unless (or (tramp--test-ftp-p)
1931 (tramp--test-gvfs-p)
1932 (tramp--test-smb-or-windows-nt-p))
1934 (if (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1938 (if (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1941 (if (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1944 (unless (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1947 (unless (or (tramp--test-ftp-p) (tramp--test-gvfs-p)) "[foo]bar[baz]")
1950 ;; These tests are inspired by Bug#17238.
1951 (ert-deftest tramp-test31-special-characters
()
1952 "Check special characters in file names."
1953 (skip-unless (tramp--test-enabled))
1955 (tramp--test-special-characters))
1957 (ert-deftest tramp-test31-special-characters-with-stat
()
1958 "Check special characters in file names.
1959 Use the `stat' command."
1960 (skip-unless (tramp--test-enabled))
1963 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1964 'tramp-sh-file-name-handler
))
1965 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1966 (skip-unless (tramp-get-remote-stat v
)))
1968 (let ((tramp-connection-properties
1970 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
1972 tramp-connection-properties
)))
1973 (tramp--test-special-characters)))
1975 (ert-deftest tramp-test31-special-characters-with-perl
()
1976 "Check special characters in file names.
1977 Use the `perl' command."
1978 (skip-unless (tramp--test-enabled))
1981 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1982 'tramp-sh-file-name-handler
))
1983 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1984 (skip-unless (tramp-get-remote-perl v
)))
1986 (let ((tramp-connection-properties
1988 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
1990 tramp-connection-properties
)))
1991 (tramp--test-special-characters)))
1993 (ert-deftest tramp-test31-special-characters-with-ls
()
1994 "Check special characters in file names.
1995 Use the `ls' command."
1996 (skip-unless (tramp--test-enabled))
1999 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
2000 'tramp-sh-file-name-handler
))
2002 (let ((tramp-connection-properties
2004 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
2006 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
2008 tramp-connection-properties
)))
2009 (tramp--test-special-characters)))
2011 (defun tramp--test-utf8 ()
2012 "Perform the test in `tramp-test32-utf8*'."
2013 (let ((coding-system-for-read 'utf-8
)
2014 (coding-system-for-write 'utf-8
)
2015 (file-name-coding-system 'utf-8
))
2016 (tramp--test-check-files
2017 (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ")
2018 (unless (tramp--test-hpux-p)
2019 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
2021 "Автостопом по гала́ктике")))
2023 (ert-deftest tramp-test32-utf8
()
2024 "Check UTF8 encoding in file names and file contents."
2025 (skip-unless (tramp--test-enabled))
2029 (ert-deftest tramp-test32-utf8-with-stat
()
2030 "Check UTF8 encoding in file names and file contents.
2031 Use the `stat' command."
2032 (skip-unless (tramp--test-enabled))
2035 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
2036 'tramp-sh-file-name-handler
))
2037 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2038 (skip-unless (tramp-get-remote-stat v
)))
2040 (let ((tramp-connection-properties
2042 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
2044 tramp-connection-properties
)))
2045 (tramp--test-utf8)))
2047 (ert-deftest tramp-test32-utf8-with-perl
()
2048 "Check UTF8 encoding in file names and file contents.
2049 Use the `perl' command."
2050 (skip-unless (tramp--test-enabled))
2053 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
2054 'tramp-sh-file-name-handler
))
2055 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2056 (skip-unless (tramp-get-remote-perl v
)))
2058 (let ((tramp-connection-properties
2060 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
2062 tramp-connection-properties
)))
2063 (tramp--test-utf8)))
2065 (ert-deftest tramp-test32-utf8-with-ls
()
2066 "Check UTF8 encoding in file names and file contents.
2067 Use the `ls' command."
2068 (skip-unless (tramp--test-enabled))
2071 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
2072 'tramp-sh-file-name-handler
))
2074 (let ((tramp-connection-properties
2076 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
2078 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory
))
2080 tramp-connection-properties
)))
2081 (tramp--test-utf8)))
2083 ;; This test is inspired by Bug#16928.
2084 (ert-deftest tramp-test33-asynchronous-requests
()
2085 "Check parallel asynchronous requests.
2086 Such requests could arrive from timers, process filters and
2087 process sentinels. They shall not disturb each other."
2088 ;; Mark as failed until bug has been fixed.
2089 :expected-result
:failed
2090 (skip-unless (tramp--test-enabled))
2093 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
2094 'tramp-sh-file-name-handler
))
2096 ;; Keep instrumentation verbosity 0 until Tramp bug is fixed. This
2097 ;; has the side effect, that this test fails instead to abort. Good
2099 (tramp--instrument-test-case 0
2100 (let* ((tmp-name (tramp--test-make-temp-name))
2101 (default-directory tmp-name
)
2102 (remote-file-name-inhibit-cache t
)
2103 timer buffers kill-buffer-query-functions
)
2107 (make-directory tmp-name
)
2109 ;; Setup a timer in order to raise an ordinary command again
2110 ;; and again. `vc-registered' is well suited, because there
2119 (buffer-name (nth (random (length buffers
)) buffers
)))))))
2121 ;; Create temporary buffers. The number of buffers
2122 ;; corresponds to the number of processes; it could be
2123 ;; increased in order to make pressure on Tramp.
2125 (add-to-list 'buffers
(generate-new-buffer "*temp*")))
2127 ;; Open asynchronous processes. Set process sentinel.
2128 (dolist (buf buffers
)
2129 (async-shell-command "read line; touch $line; echo $line" buf
)
2130 (set-process-sentinel
2131 (get-buffer-process buf
)
2132 (lambda (proc _state
)
2133 (delete-file (buffer-name (process-buffer proc
))))))
2135 ;; Send a string. Use a random order of the buffers. Mix
2136 ;; with regular operation.
2137 (let ((buffers (copy-sequence buffers
))
2140 (setq buf
(nth (random (length buffers
)) buffers
))
2141 (process-send-string
2142 (get-buffer-process buf
) (format "'%s'\n" buf
))
2143 (file-attributes (buffer-name buf
))
2144 (setq buffers
(delq buf buffers
))))
2146 ;; Wait until the whole output has been read.
2147 (with-timeout ((* 10 (length buffers
))
2148 (ert-fail "`async-shell-command' timed out"))
2149 (let ((buffers (copy-sequence buffers
))
2152 (setq buf
(nth (random (length buffers
)) buffers
))
2154 (memq (process-status (get-buffer-process buf
))
2156 (accept-process-output (get-buffer-process buf
) 0.1)
2157 (setq buffers
(delq buf buffers
))))))
2160 (dolist (buf buffers
)
2161 (with-current-buffer buf
2163 (string-equal (format "'%s'\n" buf
) (buffer-string)))))
2165 (directory-files tmp-name nil directory-files-no-dot-files-regexp
)))
2168 (ignore-errors (cancel-timer timer
))
2169 (ignore-errors (delete-directory tmp-name
'recursive
))
2170 (dolist (buf buffers
)
2171 (ignore-errors (kill-buffer buf
)))))))
2173 (ert-deftest tramp-test34-recursive-load
()
2174 "Check that Tramp does not fail due to recursive load."
2175 (skip-unless (tramp--test-enabled))
2180 "(expand-file-name %S)"
2181 tramp-test-temporary-file-directory
)
2183 "(let ((default-directory %S)) (expand-file-name %S))"
2184 tramp-test-temporary-file-directory
2185 temporary-file-directory
)))
2189 (shell-command-to-string
2191 "%s -batch -Q -L %s --eval %s"
2192 (expand-file-name invocation-name invocation-directory
)
2193 (mapconcat 'shell-quote-argument load-path
" -L ")
2194 (shell-quote-argument code
)))))))
2196 (ert-deftest tramp-test35-unload
()
2197 "Check that Tramp and its subpackages unload completely.
2198 Since it unloads Tramp, it shall be the last test to run."
2199 ;; Mark as failed until all symbols are unbound.
2200 :expected-result
(if (featurep 'tramp
) :failed
:passed
)
2201 (when (featurep 'tramp
)
2202 (unload-feature 'tramp
'force
)
2203 ;; No Tramp feature must be left.
2204 (should-not (featurep 'tramp
))
2205 (should-not (all-completions "tramp" (delq 'tramp-tests features
)))
2206 ;; `file-name-handler-alist' must be clean.
2207 (should-not (all-completions "tramp" (mapcar 'cdr file-name-handler-alist
)))
2208 ;; There shouldn't be left a bound symbol. We do not regard our
2209 ;; test symbols, and the Tramp unload hooks.
2212 (and (or (boundp x
) (functionp x
))
2213 (string-match "^tramp" (symbol-name x
))
2214 (not (string-match "^tramp--?test" (symbol-name x
)))
2215 (not (string-match "unload-hook$" (symbol-name x
)))
2216 (ert-fail (format "`%s' still bound" x
)))))
2217 ;; There shouldn't be left a hook function containing a Tramp
2218 ;; function. We do not regard the Tramp unload hooks.
2222 (string-match "-hooks?$" (symbol-name x
))
2223 (not (string-match "unload-hook$" (symbol-name x
)))
2224 (consp (symbol-value x
))
2225 (ignore-errors (all-completions "tramp" (symbol-value x
)))
2226 (ert-fail (format "Hook `%s' still contains Tramp function" x
)))))))
2230 ;; * dired-compress-file
2233 ;; * file-ownership-preserved-p
2234 ;; * file-selinux-context
2235 ;; * find-backup-file-name
2237 ;; * set-file-selinux-context
2239 ;; * Work on skipped tests. Make a comment, when it is impossible.
2240 ;; * Fix `tramp-test15-copy-directory' for `smb'. Using tar in a pipe
2241 ;; doesn't work well when an interactive password must be provided.
2242 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
2243 ;; * Fix Bug#16928. Set expected error of `tramp-test33-asynchronous-requests'.
2244 ;; * Fix `tramp-test35-unload' (Not all symbols are unbound). Set
2247 (defun tramp-test-all (&optional interactive
)
2248 "Run all tests for \\[tramp]."
2251 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
) "^tramp"))
2253 (provide 'tramp-tests
)
2254 ;;; tramp-tests.el ends here