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