Merge from emacs-24; up to 2014-04-22T20:19:17Z!eggert@cs.ucla.edu
[bpt/emacs.git] / test / automated / tramp-tests.el
1 ;;; tramp-tests.el --- Tests of remote file access
2
3 ;; Copyright (C) 2013-2014 Free Software Foundation, Inc.
4
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6
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.
11 ;;
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.
16 ;;
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/'.
19
20 ;;; Commentary:
21
22 ;; The tests require a recent ert.el from Emacs 24.4.
23
24 ;; Some of the tests require access to a remote host files. Set
25 ;; $REMOTE_TEMPORARY_FILE_DIRECTORY to a suitable value in order
26 ;; to overwrite the default value. If you want to skip tests
27 ;; accessing a remote host, set this environment variable to
28 ;; "/dev/null" or whatever is appropriate on your system.
29
30 ;; When running the tests in batch mode, it must NOT require an
31 ;; interactive password prompt unless the environment variable
32 ;; $REMOTE_ALLOW_PASSWORD is set.
33
34 ;; A whole test run can be performed calling the command `tramp-test-all'.
35
36 ;;; Code:
37
38 (require 'ert)
39 (require 'tramp)
40 (require 'vc)
41 (require 'vc-bzr)
42 (require 'vc-git)
43 (require 'vc-hg)
44
45 (declare-function tramp-find-executable "tramp-sh")
46 (declare-function tramp-get-remote-path "tramp-sh")
47 (defvar tramp-copy-size-limit)
48
49 ;; There is no default value on w32 systems, which could work out of the box.
50 (defconst tramp-test-temporary-file-directory
51 (cond
52 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
53 ((eq system-type 'windows-nt) null-device)
54 (t (format "/ssh::%s" temporary-file-directory)))
55 "Temporary directory for Tramp tests.")
56
57 (setq password-cache-expiry nil
58 tramp-verbose 0
59 tramp-copy-size-limit nil
60 tramp-message-show-message nil)
61
62 ;; Disable interactive passwords in batch mode.
63 (when (and noninteractive (not (getenv "REMOTE_ALLOW_PASSWORD")))
64 (defalias 'tramp-read-passwd 'ignore))
65
66 ;; This shall happen on hydra only.
67 (when (getenv "NIX_STORE")
68 (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
69
70 (defvar tramp--test-enabled-checked nil
71 "Cached result of `tramp--test-enabled'.
72 If the function did run, the value is a cons cell, the `cdr'
73 being the result.")
74
75 (defun tramp--test-enabled ()
76 "Whether remote file access is enabled."
77 (unless (consp tramp--test-enabled-checked)
78 (setq
79 tramp--test-enabled-checked
80 (cons
81 t (ignore-errors
82 (and
83 (file-remote-p tramp-test-temporary-file-directory)
84 (file-directory-p tramp-test-temporary-file-directory)
85 (file-writable-p tramp-test-temporary-file-directory))))))
86
87 (when (cdr tramp--test-enabled-checked)
88 ;; Cleanup connection.
89 (tramp-cleanup-connection
90 (tramp-dissect-file-name tramp-test-temporary-file-directory)
91 nil 'keep-password))
92
93 ;; Return result.
94 (cdr tramp--test-enabled-checked))
95
96 (defun tramp--test-make-temp-name (&optional local)
97 "Create a temporary file name for test."
98 (expand-file-name
99 (make-temp-name "tramp-test")
100 (if local temporary-file-directory tramp-test-temporary-file-directory)))
101
102 (defmacro tramp--instrument-test-case (verbose &rest body)
103 "Run BODY with `tramp-verbose' equal VERBOSE.
104 Print the the content of the Tramp debug buffer, if BODY does not
105 eval properly in `should', `should-not' or `should-error'."
106 (declare (indent 1) (debug (natnump body)))
107 `(let ((tramp-verbose ,verbose)
108 (tramp-message-show-message t)
109 (tramp-debug-on-error t))
110 (condition-case err
111 ;; In general, we cannot use a timeout here: this would
112 ;; prevent traces when the test runs into an error.
113 ; (with-timeout (10 (ert-fail "`tramp--instrument-test-case' timed out"))
114 (progn
115 ,@body)
116 (ert-test-skipped
117 (signal (car err) (cdr err)))
118 ((error quit)
119 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
120 (with-current-buffer (tramp-get-connection-buffer v)
121 (message "%s" (buffer-string)))
122 (with-current-buffer (tramp-get-debug-buffer v)
123 (message "%s" (buffer-string))))
124 (message "%s" err)
125 (signal (car err) (cdr err))))))
126
127 (ert-deftest tramp-test00-availability ()
128 "Test availability of Tramp functions."
129 :expected-result (if (tramp--test-enabled) :passed :failed)
130 (should (ignore-errors
131 (and
132 (file-remote-p tramp-test-temporary-file-directory)
133 (file-directory-p tramp-test-temporary-file-directory)
134 (file-writable-p tramp-test-temporary-file-directory)))))
135
136 (ert-deftest tramp-test01-file-name-syntax ()
137 "Check remote file name syntax."
138 ;; Simple cases.
139 (should (tramp-tramp-file-p "/method::"))
140 (should (tramp-tramp-file-p "/host:"))
141 (should (tramp-tramp-file-p "/user@:"))
142 (should (tramp-tramp-file-p "/user@host:"))
143 (should (tramp-tramp-file-p "/method:host:"))
144 (should (tramp-tramp-file-p "/method:user@:"))
145 (should (tramp-tramp-file-p "/method:user@host:"))
146 (should (tramp-tramp-file-p "/method:user@email@host:"))
147
148 ;; Using a port.
149 (should (tramp-tramp-file-p "/host#1234:"))
150 (should (tramp-tramp-file-p "/user@host#1234:"))
151 (should (tramp-tramp-file-p "/method:host#1234:"))
152 (should (tramp-tramp-file-p "/method:user@host#1234:"))
153
154 ;; Using an IPv4 address.
155 (should (tramp-tramp-file-p "/1.2.3.4:"))
156 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
157 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
158 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
159
160 ;; Using an IPv6 address.
161 (should (tramp-tramp-file-p "/[]:"))
162 (should (tramp-tramp-file-p "/[::1]:"))
163 (should (tramp-tramp-file-p "/user@[::1]:"))
164 (should (tramp-tramp-file-p "/method:[::1]:"))
165 (should (tramp-tramp-file-p "/method:user@[::1]:"))
166
167 ;; Local file name part.
168 (should (tramp-tramp-file-p "/host:/:"))
169 (should (tramp-tramp-file-p "/method:::"))
170 (should (tramp-tramp-file-p "/method::/path/to/file"))
171 (should (tramp-tramp-file-p "/method::file"))
172
173 ;; Multihop.
174 (should (tramp-tramp-file-p "/method1:|method2::"))
175 (should (tramp-tramp-file-p "/method1:host1|host2:"))
176 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
177 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
178 (should (tramp-tramp-file-p
179 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
180
181 ;; No strings.
182 (should-not (tramp-tramp-file-p nil))
183 (should-not (tramp-tramp-file-p 'symbol))
184 ;; "/:" suppresses file name handlers.
185 (should-not (tramp-tramp-file-p "/::"))
186 (should-not (tramp-tramp-file-p "/:@:"))
187 (should-not (tramp-tramp-file-p "/:[]:"))
188 ;; Multihops require a method.
189 (should-not (tramp-tramp-file-p "/host1|host2:"))
190 ;; Methods or hostnames shall be at least two characters on MS Windows.
191 (when (memq system-type '(cygwin windows-nt))
192 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
193 (should-not (tramp-tramp-file-p "/c::/path/to/file"))))
194
195 (ert-deftest tramp-test02-file-name-dissect ()
196 "Check remote file name components."
197 (let ((tramp-default-method "default-method")
198 (tramp-default-user "default-user")
199 (tramp-default-host "default-host"))
200 ;; Expand `tramp-default-user' and `tramp-default-host'.
201 (should (string-equal
202 (file-remote-p "/method::")
203 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
204 (should (string-equal (file-remote-p "/method::" 'method) "method"))
205 (should (string-equal (file-remote-p "/method::" 'user) "default-user"))
206 (should (string-equal (file-remote-p "/method::" 'host) "default-host"))
207 (should (string-equal (file-remote-p "/method::" 'localname) ""))
208
209 ;; Expand `tramp-default-method' and `tramp-default-user'.
210 (should (string-equal
211 (file-remote-p "/host:")
212 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
213 (should (string-equal (file-remote-p "/host:" 'method) "default-method"))
214 (should (string-equal (file-remote-p "/host:" 'user) "default-user"))
215 (should (string-equal (file-remote-p "/host:" 'host) "host"))
216 (should (string-equal (file-remote-p "/host:" 'localname) ""))
217
218 ;; Expand `tramp-default-method' and `tramp-default-host'.
219 (should (string-equal
220 (file-remote-p "/user@:")
221 (format "/%s:%s@%s:" "default-method""user" "default-host")))
222 (should (string-equal (file-remote-p "/user@:" 'method) "default-method"))
223 (should (string-equal (file-remote-p "/user@:" 'user) "user"))
224 (should (string-equal (file-remote-p "/user@:" 'host) "default-host"))
225 (should (string-equal (file-remote-p "/user@:" 'localname) ""))
226
227 ;; Expand `tramp-default-method'.
228 (should (string-equal
229 (file-remote-p "/user@host:")
230 (format "/%s:%s@%s:" "default-method" "user" "host")))
231 (should (string-equal
232 (file-remote-p "/user@host:" 'method) "default-method"))
233 (should (string-equal (file-remote-p "/user@host:" 'user) "user"))
234 (should (string-equal (file-remote-p "/user@host:" 'host) "host"))
235 (should (string-equal (file-remote-p "/user@host:" 'localname) ""))
236
237 ;; Expand `tramp-default-user'.
238 (should (string-equal
239 (file-remote-p "/method:host:")
240 (format "/%s:%s@%s:" "method" "default-user" "host")))
241 (should (string-equal (file-remote-p "/method:host:" 'method) "method"))
242 (should (string-equal (file-remote-p "/method:host:" 'user) "default-user"))
243 (should (string-equal (file-remote-p "/method:host:" 'host) "host"))
244 (should (string-equal (file-remote-p "/method:host:" 'localname) ""))
245
246 ;; Expand `tramp-default-host'.
247 (should (string-equal
248 (file-remote-p "/method:user@:")
249 (format "/%s:%s@%s:" "method" "user" "default-host")))
250 (should (string-equal (file-remote-p "/method:user@:" 'method) "method"))
251 (should (string-equal (file-remote-p "/method:user@:" 'user) "user"))
252 (should (string-equal (file-remote-p "/method:user@:" 'host)
253 "default-host"))
254 (should (string-equal (file-remote-p "/method:user@:" 'localname) ""))
255
256 ;; No expansion.
257 (should (string-equal
258 (file-remote-p "/method:user@host:")
259 (format "/%s:%s@%s:" "method" "user" "host")))
260 (should (string-equal
261 (file-remote-p "/method:user@host:" 'method) "method"))
262 (should (string-equal (file-remote-p "/method:user@host:" 'user) "user"))
263 (should (string-equal (file-remote-p "/method:user@host:" 'host) "host"))
264 (should (string-equal (file-remote-p "/method:user@host:" 'localname) ""))
265
266 ;; No expansion.
267 (should (string-equal
268 (file-remote-p "/method:user@email@host:")
269 (format "/%s:%s@%s:" "method" "user@email" "host")))
270 (should (string-equal
271 (file-remote-p "/method:user@email@host:" 'method) "method"))
272 (should (string-equal
273 (file-remote-p "/method:user@email@host:" 'user) "user@email"))
274 (should (string-equal
275 (file-remote-p "/method:user@email@host:" 'host) "host"))
276 (should (string-equal
277 (file-remote-p "/method:user@email@host:" 'localname) ""))
278
279 ;; Expand `tramp-default-method' and `tramp-default-user'.
280 (should (string-equal
281 (file-remote-p "/host#1234:")
282 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
283 (should (string-equal
284 (file-remote-p "/host#1234:" 'method) "default-method"))
285 (should (string-equal (file-remote-p "/host#1234:" 'user) "default-user"))
286 (should (string-equal (file-remote-p "/host#1234:" 'host) "host#1234"))
287 (should (string-equal (file-remote-p "/host#1234:" 'localname) ""))
288
289 ;; Expand `tramp-default-method'.
290 (should (string-equal
291 (file-remote-p "/user@host#1234:")
292 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
293 (should (string-equal
294 (file-remote-p "/user@host#1234:" 'method) "default-method"))
295 (should (string-equal (file-remote-p "/user@host#1234:" 'user) "user"))
296 (should (string-equal (file-remote-p "/user@host#1234:" 'host) "host#1234"))
297 (should (string-equal (file-remote-p "/user@host#1234:" 'localname) ""))
298
299 ;; Expand `tramp-default-user'.
300 (should (string-equal
301 (file-remote-p "/method:host#1234:")
302 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
303 (should (string-equal
304 (file-remote-p "/method:host#1234:" 'method) "method"))
305 (should (string-equal
306 (file-remote-p "/method:host#1234:" 'user) "default-user"))
307 (should (string-equal
308 (file-remote-p "/method:host#1234:" 'host) "host#1234"))
309 (should (string-equal (file-remote-p "/method:host#1234:" 'localname) ""))
310
311 ;; No expansion.
312 (should (string-equal
313 (file-remote-p "/method:user@host#1234:")
314 (format "/%s:%s@%s:" "method" "user" "host#1234")))
315 (should (string-equal
316 (file-remote-p "/method:user@host#1234:" 'method) "method"))
317 (should (string-equal
318 (file-remote-p "/method:user@host#1234:" 'user) "user"))
319 (should (string-equal
320 (file-remote-p "/method:user@host#1234:" 'host) "host#1234"))
321 (should (string-equal
322 (file-remote-p "/method:user@host#1234:" 'localname) ""))
323
324 ;; Expand `tramp-default-method' and `tramp-default-user'.
325 (should (string-equal
326 (file-remote-p "/1.2.3.4:")
327 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
328 (should (string-equal (file-remote-p "/1.2.3.4:" 'method) "default-method"))
329 (should (string-equal (file-remote-p "/1.2.3.4:" 'user) "default-user"))
330 (should (string-equal (file-remote-p "/1.2.3.4:" 'host) "1.2.3.4"))
331 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname) ""))
332
333 ;; Expand `tramp-default-method'.
334 (should (string-equal
335 (file-remote-p "/user@1.2.3.4:")
336 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
337 (should (string-equal
338 (file-remote-p "/user@1.2.3.4:" 'method) "default-method"))
339 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user) "user"))
340 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'host) "1.2.3.4"))
341 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname) ""))
342
343 ;; Expand `tramp-default-user'.
344 (should (string-equal
345 (file-remote-p "/method:1.2.3.4:")
346 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
347 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method) "method"))
348 (should (string-equal
349 (file-remote-p "/method:1.2.3.4:" 'user) "default-user"))
350 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host) "1.2.3.4"))
351 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname) ""))
352
353 ;; No expansion.
354 (should (string-equal
355 (file-remote-p "/method:user@1.2.3.4:")
356 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
357 (should (string-equal
358 (file-remote-p "/method:user@1.2.3.4:" 'method) "method"))
359 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user) "user"))
360 (should (string-equal
361 (file-remote-p "/method:user@1.2.3.4:" 'host) "1.2.3.4"))
362 (should (string-equal
363 (file-remote-p "/method:user@1.2.3.4:" 'localname) ""))
364
365 ;; Expand `tramp-default-method', `tramp-default-user' and
366 ;; `tramp-default-host'.
367 (should (string-equal
368 (file-remote-p "/[]:")
369 (format
370 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
371 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
372 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
373 (should (string-equal (file-remote-p "/[]:" 'host) "default-host"))
374 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
375
376 ;; Expand `tramp-default-method' and `tramp-default-user'.
377 (let ((tramp-default-host "::1"))
378 (should (string-equal
379 (file-remote-p "/[]:")
380 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
381 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
382 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
383 (should (string-equal (file-remote-p "/[]:" 'host) "::1"))
384 (should (string-equal (file-remote-p "/[]:" 'localname) "")))
385
386 ;; Expand `tramp-default-method' and `tramp-default-user'.
387 (should (string-equal
388 (file-remote-p "/[::1]:")
389 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
390 (should (string-equal (file-remote-p "/[::1]:" 'method) "default-method"))
391 (should (string-equal (file-remote-p "/[::1]:" 'user) "default-user"))
392 (should (string-equal (file-remote-p "/[::1]:" 'host) "::1"))
393 (should (string-equal (file-remote-p "/[::1]:" 'localname) ""))
394
395 ;; Expand `tramp-default-method'.
396 (should (string-equal
397 (file-remote-p "/user@[::1]:")
398 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
399 (should (string-equal
400 (file-remote-p "/user@[::1]:" 'method) "default-method"))
401 (should (string-equal (file-remote-p "/user@[::1]:" 'user) "user"))
402 (should (string-equal (file-remote-p "/user@[::1]:" 'host) "::1"))
403 (should (string-equal (file-remote-p "/user@[::1]:" 'localname) ""))
404
405 ;; Expand `tramp-default-user'.
406 (should (string-equal
407 (file-remote-p "/method:[::1]:")
408 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
409 (should (string-equal (file-remote-p "/method:[::1]:" 'method) "method"))
410 (should (string-equal
411 (file-remote-p "/method:[::1]:" 'user) "default-user"))
412 (should (string-equal (file-remote-p "/method:[::1]:" 'host) "::1"))
413 (should (string-equal (file-remote-p "/method:[::1]:" 'localname) ""))
414
415 ;; No expansion.
416 (should (string-equal
417 (file-remote-p "/method:user@[::1]:")
418 (format "/%s:%s@%s:" "method" "user" "[::1]")))
419 (should (string-equal
420 (file-remote-p "/method:user@[::1]:" 'method) "method"))
421 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user) "user"))
422 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host) "::1"))
423 (should (string-equal
424 (file-remote-p "/method:user@[::1]:" 'localname) ""))
425
426 ;; Local file name part.
427 (should (string-equal (file-remote-p "/host:/:" 'localname) "/:"))
428 (should (string-equal (file-remote-p "/method:::" 'localname) ":"))
429 (should (string-equal (file-remote-p "/method:: " 'localname) " "))
430 (should (string-equal (file-remote-p "/method::file" 'localname) "file"))
431 (should (string-equal
432 (file-remote-p "/method::/path/to/file" 'localname)
433 "/path/to/file"))
434
435 ;; Multihop.
436 (should
437 (string-equal
438 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
439 (format "/%s:%s@%s:" "method2" "user2" "host2")))
440 (should
441 (string-equal
442 (file-remote-p
443 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method)
444 "method2"))
445 (should
446 (string-equal
447 (file-remote-p
448 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user)
449 "user2"))
450 (should
451 (string-equal
452 (file-remote-p
453 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host)
454 "host2"))
455 (should
456 (string-equal
457 (file-remote-p
458 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname)
459 "/path/to/file"))
460
461 (should
462 (string-equal
463 (file-remote-p
464 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
465 (format "/%s:%s@%s:" "method3" "user3" "host3")))
466 (should
467 (string-equal
468 (file-remote-p
469 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
470 'method)
471 "method3"))
472 (should
473 (string-equal
474 (file-remote-p
475 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
476 'user)
477 "user3"))
478 (should
479 (string-equal
480 (file-remote-p
481 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
482 'host)
483 "host3"))
484 (should
485 (string-equal
486 (file-remote-p
487 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
488 'localname)
489 "/path/to/file"))))
490
491 (ert-deftest tramp-test03-file-name-defaults ()
492 "Check default values for some methods."
493 ;; Default values in tramp-adb.el.
494 (should (string-equal (file-remote-p "/adb::" 'host) ""))
495 ;; Default values in tramp-ftp.el.
496 (should (string-equal (file-remote-p "/ftp.host:" 'method) "ftp"))
497 (dolist (u '("ftp" "anonymous"))
498 (should (string-equal (file-remote-p (format "/%s@:" u) 'method) "ftp")))
499 ;; Default values in tramp-gvfs.el.
500 (when (and (load "tramp-gvfs" 'noerror 'nomessage)
501 (symbol-value 'tramp-gvfs-enabled))
502 (should (string-equal (file-remote-p "/synce::" 'user) nil)))
503 ;; Default values in tramp-gw.el.
504 (dolist (m '("tunnel" "socks"))
505 (should
506 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
507 ;; Default values in tramp-sh.el.
508 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
509 (should (string-equal (file-remote-p (format "/root@%s:" h) 'method) "su")))
510 (dolist (m '("su" "sudo" "ksu"))
511 (should (string-equal (file-remote-p (format "/%s::" m) 'user) "root")))
512 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
513 (should
514 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
515 ;; Default values in tramp-smb.el.
516 (should (string-equal (file-remote-p "/user%domain@host:" 'method) "smb"))
517 (should (string-equal (file-remote-p "/smb::" 'user) nil)))
518
519 (ert-deftest tramp-test04-substitute-in-file-name ()
520 "Check `substitute-in-file-name'."
521 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
522 (should
523 (string-equal
524 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
525 (should
526 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
527 (should
528 (string-equal
529 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
530 (should
531 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
532 (let (process-environment)
533 (should
534 (string-equal
535 (substitute-in-file-name "/method:host:/path/$FOO")
536 "/method:host:/path/$FOO"))
537 (setenv "FOO" "bla")
538 (should
539 (string-equal
540 (substitute-in-file-name "/method:host:/path/$FOO")
541 "/method:host:/path/bla"))
542 (should
543 (string-equal
544 (substitute-in-file-name "/method:host:/path/$$FOO")
545 "/method:host:/path/$FOO"))))
546
547 (ert-deftest tramp-test05-expand-file-name ()
548 "Check `expand-file-name'."
549 (should
550 (string-equal
551 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
552 (should
553 (string-equal
554 (expand-file-name "/method:host:/path/../file") "/method:host:/file")))
555
556 (ert-deftest tramp-test06-directory-file-name ()
557 "Check `directory-file-name'.
558 This checks also `file-name-as-directory', `file-name-directory'
559 and `file-name-nondirectory'."
560 (should
561 (string-equal
562 (directory-file-name "/method:host:/path/to/file")
563 "/method:host:/path/to/file"))
564 (should
565 (string-equal
566 (directory-file-name "/method:host:/path/to/file/")
567 "/method:host:/path/to/file"))
568 (should
569 (string-equal
570 (file-name-as-directory "/method:host:/path/to/file")
571 "/method:host:/path/to/file/"))
572 (should
573 (string-equal
574 (file-name-as-directory "/method:host:/path/to/file/")
575 "/method:host:/path/to/file/"))
576 (should
577 (string-equal
578 (file-name-directory "/method:host:/path/to/file")
579 "/method:host:/path/to/"))
580 (should
581 (string-equal
582 (file-name-directory "/method:host:/path/to/file/")
583 "/method:host:/path/to/file/"))
584 (should
585 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
586 (should
587 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
588 (should-not
589 (file-remote-p
590 (unhandled-file-name-directory "/method:host:/path/to/file"))))
591
592 (ert-deftest tramp-test07-file-exists-p ()
593 "Check `file-exist-p', `write-region' and `delete-file'."
594 (skip-unless (tramp--test-enabled))
595
596 (let ((tmp-name (tramp--test-make-temp-name)))
597 (should-not (file-exists-p tmp-name))
598 (write-region "foo" nil tmp-name)
599 (should (file-exists-p tmp-name))
600 (delete-file tmp-name)
601 (should-not (file-exists-p tmp-name))))
602
603 (ert-deftest tramp-test08-file-local-copy ()
604 "Check `file-local-copy'."
605 (skip-unless (tramp--test-enabled))
606
607 (let ((tmp-name1 (tramp--test-make-temp-name))
608 tmp-name2)
609 (unwind-protect
610 (progn
611 (write-region "foo" nil tmp-name1)
612 (should (setq tmp-name2 (file-local-copy tmp-name1)))
613 (with-temp-buffer
614 (insert-file-contents tmp-name2)
615 (should (string-equal (buffer-string) "foo"))))
616 (ignore-errors
617 (delete-file tmp-name1)
618 (delete-file tmp-name2)))))
619
620 (ert-deftest tramp-test09-insert-file-contents ()
621 "Check `insert-file-contents'."
622 (skip-unless (tramp--test-enabled))
623
624 (let ((tmp-name (tramp--test-make-temp-name)))
625 (unwind-protect
626 (progn
627 (write-region "foo" nil tmp-name)
628 (with-temp-buffer
629 (insert-file-contents tmp-name)
630 (should (string-equal (buffer-string) "foo"))
631 (insert-file-contents tmp-name)
632 (should (string-equal (buffer-string) "foofoo"))
633 ;; Insert partly.
634 (insert-file-contents tmp-name nil 1 3)
635 (should (string-equal (buffer-string) "oofoofoo"))
636 ;; Replace.
637 (insert-file-contents tmp-name nil nil nil 'replace)
638 (should (string-equal (buffer-string) "foo"))))
639 (ignore-errors (delete-file tmp-name)))))
640
641 (ert-deftest tramp-test10-write-region ()
642 "Check `write-region'."
643 (skip-unless (tramp--test-enabled))
644
645 (let ((tmp-name (tramp--test-make-temp-name)))
646 (unwind-protect
647 (progn
648 (with-temp-buffer
649 (insert "foo")
650 (write-region nil nil tmp-name))
651 (with-temp-buffer
652 (insert-file-contents tmp-name)
653 (should (string-equal (buffer-string) "foo")))
654 ;; Append.
655 (with-temp-buffer
656 (insert "bla")
657 (write-region nil nil tmp-name 'append))
658 (with-temp-buffer
659 (insert-file-contents tmp-name)
660 (should (string-equal (buffer-string) "foobla")))
661 ;; Write string.
662 (write-region "foo" nil tmp-name)
663 (with-temp-buffer
664 (insert-file-contents tmp-name)
665 (should (string-equal (buffer-string) "foo")))
666 ;; Write partly.
667 (with-temp-buffer
668 (insert "123456789")
669 (write-region 3 5 tmp-name))
670 (with-temp-buffer
671 (insert-file-contents tmp-name)
672 (should (string-equal (buffer-string) "34"))))
673 (ignore-errors (delete-file tmp-name)))))
674
675 (ert-deftest tramp-test11-copy-file ()
676 "Check `copy-file'."
677 (skip-unless (tramp--test-enabled))
678
679 (let ((tmp-name1 (tramp--test-make-temp-name))
680 (tmp-name2 (tramp--test-make-temp-name))
681 (tmp-name3 (tramp--test-make-temp-name))
682 (tmp-name4 (tramp--test-make-temp-name 'local))
683 (tmp-name5 (tramp--test-make-temp-name 'local)))
684
685 ;; Copy on remote side.
686 (unwind-protect
687 (progn
688 (write-region "foo" nil tmp-name1)
689 (copy-file tmp-name1 tmp-name2)
690 (should (file-exists-p tmp-name2))
691 (with-temp-buffer
692 (insert-file-contents tmp-name2)
693 (should (string-equal (buffer-string) "foo")))
694 (should-error (copy-file tmp-name1 tmp-name2))
695 (copy-file tmp-name1 tmp-name2 'ok)
696 (make-directory tmp-name3)
697 (copy-file tmp-name1 tmp-name3)
698 (should
699 (file-exists-p
700 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name3))))
701 (ignore-errors (delete-file tmp-name1))
702 (ignore-errors (delete-file tmp-name2))
703 (ignore-errors (delete-directory tmp-name3 'recursive)))
704
705 ;; Copy from remote side to local side.
706 (unwind-protect
707 (progn
708 (write-region "foo" nil tmp-name1)
709 (copy-file tmp-name1 tmp-name4)
710 (should (file-exists-p tmp-name4))
711 (with-temp-buffer
712 (insert-file-contents tmp-name4)
713 (should (string-equal (buffer-string) "foo")))
714 (should-error (copy-file tmp-name1 tmp-name4))
715 (copy-file tmp-name1 tmp-name4 'ok)
716 (make-directory tmp-name5)
717 (copy-file tmp-name1 tmp-name5)
718 (should
719 (file-exists-p
720 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name5))))
721 (ignore-errors (delete-file tmp-name1))
722 (ignore-errors (delete-file tmp-name4))
723 (ignore-errors (delete-directory tmp-name5 'recursive)))
724
725 ;; Copy from local side to remote side.
726 (unwind-protect
727 (progn
728 (write-region "foo" nil tmp-name4 nil 'nomessage)
729 (copy-file tmp-name4 tmp-name1)
730 (should (file-exists-p tmp-name1))
731 (with-temp-buffer
732 (insert-file-contents tmp-name1)
733 (should (string-equal (buffer-string) "foo")))
734 (should-error (copy-file tmp-name4 tmp-name1))
735 (copy-file tmp-name4 tmp-name1 'ok)
736 (make-directory tmp-name3)
737 (copy-file tmp-name4 tmp-name3)
738 (should
739 (file-exists-p
740 (expand-file-name (file-name-nondirectory tmp-name4) tmp-name3))))
741 (ignore-errors (delete-file tmp-name1))
742 (ignore-errors (delete-file tmp-name4))
743 (ignore-errors (delete-directory tmp-name3 'recursive)))))
744
745 (ert-deftest tramp-test12-rename-file ()
746 "Check `rename-file'."
747 (skip-unless (tramp--test-enabled))
748
749 (let ((tmp-name1 (tramp--test-make-temp-name))
750 (tmp-name2 (tramp--test-make-temp-name))
751 (tmp-name3 (tramp--test-make-temp-name))
752 (tmp-name4 (tramp--test-make-temp-name 'local))
753 (tmp-name5 (tramp--test-make-temp-name 'local)))
754
755 ;; Rename on remote side.
756 (unwind-protect
757 (progn
758 (write-region "foo" nil tmp-name1)
759 (rename-file tmp-name1 tmp-name2)
760 (should-not (file-exists-p tmp-name1))
761 (should (file-exists-p tmp-name2))
762 (with-temp-buffer
763 (insert-file-contents tmp-name2)
764 (should (string-equal (buffer-string) "foo")))
765 (write-region "foo" nil tmp-name1)
766 (should-error (rename-file tmp-name1 tmp-name2))
767 (rename-file tmp-name1 tmp-name2 'ok)
768 (should-not (file-exists-p tmp-name1))
769 (write-region "foo" nil tmp-name1)
770 (make-directory tmp-name3)
771 (rename-file tmp-name1 tmp-name3)
772 (should-not (file-exists-p tmp-name1))
773 (should
774 (file-exists-p
775 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name3))))
776 (ignore-errors (delete-file tmp-name1))
777 (ignore-errors (delete-file tmp-name2))
778 (ignore-errors (delete-directory tmp-name3 'recursive)))
779
780 ;; Rename from remote side to local side.
781 (unwind-protect
782 (progn
783 (write-region "foo" nil tmp-name1)
784 (rename-file tmp-name1 tmp-name4)
785 (should-not (file-exists-p tmp-name1))
786 (should (file-exists-p tmp-name4))
787 (with-temp-buffer
788 (insert-file-contents tmp-name4)
789 (should (string-equal (buffer-string) "foo")))
790 (write-region "foo" nil tmp-name1)
791 (should-error (rename-file tmp-name1 tmp-name4))
792 (rename-file tmp-name1 tmp-name4 'ok)
793 (should-not (file-exists-p tmp-name1))
794 (write-region "foo" nil tmp-name1)
795 (make-directory tmp-name5)
796 (rename-file tmp-name1 tmp-name5)
797 (should-not (file-exists-p tmp-name1))
798 (should
799 (file-exists-p
800 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name5))))
801 (ignore-errors (delete-file tmp-name1))
802 (ignore-errors (delete-file tmp-name4))
803 (ignore-errors (delete-directory tmp-name5 'recursive)))
804
805 ;; Rename from local side to remote side.
806 (unwind-protect
807 (progn
808 (write-region "foo" nil tmp-name4 nil 'nomessage)
809 (rename-file tmp-name4 tmp-name1)
810 (should-not (file-exists-p tmp-name4))
811 (should (file-exists-p tmp-name1))
812 (with-temp-buffer
813 (insert-file-contents tmp-name1)
814 (should (string-equal (buffer-string) "foo")))
815 (write-region "foo" nil tmp-name4 nil 'nomessage)
816 (should-error (rename-file tmp-name4 tmp-name1))
817 (rename-file tmp-name4 tmp-name1 'ok)
818 (should-not (file-exists-p tmp-name4))
819 (write-region "foo" nil tmp-name4 nil 'nomessage)
820 (make-directory tmp-name3)
821 (rename-file tmp-name4 tmp-name3)
822 (should-not (file-exists-p tmp-name4))
823 (should
824 (file-exists-p
825 (expand-file-name (file-name-nondirectory tmp-name4) tmp-name3))))
826 (ignore-errors (delete-file tmp-name1))
827 (ignore-errors (delete-file tmp-name4))
828 (ignore-errors (delete-directory tmp-name3 'recursive)))))
829
830 (ert-deftest tramp-test13-make-directory ()
831 "Check `make-directory'.
832 This tests also `file-directory-p' and `file-accessible-directory-p'."
833 (skip-unless (tramp--test-enabled))
834
835 (let ((tmp-name (tramp--test-make-temp-name)))
836 (unwind-protect
837 (progn
838 (make-directory tmp-name)
839 (should (file-directory-p tmp-name))
840 (should (file-accessible-directory-p tmp-name)))
841 (ignore-errors (delete-directory tmp-name)))))
842
843 (ert-deftest tramp-test14-delete-directory ()
844 "Check `delete-directory'."
845 (skip-unless (tramp--test-enabled))
846
847 (let ((tmp-name (tramp--test-make-temp-name)))
848 ;; Delete empty directory.
849 (make-directory tmp-name)
850 (should (file-directory-p tmp-name))
851 (delete-directory tmp-name)
852 (should-not (file-directory-p tmp-name))
853 ;; Delete non-empty directory.
854 (make-directory tmp-name)
855 (write-region "foo" nil (expand-file-name "bla" tmp-name))
856 (should-error (delete-directory tmp-name) :type 'file-error)
857 (delete-directory tmp-name 'recursive)
858 (should-not (file-directory-p tmp-name))))
859
860 (ert-deftest tramp-test15-copy-directory ()
861 "Check `copy-directory'."
862 (skip-unless (tramp--test-enabled))
863
864 (let* ((tmp-name1 (tramp--test-make-temp-name))
865 (tmp-name2 (tramp--test-make-temp-name))
866 (tmp-name3 (expand-file-name
867 (file-name-nondirectory tmp-name1) tmp-name2))
868 (tmp-name4 (expand-file-name "foo" tmp-name1))
869 (tmp-name5 (expand-file-name "foo" tmp-name2))
870 (tmp-name6 (expand-file-name "foo" tmp-name3)))
871 (unwind-protect
872 (progn
873 ;; Copy empty directory.
874 (make-directory tmp-name1)
875 (write-region "foo" nil tmp-name4)
876 (should (file-directory-p tmp-name1))
877 (should (file-exists-p tmp-name4))
878 (copy-directory tmp-name1 tmp-name2)
879 (should (file-directory-p tmp-name2))
880 (should (file-exists-p tmp-name5))
881 ;; Target directory does exist already.
882 (copy-directory tmp-name1 tmp-name2)
883 (should (file-directory-p tmp-name3))
884 (should (file-exists-p tmp-name6)))
885 (ignore-errors
886 (delete-directory tmp-name1 'recursive)
887 (delete-directory tmp-name2 'recursive)))))
888
889 (ert-deftest tramp-test16-directory-files ()
890 "Check `directory-files'."
891 (skip-unless (tramp--test-enabled))
892
893 (let* ((tmp-name1 (tramp--test-make-temp-name))
894 (tmp-name2 (expand-file-name "bla" tmp-name1))
895 (tmp-name3 (expand-file-name "foo" tmp-name1)))
896 (unwind-protect
897 (progn
898 (make-directory tmp-name1)
899 (write-region "foo" nil tmp-name2)
900 (write-region "bla" nil tmp-name3)
901 (should (file-directory-p tmp-name1))
902 (should (file-exists-p tmp-name2))
903 (should (file-exists-p tmp-name3))
904 (should (equal (directory-files tmp-name1) '("." ".." "bla" "foo")))
905 (should (equal (directory-files tmp-name1 'full)
906 `(,(concat tmp-name1 "/.")
907 ,(concat tmp-name1 "/..")
908 ,tmp-name2 ,tmp-name3)))
909 (should (equal (directory-files
910 tmp-name1 nil directory-files-no-dot-files-regexp)
911 '("bla" "foo")))
912 (should (equal (directory-files
913 tmp-name1 'full directory-files-no-dot-files-regexp)
914 `(,tmp-name2 ,tmp-name3))))
915 (ignore-errors (delete-directory tmp-name1 'recursive)))))
916
917 (ert-deftest tramp-test17-insert-directory ()
918 "Check `insert-directory'."
919 (skip-unless (tramp--test-enabled))
920
921 (let* ((tmp-name1 (tramp--test-make-temp-name))
922 (tmp-name2 (expand-file-name "foo" tmp-name1)))
923 (unwind-protect
924 (progn
925 (make-directory tmp-name1)
926 (write-region "foo" nil tmp-name2)
927 (should (file-directory-p tmp-name1))
928 (should (file-exists-p tmp-name2))
929 (with-temp-buffer
930 (insert-directory tmp-name1 nil)
931 (goto-char (point-min))
932 (should (looking-at-p (regexp-quote tmp-name1))))
933 (with-temp-buffer
934 (insert-directory tmp-name1 "-al")
935 (goto-char (point-min))
936 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1)))))
937 (with-temp-buffer
938 (insert-directory (file-name-as-directory tmp-name1) "-al")
939 (goto-char (point-min))
940 (should
941 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1)))))
942 (with-temp-buffer
943 (insert-directory
944 (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
945 (goto-char (point-min))
946 (should
947 (looking-at-p
948 "\\(total.+[[:digit:]]+\n\\)?.+ \\.\n.+ \\.\\.\n.+ foo$"))))
949 (ignore-errors (delete-directory tmp-name1 'recursive)))))
950
951 (ert-deftest tramp-test18-file-attributes ()
952 "Check `file-attributes'.
953 This tests also `file-readable-p' and `file-regular-p'."
954 (skip-unless (tramp--test-enabled))
955
956 (let ((tmp-name (tramp--test-make-temp-name))
957 attr)
958 (unwind-protect
959 (progn
960 (write-region "foo" nil tmp-name)
961 (should (file-exists-p tmp-name))
962 (setq attr (file-attributes tmp-name))
963 (should (consp attr))
964 (should (file-exists-p tmp-name))
965 (should (file-readable-p tmp-name))
966 (should (file-regular-p tmp-name))
967 ;; We do not test inodes and device numbers.
968 (should (null (car attr)))
969 (should (numberp (nth 1 attr))) ;; Link.
970 (should (numberp (nth 2 attr))) ;; Uid.
971 (should (numberp (nth 3 attr))) ;; Gid.
972 ;; Last access time.
973 (should (stringp (current-time-string (nth 4 attr))))
974 ;; Last modification time.
975 (should (stringp (current-time-string (nth 5 attr))))
976 ;; Last status change time.
977 (should (stringp (current-time-string (nth 6 attr))))
978 (should (numberp (nth 7 attr))) ;; Size.
979 (should (stringp (nth 8 attr))) ;; Modes.
980
981 (setq attr (file-attributes tmp-name 'string))
982 (should (stringp (nth 2 attr))) ;; Uid.
983 (should (stringp (nth 3 attr))) ;; Gid.
984 (delete-file tmp-name)
985
986 (make-directory tmp-name)
987 (should (file-exists-p tmp-name))
988 (should (file-readable-p tmp-name))
989 (should-not (file-regular-p tmp-name))
990 (setq attr (file-attributes tmp-name))
991 (should (eq (car attr) t)))
992 (ignore-errors (delete-directory tmp-name)))))
993
994 (ert-deftest tramp-test19-directory-files-and-attributes ()
995 "Check `directory-files-and-attributes'."
996 (skip-unless (tramp--test-enabled))
997
998 ;; `directory-files-and-attributes' contains also values for "../".
999 ;; Ensure that this doesn't change during tests, for
1000 ;; example due to handling temporary files.
1001 (let* ((tmp-name1 (tramp--test-make-temp-name))
1002 (tmp-name2 (expand-file-name "bla" tmp-name1))
1003 attr)
1004 (unwind-protect
1005 (progn
1006 (make-directory tmp-name1)
1007 (should (file-directory-p tmp-name1))
1008 (make-directory tmp-name2)
1009 (should (file-directory-p tmp-name2))
1010 (write-region "foo" nil (expand-file-name "foo" tmp-name2))
1011 (write-region "bar" nil (expand-file-name "bar" tmp-name2))
1012 (write-region "boz" nil (expand-file-name "boz" tmp-name2))
1013 (setq attr (directory-files-and-attributes tmp-name2))
1014 (should (consp attr))
1015 ;; Dumb remote shells without perl(1) or stat(1) are not
1016 ;; able to return the date correctly. They say "don't know".
1017 (dolist (elt attr)
1018 (unless
1019 (equal
1020 (nth 5
1021 (file-attributes (expand-file-name (car elt) tmp-name2)))
1022 '(0 0))
1023 (should
1024 (equal (file-attributes (expand-file-name (car elt) tmp-name2))
1025 (cdr elt)))))
1026 (setq attr (directory-files-and-attributes tmp-name2 'full))
1027 (dolist (elt attr)
1028 (unless (equal (nth 5 (file-attributes (car elt))) '(0 0))
1029 (should
1030 (equal (file-attributes (car elt)) (cdr elt)))))
1031 (setq attr (directory-files-and-attributes tmp-name2 nil "^b"))
1032 (should (equal (mapcar 'car attr) '("bar" "boz"))))
1033 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1034
1035 (ert-deftest tramp-test20-file-modes ()
1036 "Check `file-modes'.
1037 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
1038 (skip-unless (tramp--test-enabled))
1039 (skip-unless
1040 (not
1041 (memq
1042 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1043 '(tramp-adb-file-name-handler
1044 tramp-gvfs-file-name-handler
1045 tramp-smb-file-name-handler))))
1046
1047 (let ((tmp-name (tramp--test-make-temp-name)))
1048 (unwind-protect
1049 (progn
1050 (write-region "foo" nil tmp-name)
1051 (should (file-exists-p tmp-name))
1052 (set-file-modes tmp-name #o777)
1053 (should (= (file-modes tmp-name) #o777))
1054 (should (file-executable-p tmp-name))
1055 (should (file-writable-p tmp-name))
1056 (set-file-modes tmp-name #o444)
1057 (should (= (file-modes tmp-name) #o444))
1058 (should-not (file-executable-p tmp-name))
1059 ;; A file is always writable for user "root".
1060 (unless (zerop (nth 2 (file-attributes tmp-name)))
1061 (should-not (file-writable-p tmp-name))))
1062 (ignore-errors (delete-file tmp-name)))))
1063
1064 (ert-deftest tramp-test21-file-links ()
1065 "Check `file-symlink-p'.
1066 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1067 (skip-unless (tramp--test-enabled))
1068
1069 (let ((tmp-name1 (tramp--test-make-temp-name))
1070 (tmp-name2 (tramp--test-make-temp-name))
1071 (tmp-name3 (tramp--test-make-temp-name 'local)))
1072 (unwind-protect
1073 (progn
1074 (write-region "foo" nil tmp-name1)
1075 (should (file-exists-p tmp-name1))
1076 ;; Method "smb" supports `make-symbolic-link' only if the
1077 ;; remote host has CIFS capabilities. tramp-adb.el and
1078 ;; tramp-gvfs.el do not support symbolic links at all.
1079 (condition-case err
1080 (make-symbolic-link tmp-name1 tmp-name2)
1081 (file-error
1082 (skip-unless
1083 (not (string-equal (error-message-string err)
1084 "make-symbolic-link not supported")))))
1085 (should (file-symlink-p tmp-name2))
1086 (should-error (make-symbolic-link tmp-name1 tmp-name2))
1087 (make-symbolic-link tmp-name1 tmp-name2 'ok-if-already-exists)
1088 (should (file-symlink-p tmp-name2))
1089 ;; `tmp-name3' is a local file name.
1090 (should-error (make-symbolic-link tmp-name1 tmp-name3)))
1091 (ignore-errors
1092 (delete-file tmp-name1)
1093 (delete-file tmp-name2)))
1094
1095 (unwind-protect
1096 (progn
1097 (write-region "foo" nil tmp-name1)
1098 (should (file-exists-p tmp-name1))
1099 (add-name-to-file tmp-name1 tmp-name2)
1100 (should-not (file-symlink-p tmp-name2))
1101 (should-error (add-name-to-file tmp-name1 tmp-name2))
1102 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists)
1103 (should-not (file-symlink-p tmp-name2))
1104 ;; `tmp-name3' is a local file name.
1105 (should-error (add-name-to-file tmp-name1 tmp-name3)))
1106 (ignore-errors
1107 (delete-file tmp-name1)
1108 (delete-file tmp-name2)))
1109
1110 (unwind-protect
1111 (progn
1112 (write-region "foo" nil tmp-name1)
1113 (should (file-exists-p tmp-name1))
1114 (make-symbolic-link tmp-name1 tmp-name2)
1115 (should (file-symlink-p tmp-name2))
1116 (should-not (string-equal tmp-name2 (file-truename tmp-name2)))
1117 (should
1118 (string-equal (file-truename tmp-name1) (file-truename tmp-name2)))
1119 (should (file-equal-p tmp-name1 tmp-name2)))
1120 (ignore-errors
1121 (delete-file tmp-name1)
1122 (delete-file tmp-name2)))
1123
1124 ;; `file-truename' shall preserve trailing link of directories.
1125 (unless (file-symlink-p tramp-test-temporary-file-directory)
1126 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory))
1127 (dir2 (file-name-as-directory dir1)))
1128 (should (string-equal (file-truename dir1) (expand-file-name dir1)))
1129 (should (string-equal (file-truename dir2) (expand-file-name dir2)))))))
1130
1131 (ert-deftest tramp-test22-file-times ()
1132 "Check `set-file-times' and `file-newer-than-file-p'."
1133 (skip-unless (tramp--test-enabled))
1134 (skip-unless
1135 (not
1136 (memq
1137 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1138 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1139
1140 (let ((tmp-name1 (tramp--test-make-temp-name))
1141 (tmp-name2 (tramp--test-make-temp-name))
1142 (tmp-name3 (tramp--test-make-temp-name)))
1143 (unwind-protect
1144 (progn
1145 (write-region "foo" nil tmp-name1)
1146 (should (file-exists-p tmp-name1))
1147 (should (consp (nth 5 (file-attributes tmp-name1))))
1148 ;; '(0 0) means don't know, and will be replaced by
1149 ;; `current-time'. Therefore, we use '(0 1).
1150 ;; We skip the test, if the remote handler is not able to
1151 ;; set the correct time.
1152 (skip-unless (set-file-times tmp-name1 '(0 1)))
1153 ;; Dumb remote shells without perl(1) or stat(1) are not
1154 ;; able to return the date correctly. They say "don't know".
1155 (unless (equal (nth 5 (file-attributes tmp-name1)) '(0 0))
1156 (should (equal (nth 5 (file-attributes tmp-name1)) '(0 1)))
1157 (write-region "bla" nil tmp-name2)
1158 (should (file-exists-p tmp-name2))
1159 (should (file-newer-than-file-p tmp-name2 tmp-name1))
1160 ;; `tmp-name3' does not exist.
1161 (should (file-newer-than-file-p tmp-name2 tmp-name3))
1162 (should-not (file-newer-than-file-p tmp-name3 tmp-name1))))
1163 (ignore-errors
1164 (delete-file tmp-name1)
1165 (delete-file tmp-name2)))))
1166
1167 (ert-deftest tramp-test23-visited-file-modtime ()
1168 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1169 (skip-unless (tramp--test-enabled))
1170
1171 (let ((tmp-name (tramp--test-make-temp-name)))
1172 (unwind-protect
1173 (progn
1174 (write-region "foo" nil tmp-name)
1175 (should (file-exists-p tmp-name))
1176 (with-temp-buffer
1177 (insert-file-contents tmp-name)
1178 (should (verify-visited-file-modtime))
1179 (set-visited-file-modtime '(0 1))
1180 (should (verify-visited-file-modtime))
1181 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1182 (ignore-errors (delete-file tmp-name)))))
1183
1184 (ert-deftest tramp-test24-file-name-completion ()
1185 "Check `file-name-completion' and `file-name-all-completions'."
1186 (skip-unless (tramp--test-enabled))
1187
1188 (let ((tmp-name (tramp--test-make-temp-name)))
1189 (unwind-protect
1190 (progn
1191 (make-directory tmp-name)
1192 (should (file-directory-p tmp-name))
1193 (write-region "foo" nil (expand-file-name "foo" tmp-name))
1194 (write-region "bar" nil (expand-file-name "bold" tmp-name))
1195 (make-directory (expand-file-name "boz" tmp-name))
1196 (should (equal (file-name-completion "fo" tmp-name) "foo"))
1197 (should (equal (file-name-completion "b" tmp-name) "bo"))
1198 (should
1199 (equal (file-name-completion "b" tmp-name 'file-directory-p) "boz/"))
1200 (should (equal (file-name-all-completions "fo" tmp-name) '("foo")))
1201 (should
1202 (equal (sort (file-name-all-completions "b" tmp-name) 'string-lessp)
1203 '("bold" "boz/"))))
1204 (ignore-errors (delete-directory tmp-name 'recursive)))))
1205
1206 (ert-deftest tramp-test25-load ()
1207 "Check `load'."
1208 (skip-unless (tramp--test-enabled))
1209
1210 (let ((tmp-name (tramp--test-make-temp-name)))
1211 (unwind-protect
1212 (progn
1213 (load tmp-name 'noerror 'nomessage)
1214 (should-not (featurep 'tramp-test-load))
1215 (write-region "(provide 'tramp-test-load)" nil tmp-name)
1216 ;; `load' in lread.c does not pass `must-suffix'. Why?
1217 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1218 (load tmp-name nil 'nomessage 'nosuffix)
1219 (should (featurep 'tramp-test-load)))
1220 (ignore-errors
1221 (and (featurep 'tramp-test-load) (unload-feature 'tramp-test-load))
1222 (delete-file tmp-name)))))
1223
1224 (ert-deftest tramp-test26-process-file ()
1225 "Check `process-file'."
1226 (skip-unless (tramp--test-enabled))
1227 (skip-unless
1228 (not
1229 (memq
1230 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1231 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1232
1233 (let ((tmp-name (tramp--test-make-temp-name))
1234 (default-directory tramp-test-temporary-file-directory)
1235 kill-buffer-query-functions)
1236 (unwind-protect
1237 (progn
1238 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1239 ;; do not exist on hydra.
1240 (should (zerop (process-file "true")))
1241 (should-not (zerop (process-file "false")))
1242 (should-not (zerop (process-file "binary-does-not-exist")))
1243 (with-temp-buffer
1244 (write-region "foo" nil tmp-name)
1245 (should (file-exists-p tmp-name))
1246 (should
1247 (zerop
1248 (process-file "ls" nil t nil (file-name-nondirectory tmp-name))))
1249 ;; `ls' could produce colorized output.
1250 (goto-char (point-min))
1251 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1252 (replace-match "" nil nil))
1253 (should
1254 (string-equal
1255 (format "%s\n" (file-name-nondirectory tmp-name))
1256 (buffer-string)))))
1257 (ignore-errors (delete-file tmp-name)))))
1258
1259 (ert-deftest tramp-test27-start-file-process ()
1260 "Check `start-file-process'."
1261 (skip-unless (tramp--test-enabled))
1262 (skip-unless
1263 (not
1264 (memq
1265 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1266 '(tramp-adb-file-name-handler
1267 tramp-gvfs-file-name-handler
1268 tramp-smb-file-name-handler))))
1269
1270 (let ((default-directory tramp-test-temporary-file-directory)
1271 (tmp-name (tramp--test-make-temp-name))
1272 kill-buffer-query-functions proc)
1273 (unwind-protect
1274 (with-temp-buffer
1275 (setq proc (start-file-process "test1" (current-buffer) "cat"))
1276 (should (processp proc))
1277 (should (equal (process-status proc) 'run))
1278 (process-send-string proc "foo")
1279 (process-send-eof proc)
1280 (accept-process-output proc 1)
1281 (should (string-equal (buffer-string) "foo")))
1282 (ignore-errors (delete-process proc)))
1283
1284 (unwind-protect
1285 (with-temp-buffer
1286 (write-region "foo" nil tmp-name)
1287 (should (file-exists-p tmp-name))
1288 (setq proc
1289 (start-file-process
1290 "test2" (current-buffer)
1291 "cat" (file-name-nondirectory tmp-name)))
1292 (should (processp proc))
1293 (accept-process-output proc 1)
1294 (should (string-equal (buffer-string) "foo")))
1295 (ignore-errors
1296 (delete-process proc)
1297 (delete-file tmp-name)))
1298
1299 (unwind-protect
1300 (progn
1301 (setq proc (start-file-process "test3" nil "cat"))
1302 (should (processp proc))
1303 (should (equal (process-status proc) 'run))
1304 (set-process-filter
1305 proc (lambda (_p s) (should (string-equal s "foo"))))
1306 (process-send-string proc "foo")
1307 (process-send-eof proc)
1308 (accept-process-output proc 1))
1309 (ignore-errors (delete-process proc)))))
1310
1311 (ert-deftest tramp-test28-shell-command ()
1312 "Check `shell-command'."
1313 (skip-unless (tramp--test-enabled))
1314 (skip-unless
1315 (not
1316 (memq
1317 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1318 '(tramp-adb-file-name-handler
1319 tramp-gvfs-file-name-handler
1320 tramp-smb-file-name-handler))))
1321
1322 (let ((tmp-name (tramp--test-make-temp-name))
1323 (default-directory tramp-test-temporary-file-directory)
1324 kill-buffer-query-functions)
1325 (unwind-protect
1326 (with-temp-buffer
1327 (write-region "foo" nil tmp-name)
1328 (should (file-exists-p tmp-name))
1329 (shell-command
1330 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1331 ;; `ls' could produce colorized output.
1332 (goto-char (point-min))
1333 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1334 (replace-match "" nil nil))
1335 (should
1336 (string-equal
1337 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1338 (ignore-errors (delete-file tmp-name)))
1339
1340 (unwind-protect
1341 (with-temp-buffer
1342 (write-region "foo" nil tmp-name)
1343 (should (file-exists-p tmp-name))
1344 (async-shell-command
1345 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1346 (accept-process-output (get-buffer-process (current-buffer)) 1)
1347 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1348 (while
1349 (ignore-errors
1350 (memq (process-status (get-buffer-process (current-buffer)))
1351 '(run open)))
1352 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1353 ;; `ls' could produce colorized output.
1354 (goto-char (point-min))
1355 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1356 (replace-match "" nil nil))
1357 (should
1358 (string-equal
1359 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1360 (ignore-errors (delete-file tmp-name)))
1361
1362 (unwind-protect
1363 (with-temp-buffer
1364 (write-region "foo" nil tmp-name)
1365 (should (file-exists-p tmp-name))
1366 (async-shell-command "read line; ls $line" (current-buffer))
1367 (process-send-string
1368 (get-buffer-process (current-buffer))
1369 (format "%s\n" (file-name-nondirectory tmp-name)))
1370 (accept-process-output (get-buffer-process (current-buffer)) 1)
1371 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1372 (while
1373 (ignore-errors
1374 (memq (process-status (get-buffer-process (current-buffer)))
1375 '(run open)))
1376 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1377 (should
1378 (string-equal
1379 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1380 (ignore-errors (delete-file tmp-name)))))
1381
1382 (ert-deftest tramp-test29-vc-registered ()
1383 "Check `vc-registered'."
1384 (skip-unless (tramp--test-enabled))
1385 (skip-unless
1386 (eq
1387 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1388 'tramp-sh-file-name-handler))
1389
1390 (let* ((default-directory tramp-test-temporary-file-directory)
1391 (tmp-name1 (tramp--test-make-temp-name))
1392 (tmp-name2 (expand-file-name "foo" tmp-name1))
1393 (vc-handled-backends
1394 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1395 (cond
1396 ((tramp-find-executable v vc-bzr-program (tramp-get-remote-path v))
1397 '(Bzr))
1398 ((tramp-find-executable v vc-git-program (tramp-get-remote-path v))
1399 '(Git))
1400 ((tramp-find-executable v vc-hg-program (tramp-get-remote-path v))
1401 '(Hg))
1402 (t nil)))))
1403 (skip-unless vc-handled-backends)
1404 (message "%s" vc-handled-backends)
1405
1406 (unwind-protect
1407 (progn
1408 (make-directory tmp-name1)
1409 (write-region "foo" nil tmp-name2)
1410 (should (file-directory-p tmp-name1))
1411 (should (file-exists-p tmp-name2))
1412 (should-not (vc-registered tmp-name1))
1413 (should-not (vc-registered tmp-name2))
1414
1415 (let ((default-directory tmp-name1))
1416 ;; Create empty repository, and register the file.
1417 (vc-create-repo (car vc-handled-backends))
1418 ;; The structure of VC-FILESET is not documented. Let's
1419 ;; hope it won't change.
1420 (vc-register
1421 nil (list (car vc-handled-backends)
1422 (list (file-name-nondirectory tmp-name2)))))
1423 (should (vc-registered tmp-name2)))
1424
1425 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1426
1427 (defun tramp--test-check-files (&rest files)
1428 "Runs a simple but comprehensive test over every file in FILES."
1429 (let ((tmp-name1 (tramp--test-make-temp-name))
1430 (tmp-name2 (tramp--test-make-temp-name 'local)))
1431 (unwind-protect
1432 (progn
1433 (make-directory tmp-name1)
1434 (make-directory tmp-name2)
1435 (dolist (elt files)
1436 (let ((file1 (expand-file-name elt tmp-name1))
1437 (file2 (expand-file-name elt tmp-name2)))
1438 (write-region elt nil file1)
1439 (should (file-exists-p file1))
1440 ;; Check file contents.
1441 (with-temp-buffer
1442 (insert-file-contents file1)
1443 (should (string-equal (buffer-string) elt)))
1444 ;; Copy file both directions.
1445 (copy-file file1 tmp-name2)
1446 (should (file-exists-p file2))
1447 (delete-file file1)
1448 (should-not (file-exists-p file1))
1449 (copy-file file2 tmp-name1)
1450 (should (file-exists-p file1))))
1451 ;; Check file names.
1452 (should (equal (directory-files
1453 tmp-name1 nil directory-files-no-dot-files-regexp)
1454 (sort (copy-sequence files) 'string-lessp)))
1455 (should (equal (directory-files
1456 tmp-name2 nil directory-files-no-dot-files-regexp)
1457 (sort files 'string-lessp))))
1458 (ignore-errors (delete-directory tmp-name1 'recursive))
1459 (ignore-errors (delete-directory tmp-name2 'recursive)))))
1460
1461 ;; This test is inspired by Bug#17238.
1462 (ert-deftest tramp-test30-special-characters ()
1463 "Check special characters in file names."
1464 (skip-unless (tramp--test-enabled))
1465
1466 ;; Newlines, slashes and backslashes in file names are not supported.
1467 ;; So we don't test.
1468 (tramp--test-check-files
1469 " foo\tbar baz\t"
1470 "$foo$bar$$baz$"
1471 "-foo-bar-baz-"
1472 "%foo%bar%baz%"
1473 "&foo&bar&baz&"
1474 "?foo?bar?baz?"
1475 "*foo*bar*baz*"
1476 "'foo\"bar'baz\""
1477 "#foo#bar#baz#"
1478 "!foo|bar!baz|"
1479 ":foo;bar:baz;"
1480 "<foo>bar<baz>"
1481 "(foo)bar(baz)"))
1482
1483 (ert-deftest tramp-test31-utf8 ()
1484 "Check UTF8 encoding in file names and file contents."
1485 (skip-unless (tramp--test-enabled))
1486
1487 (let ((coding-system-for-read 'utf-8)
1488 (coding-system-for-write 'utf-8)
1489 (file-name-coding-system 'utf-8))
1490 (tramp--test-check-files
1491 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت"
1492 "银河系漫游指南系列"
1493 "Автостопом по гала́ктике")))
1494
1495 ;; This test is inspired by Bug#16928.
1496 (ert-deftest tramp-test32-asynchronous-requests ()
1497 "Check parallel asynchronous requests.
1498 Such requests could arrive from timers, process filters and
1499 process sentinels. They shall not disturb each other."
1500 ;; Mark as failed until bug has been fixed.
1501 :expected-result :failed
1502 (skip-unless (tramp--test-enabled))
1503 (skip-unless
1504 (eq
1505 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1506 'tramp-sh-file-name-handler))
1507
1508 ;; Keep instrumentation verbosity 0 until Tramp bug is fixed. This
1509 ;; has the side effect, that this test fails instead to abort. Good
1510 ;; for hydra.
1511 (tramp--instrument-test-case 0
1512 (let* ((tmp-name (tramp--test-make-temp-name))
1513 (default-directory tmp-name)
1514 (remote-file-name-inhibit-cache t)
1515 timer buffers kill-buffer-query-functions)
1516
1517 (unwind-protect
1518 (progn
1519 (make-directory tmp-name)
1520
1521 ;; Setup a timer in order to raise an ordinary command again
1522 ;; and again. `vc-registered' is well suited, because there
1523 ;; are many checks.
1524 (setq
1525 timer
1526 (run-at-time
1527 0 1
1528 (lambda ()
1529 (when buffers
1530 (vc-registered
1531 (buffer-name (nth (random (length buffers)) buffers)))))))
1532
1533 ;; Create temporary buffers. The number of buffers
1534 ;; corresponds to the number of processes; it could be
1535 ;; increased in order to make pressure on Tramp.
1536 (dotimes (i 5)
1537 (add-to-list 'buffers (generate-new-buffer "*temp*")))
1538
1539 ;; Open asynchronous processes. Set process sentinel.
1540 (dolist (buf buffers)
1541 (async-shell-command "read line; touch $line; echo $line" buf)
1542 (set-process-sentinel
1543 (get-buffer-process buf)
1544 (lambda (proc _state)
1545 (delete-file (buffer-name (process-buffer proc))))))
1546
1547 ;; Send a string. Use a random order of the buffers. Mix
1548 ;; with regular operation.
1549 (let ((buffers (copy-sequence buffers))
1550 buf)
1551 (while buffers
1552 (setq buf (nth (random (length buffers)) buffers))
1553 (process-send-string
1554 (get-buffer-process buf) (format "'%s'\n" buf))
1555 (file-attributes (buffer-name buf))
1556 (setq buffers (delq buf buffers))))
1557
1558 ;; Wait until the whole output has been read.
1559 (with-timeout ((* 10 (length buffers))
1560 (ert-fail "`async-shell-command' timed out"))
1561 (let ((buffers (copy-sequence buffers))
1562 buf)
1563 (while buffers
1564 (setq buf (nth (random (length buffers)) buffers))
1565 (if (ignore-errors
1566 (memq (process-status (get-buffer-process buf))
1567 '(run open)))
1568 (accept-process-output (get-buffer-process buf) 0.1)
1569 (setq buffers (delq buf buffers))))))
1570
1571 ;; Check.
1572 (dolist (buf buffers)
1573 (with-current-buffer buf
1574 (should
1575 (string-equal (format "'%s'\n" buf) (buffer-string)))))
1576 (should-not
1577 (directory-files tmp-name nil directory-files-no-dot-files-regexp)))
1578
1579 ;; Cleanup.
1580 (ignore-errors (cancel-timer timer))
1581 (ignore-errors (delete-directory tmp-name 'recursive))
1582 (dolist (buf buffers)
1583 (ignore-errors (kill-buffer buf)))))))
1584
1585 (ert-deftest tramp-test33-recursive-load ()
1586 "Check that Tramp does not fail due to recursive load."
1587 (skip-unless (tramp--test-enabled))
1588
1589 (dolist (code
1590 (list
1591 (format
1592 "(expand-file-name %S))"
1593 tramp-test-temporary-file-directory)
1594 (format
1595 "(let ((default-directory %S)) (expand-file-name %S))"
1596 tramp-test-temporary-file-directory
1597 temporary-file-directory)))
1598 (should-not
1599 (string-match
1600 "Recursive load"
1601 (shell-command-to-string
1602 (format
1603 "%s -batch -Q -L %s --eval %s"
1604 (expand-file-name invocation-name invocation-directory)
1605 (mapconcat 'shell-quote-argument load-path " -L ")
1606 (shell-quote-argument code)))))))
1607
1608 (ert-deftest tramp-test34-unload ()
1609 "Check that Tramp and its subpackages unload completely.
1610 Since it unloads Tramp, it shall be the last test to run."
1611 ;; Mark as failed until all symbols are unbound.
1612 :expected-result (if (featurep 'tramp) :failed :passed)
1613 (when (featurep 'tramp)
1614 (unload-feature 'tramp 'force)
1615 ;; No Tramp feature must be left.
1616 (should-not (featurep 'tramp))
1617 (should-not (all-completions "tramp" (delq 'tramp-tests features)))
1618 ;; `file-name-handler-alist' must be clean.
1619 (should-not (all-completions "tramp" (mapcar 'cdr file-name-handler-alist)))
1620 ;; There shouldn't be left a bound symbol. We do not regard our
1621 ;; test symbols, and the Tramp unload hooks.
1622 (mapatoms
1623 (lambda (x)
1624 (and (or (boundp x) (functionp x))
1625 (string-match "^tramp" (symbol-name x))
1626 (not (string-match "^tramp--?test" (symbol-name x)))
1627 (not (string-match "unload-hook$" (symbol-name x)))
1628 (ert-fail (format "`%s' still bound" x)))))
1629 ; (progn (message "`%s' still bound" x)))))
1630 ;; There shouldn't be left a hook function containing a Tramp
1631 ;; function. We do not regard the Tramp unload hooks.
1632 (mapatoms
1633 (lambda (x)
1634 (and (boundp x)
1635 (string-match "-hooks?$" (symbol-name x))
1636 (not (string-match "unload-hook$" (symbol-name x)))
1637 (consp (symbol-value x))
1638 (ignore-errors (all-completions "tramp" (symbol-value x)))
1639 (ert-fail (format "Hook `%s' still contains Tramp function" x)))))))
1640
1641 ;; TODO:
1642
1643 ;; * dired-compress-file
1644 ;; * dired-uncache
1645 ;; * file-acl
1646 ;; * file-ownership-preserved-p
1647 ;; * file-selinux-context
1648 ;; * find-backup-file-name
1649 ;; * make-auto-save-file-name
1650 ;; * set-file-acl
1651 ;; * set-file-selinux-context
1652
1653 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
1654 ;; * Fix `tramp-test28-shell-command' on MS Windows (nasty plink message).
1655 ;; * Fix `tramp-test31-utf8' for MS Windows and `nc'/`telnet' (when
1656 ;; target is a dumb busybox). Seems to be in `directory-files'.
1657 ;; * Fix Bug#16928. Set expected error of `tramp-test32-asynchronous-requests'.
1658 ;; * Fix `tramp-test34-unload' (Not all symbols are unbound). Set
1659 ;; expected error.
1660
1661 (defun tramp-test-all (&optional interactive)
1662 "Run all tests for \\[tramp]."
1663 (interactive "p")
1664 (funcall
1665 (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
1666
1667 (provide 'tramp-tests)
1668 ;;; tramp-tests.el ends here